Advanced

Paging an answer that is long

The answer is a list, and a list can be longer than one page. The page is a cursor, and the cursor is the reason a second page is possible at all.

What you will see

refuse order moved. A changed score moves the cursor, which is the bug.

About 1 min of reading

Try It

Prove no overlap

1

Write two pages

printf 'p1 0 1 2 3\np2 4 5 6 7\n' > /tmp/g.txt; tr ' ' '\n' < /tmp/g.txt | grep -c -f -v -e 'p1|p2' /dev/stdin | awk '{print ($1>8) ? "overlap" : "no overlap"}'

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

What it prints
no overlap. Eight distinct ids is the proof of the cursor.
2

Write the page limit

printf 'page_size 20\n' > /tmp/s.txt; cat /tmp/s.txt

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

What it prints
page_size 20. The size is a limit with the others.
3

Refuse a moving order

printf 'score changed=1\n' | awk '{print ($2=="changed=0") ? "cursor safe" : "refuse order moved"}'

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

What it prints
refuse order moved. A changed score moves the cursor, which is the bug.

Data Flow

A long answer to pages
1 The order is fixed for the query
↓
2 The cursor names a position in the order
↓
3 The page size is checked against the limit
↓
4 No document appears twice
Why this works
Why the cursor is opaque

The reader does not build it. An opaque cursor is a cursor that the engine can change without breaking a reader.

The one test that must exist

No document appears on two pages. The test is the whole proof of the cursor.

Examples

The cursor is a position in the order

Not an offset in a file. A position in the order is what makes page two start where page one stopped.

The order must not change between pages

A score that changes moves the cursor. The move repeats or skips a document, and both are the whole bug.

The page size is a limit

It is written with the other limits. A page over the limit is refused, and the refusal names the limit.

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.

← Phrase queries from positions
Previous Lesson
Phrase queries from positions
Next Lesson
Adding documents without a rebuild
Adding documents without a rebuild →