@Override public Object clone() { try { Presentation clone = (Presentation)super.clone(); if (boldingData != null) clone.boldingData = new ArrayList<>(boldingData); if (highlight != null) clone.highlight = highlight.clone(); if (summaryFields != null) { clone.summaryFields = LazySet.newHashSet(); clone.summaryFields.addAll(this.summaryFields); } return clone; } catch (CloneNotSupportedException e) { throw new RuntimeException("Someone inserted a noncloneable superclass",e); } }
private void traverseHighlight(Highlight highlight, IndexFacts.Session indexFacts) { if (highlight == null) return; for (AndItem item : highlight.getHighlightItems().values()) { traverse(item, indexFacts); } }
/** Prepares this for binary serialization. For internal use - see {@link Query#prepare} */ public void prepare() { if (highlight != null) highlight.prepare(); }
/** * Add custom highlight term * * @param field Field name * @param item Term to be highlighted */ public void addHighlightTerm(String field, String item) { addHighlightItem(field, new WordItem(toLowerCase(item), field, true)); }
/** * Encodes properties of this query. * * @param buffer the buffer to encode to * @param encodeQueryData true to encode all properties, false to only include session information, not actual query data * @return the encoded length */ public int encodeAsProperties(ByteBuffer buffer, boolean encodeQueryData) { // Make sure we don't encode anything here if we have turned the property feature off // Due to sendQuery we sometimes end up turning this feature on and then encoding a 0 int as the number of // property maps - that's ok (probably we should simplify by just always turning the feature on) if (! hasEncodableProperties()) return 0; int start = buffer.position(); int mapCountPosition = buffer.position(); buffer.putInt(0); // map count will go here int mapCount = 0; // TODO: Push down mapCount += ranking.getProperties().encode(buffer, encodeQueryData); if (encodeQueryData) mapCount += ranking.getFeatures().encode(buffer); // TODO: Push down if (encodeQueryData && presentation.getHighlight() != null) mapCount += MapEncoder.encodeStringMultiMap(Highlight.HIGHLIGHTTERMS, presentation.getHighlight().getHighlightTerms(), buffer); // TODO: Push down if (encodeQueryData) mapCount += MapEncoder.encodeSingleValue("model", "searchpath", model.getSearchPath(), buffer); mapCount += MapEncoder.encodeSingleValue(DocumentDatabase.MATCH_PROPERTY, DocumentDatabase.SEARCH_DOC_TYPE_KEY, model.getDocumentDb(), buffer); mapCount += MapEncoder.encodeMap("caches", createCacheSettingMap(), buffer); buffer.putInt(mapCountPosition, mapCount); return buffer.position() - start; }
/** * Add custom highlight phrase * @param field Field name * @param phrase List of terms to be highlighted as a phrase */ public void addHighlightPhrase(String field, List<String> phrase) { PhraseItem pi = new PhraseItem(); pi.setIndexName(field); for (String s : phrase) { pi.addItem(new WordItem(toLowerCase(s), field, true)); } addHighlightItem(field, pi); }
this.highlightTerms.clear(); for (String index : getHighlightItems().keySet()) { AndItem root = getHighlightItems().get(index); List<WordItem> words = new ArrayList<>(); List<CompositeItem> phrases = new ArrayList<>();
public boolean hasEncodableProperties() { if ( ! ranking.getProperties().isEmpty()) return true; if ( ! ranking.getFeatures().isEmpty()) return true; if ( ranking.getFreshness() != null) return true; if ( model.getSearchPath() != null) return true; if ( model.getDocumentDb() != null) return true; if ( presentation.getHighlight() != null && ! presentation.getHighlight().getHighlightItems().isEmpty()) return true; return false; }
@Override public Result search(Query query, Execution execution) { if (query.properties().getBoolean(DISABLE)) return execution.search(query); IndexFacts.Session indexFacts = execution.context().getIndexFacts().newSession(query); Item newRoot = replaceTerms(query, indexFacts); query.getModel().getQueryTree().setRoot(newRoot); query.trace(getFunctionName(), true, 2); Highlight highlight = query.getPresentation().getHighlight(); if (highlight != null) { Set<String> highlightFields = highlight.getHighlightItems().keySet(); for (String field : highlightFields) { StemMode stemMode = indexFacts.getIndex(field).getStemMode(); if (stemMode != StemMode.NONE) { StemContext context = new StemContext(); context.language = Language.ENGLISH; context.indexFacts = indexFacts; Item newHighlight = scan(highlight.getHighlightItems().get(field), context); highlight.getHighlightItems().put(field, (AndItem)newHighlight); } } } return execution.search(query); }