Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using the FVH and Postings Highlighter without storing extra data #5184

Closed
wants to merge 14 commits into from
22 changes: 16 additions & 6 deletions docs/reference/search/request/highlighting.asciidoc
Expand Up @@ -66,11 +66,11 @@ a query match, effectively ignoring their positions.

==== Fast vector highlighter

If `term_vector` information is provided by setting `term_vector` to
`with_positions_offsets` in the mapping then the fast vector highlighter
will be used instead of the plain highlighter. The fast vector highlighter:
If positiong and offsets are stored in term vectors on the field then the
fast vector highlighter will be used instead of the plain highlighter. The
fast vector highlighter:

* Is faster especially for large fields (> `1MB`)
* Is faster for large fields (> `1MB`) but slower for small fields
* Can be customized with `boundary_chars`, `boundary_max_scan`, and
`fragment_offset` (see <<boundary-characters,below>>)
* Requires setting `term_vector` to `with_positions_offsets` which
Expand All @@ -82,8 +82,8 @@ will be used instead of the plain highlighter. The fast vector highlighter:
highlighting a Boosting Query that boosts phrase matches over term matches

Here is an example of setting the `content` field to allow for
highlighting using the fast vector highlighter on it (this will cause
the index to be bigger):
highlighting using the fast vector highlighter on it. This will store
term vectors for all fields regardless of length.

[source,js]
--------------------------------------------------
Expand All @@ -94,6 +94,7 @@ the index to be bigger):
}
--------------------------------------------------


==== Force highlighter type

The `type` field allows to force a specific highlighter type. This is useful
Expand All @@ -113,6 +114,15 @@ The following is an example that forces the use of the plain highlighter:
}
--------------------------------------------------


Forcing a highlighter for which requires extra data will fail if the extra
data is saved. For example, forcing the `postings` highlighter without
`index_options` set to `offsets` will cause an error.

coming[1.1.0]
You can force any highlighter regardless of the extra data stored at the
at the cost of extra CPU time per field.

==== Force highlighting on source

added[1.0.0.RC1]
Expand Down
Expand Up @@ -91,8 +91,7 @@ public CustomPostingsHighlighter(CustomPassageFormatter passageFormatter, List<O
/*
Our own api to highlight a single document field, passing in the query terms, and get back our own Snippet object
*/
public Snippet[] highlightDoc(String field, BytesRef[] terms, IndexSearcher searcher, int docId, int maxPassages) throws IOException {
IndexReader reader = searcher.getIndexReader();
public Snippet[] highlightDoc(String field, BytesRef[] terms, IndexReader reader, int docId, int maxPassages) throws IOException {
IndexReaderContext readerContext = reader.getContext();
List<AtomicReaderContext> leaves = readerContext.leaves();

Expand Down
Expand Up @@ -25,24 +25,24 @@
import org.apache.lucene.queries.TermFilter;
import org.apache.lucene.search.*;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.util.Version;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
import org.elasticsearch.common.lucene.search.XBooleanFilter;
import org.elasticsearch.common.lucene.search.XFilteredQuery;
import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.search.highlight.AbstractDelegatingOrAnalyzingReader.TermSetSource;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
*
*/
// LUCENE MONITOR
public class CustomFieldQuery extends FieldQuery {
public class CustomFieldQuery extends FieldQuery implements TermSetSource {

private static Field multiTermQueryWrapperFilterQueryField;

Expand Down Expand Up @@ -158,4 +158,9 @@ void flatten(Filter sourceFilter, IndexReader reader, Collection<Query> flatQuer
}
}
}

@Override
public Set<String> termSet(String field) {
return getTermSet(field);
}
}