英文:
Sort by enum field with hibernate search
问题
我在实体中有一个枚举字段
@Field(store = Store.NO, index = Index.YES, analyze = Analyze.NO)
@Enumerated(EnumType.STRING)
@FieldBridge(impl = EnumBridge.class)
@SortableField
private Status status;
我想通过这个字段对实体进行排序。因此我在 Hibernate Search 中创建了一个 Sort:
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: 处理对 /api/search/ 的请求时出现异常:org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: 对字段 'status' 的 docvalues 类型为 NONE(期望为 SORTED)。使用 UninvertingReader 或带有 docvalues 的索引
Caused by: java.lang.IllegalStateException: 对字段 'status' 的 docvalues 类型为 NONE(期望为 SORTED)。使用 UninvertingReader 或带有 docvalues 的索引。
如何在 Hibernate Search 中按枚举字段进行排序?
英文:
I have a ENUM field in my entity
@Field(store=Store.NO,index=Index.YES,analyze=Analyze.NO)
@Enumerated(EnumType.STRING)
@FieldBridge(impl = EnumBridge.class)
@SortableField
private Status status;
and i want to sort entities by this field. So i've create a Sort in Hibernate search:
Sort sort = qb
.sort()
.byDistance()
.onField("location.location")
.fromLatitude(sfq.getTheCenterLatitude())
.andLongitude(sfq.getTheCenterLongitude())
.andByField("status")
.createSort();
(i also sort by distance, but it doesn't matter)
BUT, when i try to search i see this error
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.
How to sort by enum field in hibernate search?
答案1
得分: 0
你可能在添加了 @SortableField
后忘记重新索引了?
英文:
You probably forgot to reindex after you added @SortableField
?
答案2
得分: 0
通过在property.xml中设置<property name="hibernate.search.default.locking_strategy" value="none"/>
解决。我不知道为什么,但对我有效。
英文:
Solved by setting <property name="hibernate.search.default.locking_strategy" value="none"/>
in property.xml. I don't know how, but it works for me.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论