typesense / typesense/typesense

text_match score value is not affected by query_by_weights values

Open
#1,840 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
26.6k
Forks
973
Avg merge
18h 45m
Merged PRs (30d)
4

Description

Description

According to the documentation query_by_weights parameter is a way to give a relative importance to different fields

The relative weight to give each query_by field when ranking results. Values can be between 0 and 127. This can be used to boost fields in priority, when looking for matches.

In practice, higher query_by_weights does not result in higher _text_match.

Prior to v.26.0 ranking was also random, query_by_weights was not considered at all; in 26.0 on anecdotal cases it seems, that ranking expecation is met (needs to be confirmed on larger sample set, since _text_match value is still the same,independent of which fields were hit and which query_by_weights values they had.

Steps to reproduce

Request:

"request": {
"q": "san diego",
"max_hits": 20,
"per_page": 20,
"prioritize_exact_match": "false",
"prioritize_token_position": "true",
"min_len_1typo": 3,
"min_len_2typo": 7,
"use_cache": "false",
"enable_typos_for_numerical_tokens": "false",
"enable_lazy_filter": "true",
"prioritize_num_matching_fields": "false",
"max_candidates": "40",
"sort_by": "_text_match:desc, location(35.10193405724608,-119.88281250000001,precision: 5 km):asc, popularity_bucket:desc",
"drop_tokens_threshold": 5,
"query_by": "geo_preferred_name,admin_name",
"query_by_weights": "5,1",
"num_typos": "2,1",
"prefix": "true,true",
"collection": "geo_US"
}

Document #1:

"document": {
"EntityType": "Municipality",
"admin_name": ["San Diego","CA","California"],
"admin_name_EN": "San Diego,San Diego,CA",
"geo_preferred_name": ["San Diego"],
"id": "f-BFQbwnssVlw3gjoodFKQ",
"location": [32.71575927734375,-117.163818359375],
"popularity_bucket": 3,
}

Document #2:

"document": {
"EntityType": "Municipality",
"admin_name": ["San Diego","CA","Oceanside","California"
],
"admin_name_EN": "Oceanside,San Diego,CA",
"geo_preferred_name": ["Oceanside"],
"geohash_3": "8329a4fffffffff",
"id": "WuqSAEhdDOi30dW5tkOQfg",
"location": [33.19590759277344,-117.3795166015625],
"popularity_bucket": 3,
}

Expected Behavior

text_match of document #1 is higher than of document #2
document #1 is ranked higher than document #2

Actual Behavior

text_match of document #2 and document #1 is the same.
document #1 is ranked higher than document #2 , which is an improvement, comparing to v. 0.25.x

Document 1 text match:
"text_match": 1157451471441621000,
"text_match_info": {
"best_field_score": "2211897868542",
"best_field_weight": 5,
"fields_matched": 0,
"num_tokens_dropped": 0,
"score": "1157451471441621032",
"tokens_matched": 2,
"typo_prefix_score": 0
},

Document 2 text match:
"text_match": 1157451471441621000,
"text_match_info": {
"best_field_score": "2211897868542",
"best_field_weight": 1,
"fields_matched": 0,
"num_tokens_dropped": 0,
"score": "1157451471441621000",
"tokens_matched": 2,
"typo_prefix_score": 0
},

Possibly text_match.score is used in sorting (and its calculation seems to be more consistent, comparing to v.0.25.x), still text_match value output is confusing,

Metadata

Typesense Version: 26.0

OS: Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Reproduce the Typesense 26.0 request with the two supplied documents, then inspect how query_by_weights contributes to text_match and text_match_info; done means the reported score reflects the differing field weights while document 1 remains ranked higher.

Written by the indexing model from the issue text.

Assessment

Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.