spring Data JPA 集成solr7(八)

本文介绍了Solr中可用的功能表达式,包括货币、默认值、距离等内置函数,并展示了如何通过实时获取功能检索最新文档版本,无需重新打开搜索器。此外,还提到了使用@Score注解来加载查询结果的评分信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

4.14. Using Functions

Solr supports several functional expressions within queries. Followig functions are supported out of the box. Custom functions can be added by implementing Function

Table 3. Functions
ClassSolr Function

CurrencyFunction

currency(field_name,[CODE])

DefaultValueFunction

def(field|function,defaultValue)

DistanceFunction

dist(power, pointA, pointB)

DivideFunction

div(x,y)

ExistsFunction

exists(field|function)

GeoDistanceFunction

geodist(sfield, latitude, longitude)

GeoHashFunction

geohash(latitude, longitude)

IfFunction

if(value|field|function,trueValue,falseValue)

MaxFunction

max(field|function,value)

NotFunction

not(field|function)

ProductFunction

product(x,y,…​)

QueryFunction

query(x)

TermFrequencyFunction

termfreq(field,term)

SimpleQuery query = new SimpleQuery(new SimpleStringCriteria("text:ipod"));
query.addFilterQuery(new FilterQuery(Criteria.where(QueryFunction.query("name:sol*"))));

4.15. Realtime Get

The realtime get allows retrieval of the latest version of any document using the unique-key, without the need to reopen searchers.

realtime get relies on the update log feature.
Example 58. Realtime get
Optional<Product> product = solrTemplate.getById("collection-1", "123", Product.class);

Multiple documents can be retrieved by providing a collection of ids as follows:

Example 59. Realtime multi-get
Collection<String> ids = Arrays.asList("123", "134");
Collection<Product> products = solrTemplate.getByIds("collection-1", ids, Product.class);

4.16. Special Fields

4.16.1. @Score

In order to load score information of a query result, a field annotated with @Score annotation could be added, indicating the property holding the documents score.

The score property needs to be numerical and can only appear once per document.
public class MyEntity {

    @Id
    private String id;

    @Score
    private Float score;

    // setters and getters ...

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值