簡體   English   中英

使用 hibernate 搜索按枚舉字段排序

[英]Sort by enum field with hibernate search

我的實體中有一個 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.

如何在 hibernate 搜索中按枚舉字段排序?

您可能在添加@SortableField后忘記重新索引?

通過在 property.xml 中設置<property name="hibernate.search.default.locking_strategy" value="none"/>解決。 我不知道如何,但它對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM