繁体   English   中英

Hibernate搜索完全匹配带破折号的字符串

[英]Hibernate search exact match for strings with dashes

我想对具有“ xx-xx-xx”格式的实体字段进行精确搜索。

该实体如下所示:

@Entity
@Indexed
class Resource {

    @Field
    private String address; // has "xx-xx-xx" format
}

查询创建过程如下: queryBuilder.keyword().onFields("resource").matching(searchQuery).createQuery()

假设我有两个具有以下地址的资源:

aa-bb-cc
cc-dd-ee

当我运行搜索查询"aa-bb-cc"我希望只会返回第一个资源,但是我却让搜索返回了这两个资源。

我应该更改做什么并按资源字段精确搜索?

您需要为此字段禁用默认分析器,以便将其视为“完全”关键字:

@Entity
@Indexed
class Resource {

    @Field(analyze=Analyze.NO)
    private String address; // has "xx-xx-xx" format
}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM