Toby Marsden
08/16/2021, 4:44 PMJohn
, a prefix search for John W
correctly shows John Williams
with a text_match
higher than the other Johns. But if you start the second word with the same letter that the first word starts with, i.e. John J
, the text_match
is the same for all results and therefore the order isn’t what you’d expect:
curl "<http://localhost:8108/collections>" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '{
"name": "johns",
"fields": [
{"name": "name", "type": "string" }
]
}'
curl "<http://localhost:8108/collections/johns/documents/import?action=create>" -X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '{ "id": "1", "name": "John Stark" }
{ "id": "1", "name": "John Atwood" }
{ "id": "2", "name": "John Smith" }
{ "id": "3", "name": "John Johnson" }
{ "id": "4", "name": "John Williams" }
{ "id": "5", "name": "John Brown" }
{ "id": "6", "name": "John Jones" }
{ "id": "7", "name": "John Garcia" }
{ "id": "8", "name": "John Miller" }
{ "id": "9", "name": "John Keller" }
{ "id": "10", "name": "John Davis" }'
curl -H "X-TYPESENSE-API-KEY: xyz" \
"<http://localhost:8108/collections/johns/documents/search>\
?q=John%20W&query_by=name&per_page=3"
{"facet_counts":[],"found":11,"hits":[{"document":{"id":"4","name":"John Williams"},"highlights":[{"field":"name","matched_tokens":["John","Williams"],"snippet":"<mark>John</mark> <mark>Williams</mark>"}],"text_match":50225924},{"document":{"id":"10","name":"John Davis"},"highlights":[{"field":"name","matched_tokens":["John"],"snippet":"<mark>John</mark> Davis"}],"text_match":33514496},{"document":{"id":"9","name":"John Keller"},"highlights":[{"field":"name","matched_tokens":["John"],"snippet":"<mark>John</mark> Keller"}],"text_match":33514496}],"out_of":11,"page":1,"request_params":{"collection_name":"johns","per_page":3,"q":"John W"},"search_time_ms":8}
curl -H "X-TYPESENSE-API-KEY: xyz" \
"<http://localhost:8108/collections/johns/documents/search>\
?q=John%20J&query_by=name&per_page=3"
{"facet_counts":[],"found":11,"hits":[{"document":{"id":"10","name":"John Davis"},"highlights":[{"field":"name","matched_tokens":["John"],"snippet":"<mark>John</mark> Davis"}],"text_match":50226176},{"document":{"id":"9","name":"John Keller"},"highlights":[{"field":"name","matched_tokens":["John"],"snippet":"<mark>John</mark> Keller"}],"text_match":50226176},{"document":{"id":"8","name":"John Miller"},"highlights":[{"field":"name","matched_tokens":["John"],"snippet":"<mark>John</mark> Miller"}],"text_match":50226176}],"out_of":11,"page":1,"request_params":{"collection_name":"johns","per_page":3,"q":"John J"},"search_time_ms":14}
Any ideas? Thanks!Jason Bosco
08/16/2021, 7:06 PMToby Marsden
08/16/2021, 7:47 PMJason Bosco
08/16/2021, 8:27 PM