Hi everyone! I’m having some trouble getting pref...
# community-help
t
Hi everyone! I’m having some trouble getting prefix matches to work as I expect; with a small corpus of 10 documents with names starting with
John
, 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:
Copy code
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" }'
Copy code
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}
Copy code
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!
j
@Toby Marsden This sounds like a bug. Mind opening an issue on Github so we can track it? Really appreciate the default minimal reproduceable test case! 🙏
t
@Jason Bosco Thanks for the quick response. Sure thing: https://github.com/typesense/typesense/issues/348
j
Awesome, will keep you posted via Github