Love seeing the Typesense bus stop ads :slightly_s...
# community-help
j
Love seeing the Typesense bus stop ads 🙂 . Wondering if people have simple tips/tricks for queries with multiple words. I'm guessing I'm doing some basic things wrong or need to build a lot more complex stuff to make my search better, but have tried a lot of basic things and none have worked well. For example, if I search "size 12 men's shoes", I get results like "Cynthia Rowley 100% Silk Dress Ruffled Layers Size 4 Size S" (since it has "size"). I can wrap my query in double quotes and this helps, but overfits and then searching "Size 12 shoes" does not show up. Here is my code for reference, but I've tweaked all these parameters and not gotten much better: var searchResult = await typesenseClient.collection('listings').documents.search({ // 'q':'"${input}"', 'q': '${input}', 'query_by': 'selectedItem.item,selectedItem.keywords,listingDescription,category', 'query_by_weights': '12,6,6,1', // Use filter_by to incorporate your conditions directly: 'filter_by': 'orderTime:>${oneWeekAgoInMillisFS}&&recipientClaimedTime=0&&deleted=false&&showItemOnMarketplace:=true', 'sort_by': '_text_match:desc', 'num_typos': '1', 'typo_tokens_threshold': '1', // 'drop_tokens_threshold': '0', // 'drop_tokens_mode': 'right_to_left', 'exhaustive_search': 'true', // Adding pagination parameters: 'page': '1', 'per_page': '250', // 'prefix': 'false', 'split_join_tokens': 'true', // // 'min_len_1typo': '5', // // 'min_len_2typos': '8', // 'min_len_1typo': '6', // 'min_len_2typos': '8', 'min_len_1typo': '6', 'min_len_2typos': '8', 'exact_on_single_word_query': 'true', });
k
Hi Jonathan, in Typesense if no documents match all tokens in the query, we use drop tokens mode to drop tokens from either end until hits are found. This is not perfect and there can be any combinations of N tokens that could produce a hit. One thing that will help is for you to re-order a query if it has some expected tokens like "size 12". You can try pushing those to the end of the query before sending the query to Typesense so you can use a pre-determine drop token order that makes the query more generic as tokens are dropped.
j
That's a pretty good solution. Sometimes it's hard for me to know what kind of words people search for. So do you recommend I use double quotes and try different combos of words as well? Do people do this/use this trick? That way "shoes with grey stripes" could be "grey stripes shoes with" "stripes shoes grey with" etc.? This seems expensive and potentially unnecessary I guess. I like that it covers broad cases when I don't use double quotes sometimes, but it is frustrating many users when it's a completely different item than what they are looking for because of adjectives/words that are common