Reading — step 1 of 5
Read
~1 min readBoolean Queries
Phrase Queries
"the quick brown fox" should match documents where these words appear IN ORDER, ADJACENT.
To support this, the inverted index stores positions along with doc IDs:
quick -> {doc1: [3, 17, 89], doc2: [4]} # term appears at these positions
brown -> {doc1: [4, 18], doc2: [5]}
fox -> {doc1: [5, 19], doc2: [6]}
For phrase "quick brown fox":
- Look up each term's positions per doc.
- Intersect docs (must contain all 3 terms).
- For each remaining doc, find positions where:
quickat position pbrownat position p+1foxat position p+2
Algorithm: for each pair of consecutive terms, check if any quick position p has brown at p+1, etc.
python
Variants: proximity search ("quick fox"~3 = words within 3 of each other), ordered proximity (must appear in this order, but with up to N words between).
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…