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_T开发者_C百科OKENIZED, 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?
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.
@Fields({
@Field(name = "owningOrganization_untokenized", index = Index.UN_TOKENIZED),
@Field(name = "owningOrganization", index = Index.TOKENIZED, store = Store.YES
}
)
public Organization getOwningOrganization(){
}
With this approach you have the owning organization field available tokenized and un-tokenized. You just have to use the right field name.
精彩评论