Hi HH Community
In my Knowledge Graph, I have a custom field created from a Text List field type. Let’s call this field “c_ingredients”.
What is the best method to ensure Yext Answers returns results whether a query contains AND or OR operators in the search query. i.e.
- Recipes with bacon and onions
- Recipes with bacon or onions
Both of the examples above should return a different number of recipes.
I was thinking perhaps I could use the ContextContains criteria in Query Rules and have the actions filter by the “c_ingredients” field, but I’m not too sure if this would work.
Do you have any examples / best practice in defining the above?
Thanks
Sam
Hey Sam,
Great question. Since “or” and “and” are both built-in stop words, setting c_ingredients
as a searchable field would return results using “bacon” and “onions” as tokens being searched for, regardless of whether the search query was “bacon and onions” or “bacon or onions”:
- Text search would use OR logic to return any entities that contain either bacon or onions, but would prioritize entities with both bacon and onions since it would see two tokens that match and assume those results are more relevant.
- Facets would also use OR logic.
You could use query rules to filter the actions, but this would get complicated and be more of a workaround so we don’t recommend that.
Hi Kristy and team, just revisiting this use case. Do you have a recommended best practice approach for these scenarios? Many thanks, Sam
Hey Sam,
First, amending my post to remove NLP filters for this use case as it would filter to the one best match so AND logic would not apply.
Second, I don’t think there’s a great solution to account for searches using AND or OR since these are currently stop words and not factored in to the algorithm. You could submit this to the Ideas board for our Product Managers to consider.
Third, I would suggest using text search for c_ingredients
. This would show all recipes with any combination of bacon and/or onions, but recipes with both bacon AND onions would show up at the top. If you want users to see the list of ingredients they can pick from and if the ingredients list is clean and categorical, you could also add a facet. (Side note - if there are many possible ingredients, making the facet searchable would make for a better user experience.)
I’d say this is a pretty good user experience overall, even with both searches returning the same number of recipes. If a user was searching with AND, the most relevant results they are looking for are at the top. If a user was searching with OR, the AND results they see at the top are still relevant and if they really wanted to only use one of those ingredients, they would search for recipes with just that one.
Fourth, I don’t think the query rule approach is worth it and would be very manual if anything. You would only need to add filters for the AND searches to narrow down results: if a search contains AND, apply filters for c_ingredients
equal to both A and B. However, there’s no easy way to make this dynamic with the search query. You’d have to manually add each combination of filters, which would be tedious and difficult to maintain as the new ingredients are added.
Hi Kristy - thanks for your detailed response. This is super helpful and a good insight to options.
Thanks again, Sam