4.10. Select Request Handler
Select the request handler via qt
Parameter directly in Query
or add @Query
to your method signature.
@Query(requestHandler = "/instock")
Page<Product> findByNameOrDescription(String name, String description);
4.11. Using Join
Join attributes within one solr core by defining Join
attribute of Query
. NOTE: Join is not available prior to solr 4.x.
SimpleQuery query = new SimpleQuery(new SimpleStringCriteria("text:ipod"));
query.setJoin(Join.from("manu_id_s").to("id"));
4.12. Highlighting
To highlight matches in search result add HighlightOptions
to the SimpleHighlightQuery
. Providing HighlightOptions
without any further attributes will highlight apply highlighting on all fields within a SolrDocument
. NOTE: Field specific highlight parameters can be set by adding FieldWithHighlightParameters
to HighlightOptions
.
SimpleHighlightQuery query = new SimpleHighlightQuery(new SimpleStringCriteria("name:with"));
query.setHighlightOptions(new HighlightOptions());
HighlightPage<Product> page = solrTemplate.queryForHighlightPage("collection-1", query, Product.class);
Not all parameters are available via setters/getters but can be added directly.
SimpleHighlightQuery query = new SimpleHighlightQuery(new SimpleStringCriteria("name:with"));
query.setHighlightOptions(new HighlightOptions().addHighlightParameter("hl.bs.country", "at"));
In order to apply Highlighting to derived queries use @Highlight
. If no fields
are defined highlighting will be aplied on all fields.
@Highlight(prefix = "<b>", postfix = "</b>")
HighlightPage<Product> findByName(String name, Pageable page);
4.13. Spellchecking
Spellchecking offers search term suggestions based on the actual query. Please see the Solr Reference for more details.
4.13.1. Spellecheck Options
Spellcheck query parameters are added to request when SpellcheckOptions
are set.
SimpleQuery q = new SimpleQuery("name:gren");
q.setSpellcheckOptions(SpellcheckOptions.spellcheck()
.dictionaries("dict1", "dict2")
.count(5)
.extendedResults());
q.setRequestHandler("/spell");
SpellcheckedPage<Product> found = template.query(q, Product.class);
Enable spellcheck by setting SpellcheckOptions . Sets spellcheck=on request parameter. | |
Set up the dictionaries to use for lookup. | |
Set the max number of suggestions to return. | |
Enable extended results including term frequency etc. | |
Set the request handler capable of processing suggestions. | |
Execute the query. |
4.13.2. @Spellcheck
The @Spellcheck
annotations allows usage of the spellcheck feature on Repository
level.
public interface ProductRepository extends Repository<Product, String> {
@Query(requestHandler = "/spell")
@Spellcheck(dictionaries = { "dict1", "dic2" }, count=5, extendedResults = true)
SpellcheckedPage<Product> findByName(String name, Pageable page);
}