/** * Adds a field to be highlighted with a provided fragment size (in characters), and * default number of fragments of 5. * * @param name The field to highlight * @param fragmentSize The size of a fragment in characters */ public T addHighlightedField(String name, int fragmentSize) { highlightBuilder().field(name, fragmentSize); return (T) this; }
/** * Should each {@link org.elasticsearch.search.SearchHit} be returned with an * explanation of the hit (ranking). */ public T setExplain(boolean explain) { sourceBuilder().explain(explain); return (T) this; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (path != null) { builder.startObject("path").startObject(path); } else { builder.startObject("type").startObject(type); } super.toXContent(builder, params); return builder.endObject().endObject(); } }
/** * Sets the size of the fragment to return from the beginning of the field if there are no matches to * highlight and the field doesn't also define noMatchSize. * @param noMatchSize integer to set or null to leave out of request. default is null. * @return this builder for chaining */ public T setHighlighterNoMatchSize(Integer noMatchSize) { highlightBuilder().noMatchSize(noMatchSize); return (T) this; }
/** * Sets no fields to be loaded, resulting in only id and type to be returned per field. */ public T setNoFields() { sourceBuilder().noFields(); return (T) this; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { super.toXContent(builder, params); if (name != null) { builder.field("name", name); } return builder; }
/** * Adds a field to be highlighted with default fragment size of 100 characters, and * default number of fragments of 5. * * @param name The field to highlight */ public T addHighlightedField(String name) { highlightBuilder().field(name); return (T) this; }
/** * Indicates whether the response should contain the stored _source for every hit */ public T setFetchSource(boolean fetch) { sourceBuilder().fetchSource(fetch); return (T) this; }
/** * Set a tag scheme that encapsulates a built in pre and post tags. The allows schemes * are <tt>styled</tt> and <tt>default</tt>. * * @param schemaName The tag scheme name */ public T setHighlighterTagsSchema(String schemaName) { highlightBuilder().tagsSchema(schemaName); return (T) this; }
/** * Applies when sorting, and controls if scores will be tracked as well. Defaults to * <tt>false</tt>. */ public T setTrackScores(boolean trackScores) { sourceBuilder().trackScores(trackScores); return (T) this; }
/** * The order of fragments per field. By default, ordered by the order in the * highlighted text. Can be <tt>score</tt>, which then it will be ordered * by score of the fragments. */ public T setHighlighterOrder(String order) { highlightBuilder().order(order); return (T) this; }
/** * Should each {@link org.elasticsearch.search.SearchHit} be returned with its * version. */ public T setVersion(boolean version) { sourceBuilder().version(version); return (T) this; }
/** * Adds a field to be highlighted with a provided fragment size (in characters), and * a provided (maximum) number of fragments. * * @param name The field to highlight * @param fragmentSize The size of a fragment in characters * @param numberOfFragments The (maximum) number of fragments */ public T addHighlightedField(String name, int fragmentSize, int numberOfFragments) { highlightBuilder().field(name, fragmentSize, numberOfFragments); return (T) this; }
/** * Adds a sort against the given field name and the sort ordering. * * @param field The name of the field * @param order The sort ordering */ public T addSort(String field, SortOrder order) { sourceBuilder().sort(field, order); return (T) this; }
/** * Explicitly set the post tags that will be used for highlighting. */ public T setHighlighterPostTags(String... postTags) { highlightBuilder().postTags(postTags); return (T) this; }
/** * The index to start to return hits from. Defaults to <tt>0</tt>. */ public T setFrom(int from) { sourceBuilder().from(from); return (T) this; }
/** * Explicitly set the pre tags that will be used for highlighting. */ public T setHighlighterPreTags(String... preTags) { highlightBuilder().preTags(preTags); return (T) this; }
/** * The number of search hits to return. Defaults to <tt>10</tt>. */ public T setSize(int size) { sourceBuilder().size(size); return (T) this; }
/** * Sets a query to be used for highlighting all fields instead of the search query. */ public T setHighlighterQuery(QueryBuilder highlightQuery) { highlightBuilder().highlightQuery(highlightQuery); return (T) this; }
/** * Add a stored field to be loaded and returned with the inner hit. */ public T field(String name) { sourceBuilder().field(name); return (T) this; }