首页 > 解决方案 > 使用休眠搜索按枚举字段排序

问题描述

我的实体中有一个 ENUM 字段

@Field(store=Store.NO,index=Index.YES,analyze=Analyze.NO)
@Enumerated(EnumType.STRING)
@FieldBridge(impl = EnumBridge.class)
@SortableField
private Status status;

我想按此字段对实体进行排序。所以我在 Hibernate 搜索中创建了一个排序:

Sort sort = qb
        .sort()
        .byDistance()
        .onField("location.location")
        .fromLatitude(sfq.getTheCenterLatitude())
        .andLongitude(sfq.getTheCenterLongitude())
        .andByField("status")
        .createSort();

(我也按距离排序,但这没关系)

但是,当我尝试搜索时,我看到了这个错误

ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /api/search/: org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: unexpected docvalues type NONE for field 'status' (expected=SORTED). Use UninvertingReader or index with docvalues
Caused by: java.lang.IllegalStateException: unexpected docvalues type NONE for field 'status' (expected=SORTED). Use UninvertingReader or index with docvalues.

如何在休眠搜索中按枚举字段排序?

标签: javahibernatesortinglucenehibernate-search

解决方案


<property name="hibernate.search.default.locking_strategy" value="none"/>通过property.xml中的设置解决。我不知道如何,但它对我有用。


推荐阅读