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"
我希望只返回第一个资源,但相反,我搜索 returns 两个资源。
我应该更改为做什么,并按资源字段进行精确搜索?
您需要禁用此字段的默认分析器,以便将其视为 "exact" 个关键字:
@Entity
@Indexed
class Resource {
@Field(analyze=Analyze.NO)
private String address; // has "xx-xx-xx" format
}
我想精确搜索 "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"
我希望只返回第一个资源,但相反,我搜索 returns 两个资源。
我应该更改为做什么,并按资源字段进行精确搜索?
您需要禁用此字段的默认分析器,以便将其视为 "exact" 个关键字:
@Entity
@Indexed
class Resource {
@Field(analyze=Analyze.NO)
private String address; // has "xx-xx-xx" format
}