Master

Debugging an engine that answers wrong

A wrong answer is wrong at one step. The steps are the places, and the places are the reason a wrong answer is a question rather than a hunt.

What you will see

2:posting wrong. The first wrong print names the place, which is the fix.

About 1 min of reading

Try It

Print the three places

1

Print the parse

printf 'words red fish op AND\n' > /tmp/q.txt; cat /tmp/q.txt

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

What it prints
One line with words and an operator. The parse is compared to the typed words.
2

Print a posting

printf 'red 0 2 5\n' | awk '{print NF-1}'

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

What it prints
3. Three ids is the posting length, checked against the library.
3

Name the first wrong print

printf 'parse ok\nposting wrong\nscore unknown\n' > /tmp/w.txt; grep -n wrong /tmp/w.txt

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

What it prints
2:posting wrong. The first wrong print names the place, which is the fix.

Data Flow

A wrong answer to one place
1 The parsed query is printed
↓
2 The posting for a word is printed
↓
3 The score parts are printed per document
↓
4 The first wrong print names the place
Why this works
Why the three prints are ordered

Each narrows the next. A wrong parse makes the posting print meaningless, so the parse is asked first.

The record of a debug run

The three prints in one file. The file names one place, and one place is the fix.

Examples

The first place is the query parse

The parsed query is printed. A printed parse is a parse that can be compared to the words the reader typed.

The second place is the posting

The posting for a word is printed. A printed posting is a posting that can be checked against the library.

The third place is the score

The parts are printed per document. Printed parts are parts that name which claim is wrong.

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.

← Building an index that fits
Previous Lesson
Building an index that fits
Next Lesson
Shipping an engine that is bounded
Shipping an engine that is bounded →