简体   繁体   English

Hibernate 搜索六:可聚合字段不区分大小写搜索,同时保留区分大小写的聚合结果

[英]Hibernate Search 6: Case-insensitive searching of aggregable fields while retaining case-sensitive aggregation results

I have used the new aggregation functionality of Hibernate Search 6 to develop a classic "faceted search" interface, in which the various search fields in the UI are accompanied by the most popular choices taken from the aggregation data of the SearchResult .我使用 Hibernate Search 6 的新聚合功能开发了一个经典的“分面搜索”界面,其中 UI 中的各种搜索字段伴随着从SearchResult的聚合数据中提取的最流行的选择。 This works beautifully.这很好用。

However, I would like to allow the users to be able to search these fields case-insensitively, so that they are not limited to choosing from the aggregation results and are not penalised for typing in the wrong case.但是,我希望允许用户能够不区分大小写地搜索这些字段,这样他们就不会局限于从聚合结果中进行选择,也不会因输入错误的大小写而受到惩罚。

I have applied a lowercase normalizer to the aggregable field definition, which allows me to search case-insensitively, but if I do this all of the aggregation data retrieved from the SearchResult , and presented to the user, is also in lowercase.我已将小写规范器应用于可聚合字段定义,这允许我不区分大小写地搜索,但如果我这样做,则从SearchResult检索并呈现给用户的所有聚合数据也是小写的。

Is there a way to allow case-insensitive searches while retaining the original case in the aggregation results?有没有办法允许不区分大小写的搜索,同时在聚合结果中保留原始大小写?

I have attempted to use projectable( Projectable.YES ) in my field definition, in the hope that this would return the original case, but it had no effect.我试图在我的字段定义中使用projectable( Projectable.YES ) ,希望这会返回原始案例,但它没有效果。

My current field template definition is:我当前的字段模板定义是:

indexSchemaObjectField.fieldTemplate( "template", f -> f.asString()
    .aggregable( Aggregable.YES )
    .projectable( Projectable.YES )
    .normalizer( "lowercase")
).multiValued();

and my lowercase normalizer is defined as:我的小写规范器定义为:

luceneAnalysisConfigurationContext.normalizer( "lowercase" )
    .custom()
    .tokenFilter( "lowercase" );

I'm using the Lucene backend.我正在使用 Lucene 后端。

Ideally you'd use multi-fields, but that's not available at the moment ( https://hibernate.atlassian.net/browse/HSEARCH-3465 ).理想情况下,您会使用多字段,但目前不可用( https://hibernate.atlassian.net/browse/HSEARCH-3465 )。

In the meantime, I would rely on two separate fields:同时,我将依赖两个独立的字段:

// Declare one field for aggregations
// (do this first, so that the glob is matched first)
indexSchemaObjectField.fieldTemplate( "template", f -> f.asString()
    .aggregable( Aggregable.YES )
)
.matchingPathGlob("*_agg")
.multiValued();

// Declare one field for search
indexSchemaObjectField.fieldTemplate( "template", f -> f.asString()
    .normalizer( "lowercase")
).multiValued();

Then in your bridge, you would duplicate the value: first populate the field "<fieldname>" , then the field "<fieldname>_agg" with the same value.然后在您的网桥中,您将复制该值:首先填充字段"<fieldname>" ,然后使用相同的值填充字段"<fieldname>_agg"

Finally, when searching, you would use "<fieldname>" for predicates, but "<fieldname>_agg" for aggregations.最后,在搜索时,您将使用"<fieldname>"作为谓词,而使用"<fieldname>_agg"作为聚合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 休眠搜索不区分大小写的搜索不适用于LowerCaseFilterFactory - hibernate search case insensitive search is not corretly work with LowerCaseFilterFactory Hibernate-Search - 使用 lucene 查询解析器语法的不区分大小写的通配符搜索(不使用 QueryBuilder!) - Hibernate-Search - Case insensitive wildcard search using lucene query parser syntax (not using QueryBuilder!) 如何使用 Hibernate Lucene Search 对挪威字符(Æ、Ø 和 Å)进行不区分大小写的排序? - How to do case insensitive sorting of Norwegian characters (Æ, Ø, and Å) using Hibernate Lucene Search? 什么分析仪适合我的情况? hibernate 搜索案例 - what analzyer is good for my situation? hibernate search case Lucene阶段查询不区分大小写 - Lucene phase query case insensitive 休眠搜索Lucene变音不敏感搜索 - Hibernate search Lucene accent insensitive search 休眠多字段搜索 - Hibernate search on multi fields Hibernate 搜索:使用 Ngram 过滤器索引数据,并且在搜索时由于查询时的标记化而给出不正确的结果 - Hibernate search: Indexed data with Ngram filter and while searching it gives incorrect result due to tokenizing while querying 休眠搜索结果排序 - Hibernate Search Results Ordering 在休眠搜索中搜索首选项 - Searching for a preference in Hibernate Search
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM