Skip to content
Astera Technology

Match index and query tokenisation rules

Execute a small inverted index and its actual query analysis.

Download complete case notes and answer keys ↓

Set the decision and its input

The synthetic index splits uppercase ASCII text at non-letter/digit separators. AB-12 becomes tokens AB and12. A query analyser retaining the whole AB-12 finds no indexed token. The corrected query uses the same split rule and matches D1 while excluding AB-56 in D2.

Filled local test worksheet
CaseInput JSON
Base test{"query":"AB-12","documents":[{"id":"D1","text":"AB-12"},{"id":"D2","text":"AB-56"}]}
Download editable CSV ↓

Run the supplied comparison

The programme builds the token-to-document sets and executes their intersection. It does not supply an exact-code identity policy, stemming engine or a real search provider’s feature set.

Faulty and required outputs
PathOutput JSON
Faulty path{"queryTokens":["AB-12"],"matches":[]}
Required path{"queryTokens":["AB","12"],"matches":["D1"]}
Download editable CSV ↓
Complete local Node24.14.1 programme
import assert from 'node:assert/strict';

const run=function run(i,corrected=true){
    const tokenize=s=>s.split(/[^A-Z0-9]+/).filter(Boolean),index=new Map();
    for(const d of i.documents)for(const token of tokenize(d.text)){if(!index.has(token))index.set(token,new Set());index.get(token).add(d.id);}
    const query=corrected?tokenize(i.query):[i.query];if(query.length===0)return {held:true,reason:'empty-analysis'};
    return {queryTokens:query,matches:i.documents.filter(d=>query.every(t=>index.get(t)?.has(d.id))).map(d=>d.id)};
  };
const cases=[{"input":{"query":"AB-12","documents":[{"id":"D1","text":"AB-12"},{"id":"D2","text":"AB-56"}]},"corrected":false,"expected":{"queryTokens":["AB-12"],"matches":[]}},{"input":{"query":"AB-12","documents":[{"id":"D1","text":"AB-12"},{"id":"D2","text":"AB-56"}]},"corrected":true,"expected":{"queryTokens":["AB","12"],"matches":["D1"]}},{"input":{"query":"AB 12","documents":[{"id":"D1","text":"AB-12"},{"id":"D2","text":"AB-56"}]},"corrected":true,"expected":{"queryTokens":["AB","12"],"matches":["D1"]}},{"input":{"query":"---","documents":[{"id":"D1","text":"AB-12"}]},"corrected":true,"expected":{"held":true,"reason":"empty-analysis"}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Download runnable example ↓

Choose from the boundary evidence

The query AB 12 uses a space and still matches the same two tokens. A punctuation-only query yields no tokens and is held, avoiding an empty-loop all-documents result.

  1. Inspect index analysis
  2. Analyse the query identically
  3. Execute token intersection

An empty analysed query is unresolved, not all documents matched.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
token pair separated by space{"query":"AB 12","documents":[{"id":"D1","text":"AB-12"},{"id":"D2","text":"AB-56"}]}{"queryTokens":["AB","12"],"matches":["D1"]}
analysis gives no tokens{"query":"---","documents":[{"id":"D1","text":"AB-12"}]}{"held":true,"reason":"empty-analysis"}
Download editable CSV ↓

Why does the repaired base query match D1?

Show the worked answer

Both AB and12 exist for D1 under the same declared analyser. D2 lacks12; raw AB-12 was never an index token.

Related resources