• Resolved webcart

    (@webcart)


    Hi
    Is there a way to exlude a specific result (like a product) from a search result per word?
    For example if I search for a picnic I want the results to include blanket but to show suitcase although in the suitcase description there is a word “picnic”.

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

    (@msaari)

    Yes. With Relevanssi Premium, this would be really simple: in Premium, there’s a field on post edit pages where you can add words that are blocked for the post, so you could list “picnic” in the suitcase post and that post would never come up for “picnic”.

    With the free version, it’s also possible, but requires some custom code – you’d need to write a filter on relevanssi_hits_filter to process the search results and to remove the posts that match the specific search terms. It’s complicated enough that I won’t explain it here, but if you want to give it a shot, I can give you some pointers on how to do it.

    Thread Starter webcart

    (@webcart)

    Much appreciate your prompt reply.
    Does for the answer is also good for a product?

    If yes, it would be nice if you could first send me the code pointers.
    I would like to give it a shot before I ask my customer to buy the premium version.

    Plugin Author Mikko Saari

    (@msaari)

    Yes, the post type doesn’t matter.

    You need some way to store the negative keywords; you can put them in a custom field for example.

    Then you need a filter on the relevanssi_hits_filter filter hook. That filter has two parameters: the first one is an array of post objects, ie. your search results, and the second is the search query.

    Now what you need to do is to go through the search results array and for each post check if the negative keywords for that post appear in the search query and if they do, pluck that post from the list of results.

    Then just return the array without the unwanted posts.

    Thread Starter webcart

    (@webcart)

    Thanks.
    I will advice my customer to buy the premium version 🙂
    Much appreicate your help. 5 stars are on the way.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Exclude results per word’ is closed to new replies.