Basic

Answering a query

A query is words looked up and postings combined. Combining is the decision, and the decision is written rather than remembered.

What you will see

empty answer. Empty is an answer, which is the honest claim.

About 1 min of reading

Try It

Answer AND and OR

1

Write two postings

printf 'red 0 2 5\nfish 0 1 2\n' > /tmp/p.txt; awk 'NR==1{for(i=2;i<=NF;i++)a[$i]=1} NR==2{for(i=2;i<=NF;i++)if(a[$i])print $i}' /tmp/p.txt | sort -n

Before you run it, say out loud what it will print. Then open the answer.

What it prints
0 and 2. Those are the documents with both words, which is AND.
2

Answer OR

printf 'red 0 2 5\nfish 0 1 2\n' | tr ' ' '\n' | grep -c -f -v -e 'red|fish' /dev/stdin

Before you run it, say out loud what it will print. Then open the answer.

What it prints
6. Six ids before dedupe is the union before the walk, which is OR.
3

Answer a missing key

printf 'key=unicorn found=0\n' | awk '{print ($2=="found=1") ? "list" : "empty answer"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
empty answer. Empty is an answer, which is the honest claim.

Data Flow

A query to a list of ids
1 Each word is looked up as a key
↓
2 A missing key answers empty
↓
3 The smallest posting is walked first
↓
4 The postings are combined by the chosen rule
Why this works
Why the combine is chosen per query

The shape of the answer changes with the word count. The smallest posting is walked first, and the choice is a written rule.

The answer is a list of ids

Not documents. Ids are what the answer is allowed to hold, and the ids are resolved at the end.

Examples

AND is an intersection

The answer has documents with every word. Every word is the claim, and the claim is the whole of AND.

OR is a union

The answer has documents with any word. Any word is a different claim, and a different claim is a different answer.

A word that is not a key answers empty

Empty is an answer, not a failure. The answer is honest because the key was checked.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Stopwords as a written decision
Previous Lesson
Stopwords as a written decision
Next Lesson
Ranking as a score with a reason
Ranking as a score with a reason →