spring Data JPA 集成solr7(六)

7 篇文章 1 订阅

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 HighlightOptionswithout 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);

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值