You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Phrases across line boundaries: configurable position gap for multi-valued fields?
#3149
We index a library of books one line (paragraph) per document, because results, counts and navigation are per line. Users expect a phrase to match even when it straddles two consecutive lines, e.g. "waters and said" where waters ends line N and and said opens line N+1. Today that is impossible: a phrase only ever matches inside one field of one document.
We are solving it in our engine with a custom Query, built on the public API. At index time we store each line's first and last content position as FAST fields. At query time each phrase is split at every word boundary: the left half must end at the line's last position, the right half must start at the next line's first position, and the hits are joined on our own consecutive line id. That works for us, but it got me wondering what a Tantivy-native answer would look like. Two directions came to mind:
1. A configurable position gap between the values of a multi-valued text field. POSITION_GAP is hard-coded to 1 in postings_writer.rs. Lucene exposes the same thing per field as position_increment_gap.
With a gap of 0, a phrase could cross from one value to the next.
With a large gap, phrases (and sloppy phrases) would be kept inside one value.
This would make the usual "index the bigger unit, keep the lines as values" design work for cross-line phrases. Today a gap of 1 means an exact phrase never crosses values, while slop >= 1 silently does.
2. Knowing which value a match came from.
If a section were one document with each line as a value, we would still need to report the matching line. That means mapping a match position back to its value index (and ideally to an offset inside it). A per-document list of value start positions would be enough, or a helper on the phrase scorer that exposes match positions.
Questions:
Would a per-field position gap (an option on TextOptions/TextFieldIndexing) be acceptable upstream? I'd be happy to send a PR.
Is there interest in exposing match positions or value boundaries, or is that intentionally out of scope?
Is there a recommended pattern for "phrase across adjacent documents" that I'm missing?
Phrases that span documents (adjacency by a user field) seem clearly out of scope for Tantivy; I'm mentioning them only as the motivation.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
We index a library of books one line (paragraph) per document, because results, counts and navigation are per line. Users expect a phrase to match even when it straddles two consecutive lines, e.g.
"waters and said"wherewatersends line N andand saidopens line N+1. Today that is impossible: a phrase only ever matches inside one field of one document.We are solving it in our engine with a custom
Query, built on the public API. At index time we store each line's first and last content position as FAST fields. At query time each phrase is split at every word boundary: the left half must end at the line's last position, the right half must start at the next line's first position, and the hits are joined on our own consecutive line id. That works for us, but it got me wondering what a Tantivy-native answer would look like. Two directions came to mind:1. A configurable position gap between the values of a multi-valued text field.
POSITION_GAPis hard-coded to1inpostings_writer.rs. Lucene exposes the same thing per field asposition_increment_gap.0, a phrase could cross from one value to the next.This would make the usual "index the bigger unit, keep the lines as values" design work for cross-line phrases. Today a gap of 1 means an exact phrase never crosses values, while
slop >= 1silently does.2. Knowing which value a match came from.
If a section were one document with each line as a value, we would still need to report the matching line. That means mapping a match position back to its value index (and ideally to an offset inside it). A per-document list of value start positions would be enough, or a helper on the phrase scorer that exposes match positions.
Questions:
TextOptions/TextFieldIndexing) be acceptable upstream? I'd be happy to send a PR.Phrases that span documents (adjacency by a user field) seem clearly out of scope for Tantivy; I'm mentioning them only as the motivation.
All reactions