Overhaul the snippet implementation
commitb2f228d7c64d36f38ad17ea34c618e3f7744a86d
authorOlly Betts <olly@survex.com>
Wed, 6 Jan 2016 03:57:27 +0000 (6 16:57 +1300)
committerOlly Betts <olly@survex.com>
Wed, 6 Jan 2016 03:57:27 +0000 (6 16:57 +1300)
treeeca64c8a1809e02dd1a1dd5f9f2b8cfae4e874f9
parenta6cbcf9ee8c091adef1547571ac502f8c78343c2
Overhaul the snippet implementation

The approach from the paper Mihai based his implementation on doesn't
directly consider the query, but instead looks at the top few documents
matched and builds a document language model.  In theory this is a nice
approach - it has a sound theoretical basis, and it will consider
interesting terms outside of the query.  But in practice, this turns out
to have a serious drawback - it sometimes selects a snippet which
doesn't contain any of the query terms, and users find that surprising
(quite reasonably I think).  It's also slower than is ideal.

We also had a patch for generating snippets from fastmail, but that has
different drawbacks - for example, its segmenting of text doesn't
exactly match what TermGenerator produces, so it fails to highlight in
some cases; also it considers each term in turn, so doesn't prefer a
snippet containing more terms from the query.

So I've taken the best ideas from each, and implemented a new snippet
generating algorithm.  A key design choice is that it makes a single
pass over the text we're generating the snippet from (with scope to
terminate early).  It prefers occurrences of the query terms in contexts
containing "interesting" non-query terms.  And it also handles exact
phrases and wildcards (both selecting snippets based on them, and
highlighting them).

Fixes #211.
xapian-core/api/omenquire.cc
xapian-core/api/omenquireinternal.h
xapian-core/api/queryinternal.h
xapian-core/include/xapian/enquire.h
xapian-core/queryparser/termgenerator_internal.cc
xapian-core/tests/Makefile.am
xapian-core/tests/api_snipper.cc
xapian-core/tests/testdata/snippet.txt [new file with mode: 0644]
xapian-core/weight/weightinternal.h