• Resolved Nat

    (@etisse)


    Hi,

    Thanks Mikko for this plugin!

    I’d like to index some custom fields without indexing content. I set content to 0 in relevanssi option > search tab.

    I try some solutions with relevanssi hooks to do that, but i failed.

    I try: relevanssi_content_to_index, relevanssi_index_custom_fields, relevanssi_post_title_before_tokenize (but didn’t understand what is tokenize).

    Is there a way to do that? Like a hook to indexing custom fields within the title, or to filter all indexed content instead of adding content to indexed content?

    Or any other way to do that?

    Thanks to anybody for solution I could try

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    All you need is this:

    add_filter( 'relevanssi_index_content', '__return_false' );
    add_filter( 'relevanssi_index_titles', '__return_false' );

    Now no content or titles are indexed. Everything else can be disabled from Relevanssi settings. Then just adjust Relevanssi settings so that the desired custom fields are indexed, and build the index.

    Thread Starter Nat

    (@etisse)

    Hi Mikko,

    Thanx.
    I try to disable indexing the content with your indication.
    But it seems that when indexing content is disable even by this way, the hooks
    relevanssi_content_to_index or relevanssi_index_custom_fields or relevanssi_custom_field_value have no effect. It seems that the custom fields aren’t indexed. Is this possible?

    I need to use hook to index custom fields because it’s an ACF relationship content.

    Is there a way?

    For example, is there a hook to add something to title which is indexed?

    Plugin Author Mikko Saari

    (@msaari)

    If you disable content indexing, relevanssi_content_to_index isn’t run, because the content is not indexed. On the other hand, relevanssi_index_custom_fields is run before the relevanssi_index_content filter hook state is even checked, so there’s no way that filter affects that.

    Custom fields should still be indexed, if you have set Relevanssi to index custom fields. What have you chosen in the custom field indexing setting? It should probably be set to “Visible”, because ACF keeps all the useful data in visible fields and the invisible fields only contain metadata.

    The filter to modify the title is relevanssi_post_title_before_tokenize.

    Thread Starter Nat

    (@etisse)

    Hi Mikko,

    Thank you for the details.

    The filter relevanssi_post_title_before_tokenize do the job!
    (When I was trying using this the first time, I forget to use get_the_ID() and used $post->ID which is not defined to get the metadata.)

    In the custom field indexing setting, I set to “some” because just one field need to be indexed. The field is a relation field so I used the filter relevanssi_custom_field_value adapted from your documentation

    Then I rebuild the index. But when using the search form, I wasn’t able to find all the posts by related posts title – just some… Perhaps some incompatibility with woocommerce or elementor builder used in the website.

    When adding the custom field value to the post title on the search index, it works. The post and all related posts are found. So the solution is found.

    Thanks again for your reactive and helpful support.

    Plugin Author Mikko Saari

    (@msaari)

    You can use $post->ID with relevanssi_post_title_before_tokenize and avoid the extra function call, the relevant post object is passed as the second parameter to the filter hook so you can get it there.

    Good to hear everything works now.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Index custom fields without indexing content’ is closed to new replies.