#community-help

Issues with Recommendation Query Tag Sorting and Matching

TLDR Adrian has an issue with a recommendation query not returning sorted results. Jason suggested turning the array into a string. Adrian tried this without success and suggests it may be a bug.

Powered by Struct AI

1

Jan 31, 2023 (8 months ago)
Adrian
Photo of md5-051f535431ff484f44f165e9a0b696a5
Adrian
08:08 PM
Hi all, trying to make a simple recommendation query against a “tags” string[] to match against user selected tags, but having some trouble. I would expect the the results to be ordered with documents containing the most matching tags appearing first, but the documents don’t even always get returned, and if they do they are not sorted correctly. Also, the order of the tags in the query greatly affects the results. For example:

q='tradition_daoism tradition_buddhism topic_freedom topic_bliss style_body style_meditation'&query_by=tags&prefix=false

returns documents with a single matching tag in the array, and then in the 15th spot will return documents that match 2-3 tags, and it doesn’t return all documents with multiple matching tags. Also changing the query string order of the tags will affect what documents get returned and in which order. Have also tried using filter_by=tags:[tradition_daoism, etc.…], but that doesn’t sort by number of matching tags either. Feels like I’m missing something obvious, but can’t seem to make any progress, any tips are appreciated.
Feb 01, 2023 (8 months ago)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:01 PM
Adrian

> I would expect the the results to be ordered with documents containing the most matching tags appearing first,
We don’t do this within a string array, only a regular string field.

Could you change this field into a string and separate entries by space and try with the q parameter?
Adrian
Photo of md5-051f535431ff484f44f165e9a0b696a5
Adrian
07:19 PM
Ok got it…I’ll try and add an extra field that flattens the array into a string and see how that works. Thanks for the response!

Seems like it might a useful feature for string arrays, any plans for something that might achieve a similar functionality?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:46 PM
We don’t have plans at the moment, but could you open a Github issue for this, describing your use-case, so we can track demand?

1

Feb 05, 2023 (8 months ago)
Adrian
Photo of md5-051f535431ff484f44f165e9a0b696a5
Adrian
03:25 PM
Jason circling back here, I tried making it a space delimited string, and using “q” but still seeing odd results. Seems like the text match score is the same for all results, irrespective of how many matching tokens there are. Feels like a bug, or maybe related to having a lot of tokens in “q” ?

/collections/articles/documents/search?q=tradition_buddhism tradition_daoism style_body style_meditation topic_bliss topic_freedom&query_by=tagsString&include_fields=tagsString,id&highlight_fields=none&highlight_full_fields=none&prefix=false&per_page=100

Gives this output, as an example note how the penultimate result has 3 matching tokens, yet has the same textmatch scores. (ps. this is on Typesense cloud v0.24)