Hello, i have successfully created my schema and s...
# community-help
p
Hello, i have successfully created my schema and started to index some documents, so far so good. However i would like to sort my search results based on weights, so i came across query by weights. Say that i have those two fields: title, city. I want to give a greater weight to the tile than city so that i give priority to the titles. I am using query_by_weights=2,1. I would expect that results with the keyword in title would come first but then i saw that results are sorted by default with text_match. What is the purpose of the weights if they dont override sorting? How can i achieve what i want?
k
👋 can you post an example query, an example record that you were expecting first, and the record that actually shows up?
p
sure i have the following structure: Documents: {title: 'Eat Croissant in Nice', food: ['Socca', 'Ratatouille'} {title: 'Stroll through Montmartre's cobblestone streets', food: ['Baguette', Croissant] query_by=title,food query_by_weights=2,1 the second one comes first when i search for 'Croissant'
where i want the fields with the most weights to come up first, in my case Eat Croissant in Nice
k
Can you try setting:
Copy code
prioritize_exact_match: false
The exact match with the word
croissant
on the
food
field is giving it a higher text match score. Weight is used to influence the ranking when match score is the same.
p
is there a way to sort the results based on the weight of the fields?
k
There is also the
text_match_type
parameter which can help with the behavior you want. Here's what the docs say:
Copy code
In a multi-field matching context, this parameter determines how the representative text match score of a record is calculated. 

Possible values: `max_score` (default) or `max_weight`. 

In the default `max_score` mode, the best text match score across all fields are used as the representative score of this record. Field weights are used as tie breakers when 2 records share the same text match score.

In the `max_weight` mode, the text match score of the highest weighted field is used as the representative text relevancy score of the record.
So try sending:
Copy code
text_match_type: 'max_weight'
p
nice let me check!
Nope it still doesnt make any difference, the result with food still comes first instead of the result that has the keyword in title
message has been deleted
prioritize_exact_match worked though
k
It's max_weight
p
you are right! thank you so much, worked as well
👍 1