4

When we create an index on redisearch, we specify different fields with their weights e.g. title text weight 50 description text weight 25 and as per my understanding these weights determine the ordering of results.

I want to know is there a way to specify fields weights which searching i.e. using FT.SEARCH

I would like to change field weights on runtime i.e. according to the query.

I would like to accomplish something like this

FT.SEARCH idx john description weight 50 title weight 25

See how I have tried to change weights while querying.

Mohsin Sethi
  • 803
  • 4
  • 16

1 Answers1

3

You can use query attribute to specify different weight for different parts of the query. Take a look here for more details: https://oss.redislabs.com/redisearch/Query_Syntax.html#query_attributes

Meir Shpilraien
  • 506
  • 2
  • 4
  • Does query attribute `weight` overrides the weight of a field which we had given while indexing ? For example: let say we have given field `title` weight 50 while indexing So if I run following query with query attribute `weight`, will query attribute `weight` overrides the weight given while indexing to `title` field ? FT.SEARCH idx (@title: john=>{$weight:5;}) – Mohsin Sethi Jan 06 '20 at 09:44
  • 1
    It depends on your scoring function, in the default tfidf this values multiplies the field score as calculated using the following formula: * . If you are using the latest redisearch you can use EXPLAINSCORE to understand how RediSearch reached the calculated score (https://oss.redislabs.com/redisearch/Commands.html#ftsearch) – Meir Shpilraien Jan 06 '20 at 15:34
  • Looks like the thing i need. Thanks! – Mohsin Sethi Jan 07 '20 at 13:52
  • Query attribute weight is not giving required results. Like I want to have certain fields to have certain weights while scoring documents. I know we can provide field weights while creating an index, But i would like to supply field weights while searching a query. The use case is for example, for 1 word query, I would like to give user results prioritized by some other fields relevance whereas for 2+ words query, i would like to prioritize on some other fields. Is it possible in Redisearch ? – Mohsin Sethi Jan 17 '20 at 09:14
  • The only way I can see you doing this is that you write your own scorer (https://oss.redislabs.com/redisearch/Extensions.html#the_scoring_function_api). If you decide to go this way let me know and I can try guide you through it. – Meir Shpilraien Jan 21 '20 at 12:19