Sameer Negi
04/16/2026, 11:45 AM6PK2100, 09103M08013, F5TZ-9C331-B, etc.
We want results ranked in this specific order:
1. Query matches the start of the part number ā rank highest (e.g. "6PK" ā "6PK2100")
2. Query matches the end of the part number ā rank second (e.g. "2100" ā "6PK2100")
3. Query matches somewhere in the middle ā rank third (e.g. "PK21" ā "6PK2100")
Our current schema (relevant fields):
⢠partNumber ā index: true, infix: false
⢠partName ā index: true, infix: false
⢠token_separators: []
We also currently have no token_separators configured, so hyphenated/dotted part numbers like F5TZ-9C331-B are indexed as a single token.
What we want guidance on:
1. Is there any native way in Typesense to rank by match position (prefix ā postfix ā substring) as a sort dimension? is there something we're missing?
2. If native positional ranking isn't supported, what is the recommended approach.
3. To even surface all three match types, should we enable infix: true on partNumber (and partName)? What are the realistic performance implications?
4. Should we add common part number separators like -, ., / to token_separators? Would this help, or would it break exact part number matches?
Would really appreciate any guidance on the schema changes (if any) and whether positional ranking is on the roadmap or achievable today. Thanks!
@Sahil RallyAlan Martini
04/16/2026, 3:25 PMinfix: true on the field and pass infix=always at query time. The infix code path bucket-scores all middle and suffix matches together, so out of the box you can't sort "ends with" above "appears in the middle".
Prefix matches get a real _text_match score, infix matches are pinned to a fixed lower score, and the official test asserts prefix.text_match > infix.text_match.
You have two options depending on how strict you need that suffix-above-middle ordering:
⢠Two tiers (simplest): set infix: true on partNumber, query with infix=always. Prefix on top, everything else below. Good enough if "appears anywhere" is acceptable as the bottom bucket.
⢠Three tiers via reversed field + `/multi_search`: store each part number both forwards and reversed, then fire 3 searches in parallel and stitch them on the client. Reversed field is the standard trick to turn "suffix" into "prefix":
{
"name": "parts",
"token_separators": [
"-",
".",
"/"
],
"fields": [
{
"name": "partNumber",
"type": "string",
"infix": true
},
{
"name": "partNumberReversed",
"type": "string",
"infix": false
},
{
"name": "partName",
"type": "string",
"infix": true
}
]
}
At index time:
{
partNumber: "6PK2100",
partNumberReversed: "0012KP6"
}
At query time:
const q = "PK21";
const qR = q.split("").reverse().join("");
multi_search([
{ q, query_by: "partNumber", prefix: true, infix: "off" }, // tier 1
{ q: qR, query_by: "partNumberReversed", prefix: true, infix: "off" }, // tier 2
{ q, query_by: "partNumber", prefix: true, infix: "always" }, // tier 3
]);
Then merge client side, deduping IDs from top tier downward. That gives you exactly the prefix ā suffix ā middle ranking.
The only gotcha is that infix is a heavy operation. For 670k SKUs of short alphanumeric tokens, p95 is typically acceptable on modern hardware, but it grows with cardinality. There's a built-in safety net (search_cutoff_ms, default 30s) and if a query saturates it you'll see search_cutoff: true in the response.
I'd benchmark on a representative slice before committing and keep an eye on search_cutoff in the response.
About Adding -, ., / to `token_separators`:
Yes, generally a net win for SKU data. The tokenizer treats those characters as splits, so F5TZ-9C331-B becomes 3 tokens: ["f5tz", "9c331", "b"]. That buys you:
⢠A query for 9C331 becomes a fast exact token match instead of a slow infix scan.
⢠The full F5TZ-9C331-B query still works, because it's also tokenized into the same 3 tokens and Typesense AND-merges them by default.
⢠F5TZ matches as a clean prefix of the first token.
The trade-off: infix can no longer match across a separator, so Z-9C won't match anymore because - is no longer part of any token. For your mixed dataset (some hyphenated SKUs, some not), the segmented tokens become first-class prefix-matchable, which is the cheaper path. Solid recommendation.
Positional ranking as a native sort dimension beyond the prefix vs infix split isn't something I can see on the public roadmap right now. Let us know how the testing goes, happy to look at specific queries once you have a config in place!Sameer Negi
04/17/2026, 6:39 AM9C331-XYZ ā true string prefix match ā ranks high
- F5TZ-9C331-B ā infix match ā ranks below
The prefix-beats-infix guarantee works perfectly here.
But after adding - to token_separators, both part numbers get tokenized:
- 9C331-XYZ ā tokens ["9c331", "xyz"] ā query matches 9c331 as a prefix of a token
- F5TZ-9C331-B ā tokens ["f5tz", "9c331", "b"] ā query also matches 9c331 as a prefix of a token
Both are now token-level prefix matches of identical quality. So F5TZ-9C331-B ā which is a mid-string match on the full part number string, now gets the same _text_match score as 9C331-XYZ which is a true string prefix match. The prefix-beats-infix tier that helps us no longer applies because the mid-string match is no longer going through the infix code path at all.
Is this correct? If so, does Typesense have any awareness of which token position matched e.g. would a match on the first token score higher than a match on the second or third token for the same query? Or are all token-level prefix matches scored equally regardless of where in the document field the token appears?
Thanks!Alan Martini
04/21/2026, 6:55 PMprioritize_token_position=true does exactly this. A match on the first token scores higher than a match on the second or third. By default it is off, so your analysis is correct: without it, both matches get the same _text_match score.