Hibernate 搜索过滤器不适用于标记化字段
我正在使用 Hibernate search 3.3 来搜索 Lucene 索引。我有一个需要在某个字段上使用的过滤器,但也将其标记为全文搜索。我发现,当我将字段设置为 UN_TOKENIZED 时,过滤器起作用,而全文搜索不起作用;当我将其设置为 TOKENIZED 时,全文搜索起作用,而过滤器不起作用。
POJO
@Field(name = "owningOrganization", index = Index.UN_TOKENIZED, store = Store.YES)
@FieldBridge(impl = OrganizationNameFieldBridge.class)
public Organization getOwningOrganization()
{
过滤器
@Factory
public Filter getFilter()
{
BooleanQuery query = new BooleanQuery();
Term orgTerm = new Term("owningOrganization", userOrganization);
Term activeTerm = new Term("currentStateIsActive", "1");
query.add(new TermQuery(orgTerm), Occur.SHOULD);
query.add(new TermQuery(activeTerm), Occur.SHOULD);
return new CachingWrapperFilter(new QueryWrapperFilter(query));
}
当我输入 owningOrganization:"这是组织的确切值"
的搜索词时,我没有得到任何结果,但过滤器按预期工作。当我将其切换为代币化时,情况正好相反。
有什么建议吗?
I am using Hibernate search 3.3 to search a Lucene index. I have a filter I need to use on a certain field, but also make it TOKENIZED for full text search. What I have found is that when I have the field set to UN_TOKENIZED, the filter works and full text search doesn't, and when I have it set to TOKENIZED, full text search works and the filter doesn't.
POJO
@Field(name = "owningOrganization", index = Index.UN_TOKENIZED, store = Store.YES)
@FieldBridge(impl = OrganizationNameFieldBridge.class)
public Organization getOwningOrganization()
{
Filter
@Factory
public Filter getFilter()
{
BooleanQuery query = new BooleanQuery();
Term orgTerm = new Term("owningOrganization", userOrganization);
Term activeTerm = new Term("currentStateIsActive", "1");
query.add(new TermQuery(orgTerm), Occur.SHOULD);
query.add(new TermQuery(activeTerm), Occur.SHOULD);
return new CachingWrapperFilter(new QueryWrapperFilter(query));
}
When I enter search terms of owningOrganization:"This is the exact value of an organization"
I get no results, but the filter works as desired. And opposite when I switch it to TOKENIZED.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该对该字段建立索引两次,一次用于搜索(分析),一次用于过滤。默认情况下,使用TermQuery不会应用任何分析。它在索引中搜索指定的术语。
通过这种方法,您可以拥有可用标记化和非标记化的所属组织字段。您只需使用正确的字段名称即可。
You should index the field twice, once for searching (analyzed) and once for filtering. Per default using a TermQuery does not apply any analyzing. It searches the index for the term as specified.
With this approach you have the owning organization field available tokenized and un-tokenized. You just have to use the right field name.