Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing and outputting custom fields #45

Open
AndrewNB opened this issue Jun 2, 2018 · 1 comment
Open

Indexing and outputting custom fields #45

AndrewNB opened this issue Jun 2, 2018 · 1 comment
Labels

Comments

@AndrewNB
Copy link

AndrewNB commented Jun 2, 2018

This is more of a question.

I have the plugin working great. However, I am struggling to get the custom fields to be indexed or outputted in results.

I have created the plugin as suggested in the readme and replaced with the field I want indexed.

{
	public static function getSubscribedEvents()
	{
	    return [
	        'onTNTSearchIndex' => ['onTNTSearchIndex', 1000]
	    ];
	}

	public function onTNTSearchIndex(Event $e)
	{
	    $fields = $e['fields'];
	    $page = $e['page'];

	    if (isset($page->header()->product_title)) {
	        $fields->product_title = $page->header()->product_title;
	    }
	}

}

How can I check what is being indexed?
If that is indexing the fields, How can i then output into the results? like this?

{% for key, val in tntsearch_results.hits  %}
            <h3 class="large_title lightblue_font">
                <a href="{{ base_url ~ val.link }}" style="font-size: 100%">{{ val.title }}</a>
            </h3>
            {% if config.get('plugins.tntsearch.display_route') %}
                <h6 class="route">{{ val.link }}</h6>
            {% endif %}
            <p>{{ val.content }}</p>
            <p>{{ val.header.product_title }}</p>
            
{% endfor %}

Thanks

@rhukster
Copy link
Member

The results that are actually available in a query is based on what you set in onTNTSearchQuery() event. By default this is:

https://github.com/trilbymedia/grav-plugin-tntsearch/blob/develop/tntsearch.php#L114-L136

more info on using your own custom results: https://github.com/trilbymedia/grav-plugin-tntsearch#customizing-query-data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants