#community-help

Query Suggestions and Result Modification in TS

TLDR Ashraful needed advice on refining query suggestions in TS. Jason recommended reducing the result quantity and utilizing snippet fields. When additional issues were raised, Jason proposed adjusting the 'highlight_affix_num_tokens' setting.

Powered by Struct AI
4
1mo
Solved
Join the chat
Aug 21, 2023 (1 month ago)
Ashraful
Photo of md5-32f459baabe416fa266859a1baa39dda
Ashraful
10:06 AM
Hello Community,

I have a question regarding the query suggestion.

Is there any OOTB feature / custom solution in TS, where I can show end users some query suggestion based on what he is typing? it should meet the following criteria:
1. It should be as precise as possible (i.e. q-> auto, results -> automotive, automatic, automation etc, q-> car auto, results -> car automotive, car automatic, car automation etc).
2. Suggestion should result in having one or more actual results.
That means, the above suggestions automotive, automatic, automation should come from my primary index, so that when i search using any of the keyword it is guaranteed to be returned some results.
I know, that TS has a built-in popular queries mechanism, but that is not appropriate in my scenario, as it does not guarantee any actual result in my primary index.

My current implementation is to query the primary index for page title attribute , and return the records. Results are guaranteed, but most the time it has a full sentence / large number of words, which defeats the purpose.

Thanks in advance.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:13 PM
> My current implementation is to query the primary index for page title attribute , and return the records.
This would indeed be the solution.

> Most the time it has a full sentence / large number of words
You can set per_page to say 4 to show users only the top 4 results.

You can also use the snippet field in the response, to only show the most relevant part of the field to the user
Aug 22, 2023 (1 month ago)
Ashraful
Photo of md5-32f459baabe416fa266859a1baa39dda
Ashraful
01:17 PM
Hi Jason,
• You can set per_page to say 4 to show users only the top 4 results.
Yes, but the number of results is not the concern here, but rather the number of words are.

• You can also use the snippet field in the response,
Yes, but in that case, I may see the same snippet word multiple times.
You can take a look at the image.
the snippet wraps around the same word.

is there a way to increase/decrease the amount of letters to be snipetted?
Image 1 for Hi Jason,<br>• You can set <code>per_page</code> to  say <code>4</code> to show users only the top 4 results.<br>Yes, but the number of results is not the concern here, but rather the number of words are.<br><br>• You can also use the snippet field in the response,<br>Yes, but in that case, I may see the same snippet word multiple times.<br>You can take a look at the image.<br>the snippet wraps around the same word.<br><br>is there a way to increase/decrease the amount of letters to be snipetted?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:37 PM
highlight_affix_num_tokens will control the length of the snippet, documented in this table: https://typesense.org/docs/0.25.0/api/search.html#results-parameters