/** * Forces the offset source for this highlighter */ @Override protected OffsetSource getOffsetSource(String field) { if (offsetSource == null) { return super.getOffsetSource(field); } return offsetSource; }
/** * Highlights terms extracted from the provided query within the content of the provided field name */ public Snippet[] highlightField(String field, Query query, int docId, int maxPassages) throws IOException { Map<String, Object[]> fieldsAsObjects = super.highlightFieldsAsObjects(new String[]{field}, query, new int[]{docId}, new int[]{maxPassages}); Object[] snippetObjects = fieldsAsObjects.get(field); if (snippetObjects != null) { //one single document at a time assert snippetObjects.length == 1; Object snippetObject = snippetObjects[0]; if (snippetObject != null && snippetObject instanceof Snippet[]) { return (Snippet[]) snippetObject; } } return EMPTY_SNIPPET; }
CharacterRunAutomaton[] automata) { OffsetSource res = super.getOptimizedOffsetSource(field, terms, phraseHelper, automata); if (res == OffsetSource.ANALYSIS) {
private void reset(IndexSearcher searcher) { if (lastSearcher == searcher) { return; } lastSearcher = searcher; highlighter = new UnifiedHighlighter(searcher, analyzer) { @Override protected OffsetSource getOffsetSource(String field) { return offsetSource != null ? offsetSource : super.getOffsetSource(field); } }; highlighter.setBreakIterator(() -> BreakIterator.getSentenceInstance(Locale.ENGLISH)); highlighter.setMaxLength(maxDocCharsToAnalyze); highlighter.setHighlightPhrasesStrictly(true); highlighter.setHandleMultiTermQuery(true); }
protected List<CharSequence[]> loadFieldValues(String[] fields, DocIdSetIterator docIter, int cacheCharsThreshold) throws IOException { return super.loadFieldValues(storedFields, docIter, cacheCharsThreshold); }
@Override public void withTopDocs(IndexSearcher searcher, Query q, TopDocs hits) throws Exception { reset(searcher); Map<String, String[]> result = highlighter.highlightFields(fields, q, hits, maxPassages); preventOptimizeAway = result.size(); } }
/** * Forces the offset source for this highlighter */ @Override protected OffsetSource getOffsetSource(String field) { if (offsetSource == null) { return super.getOffsetSource(field); } return offsetSource; }
/** * Highlights terms extracted from the provided query within the content of the provided field name */ public Snippet[] highlightField(String field, Query query, int docId, int maxPassages) throws IOException { Map<String, Object[]> fieldsAsObjects = super.highlightFieldsAsObjects(new String[]{field}, query, new int[]{docId}, new int[]{maxPassages}); Object[] snippetObjects = fieldsAsObjects.get(field); if (snippetObjects != null) { //one single document at a time assert snippetObjects.length == 1; Object snippetObject = snippetObjects[0]; if (snippetObject != null && snippetObject instanceof Snippet[]) { return (Snippet[]) snippetObject; } } return EMPTY_SNIPPET; }
/** * Forces the offset source for this highlighter */ @Override protected OffsetSource getOffsetSource(String field) { if (offsetSource == null) { return super.getOffsetSource(field); } return offsetSource; }
/** * Highlights terms extracted from the provided query within the content of the provided field name */ public Snippet[] highlightField(String field, Query query, int docId, int maxPassages) throws IOException { Map<String, Object[]> fieldsAsObjects = super.highlightFieldsAsObjects(new String[]{field}, query, new int[]{docId}, new int[]{maxPassages}); Object[] snippetObjects = fieldsAsObjects.get(field); if (snippetObjects != null) { //one single document at a time assert snippetObjects.length == 1; Object snippetObject = snippetObjects[0]; if (snippetObject != null && snippetObject instanceof Snippet[]) { return (Snippet[]) snippetObject; } } return EMPTY_SNIPPET; }
@Override protected OffsetSource getOffsetSource(String field) { return offsetSource != null ? offsetSource : super.getOffsetSource(field); } };
/** * Highlights terms extracted from the provided query within the content of the provided field name */ public Snippet[] highlightField(String field, Query query, int docId, int maxPassages) throws IOException { Map<String, Object[]> fieldsAsObjects = super.highlightFieldsAsObjects(new String[]{field}, query, new int[]{docId}, new int[]{maxPassages}); Object[] snippetObjects = fieldsAsObjects.get(field); if (snippetObjects != null) { //one single document at a time assert snippetObjects.length == 1; Object snippetObject = snippetObjects[0]; if (snippetObject != null && snippetObject instanceof Snippet[]) { return (Snippet[]) snippetObject; } } return EMPTY_SNIPPET; }