spring Data JPA 集成solr7(八)

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
Class Solr 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 ...

}

猜你喜欢

转载自blog.csdn.net/qq_32778043/article/details/80825852
今日推荐