Reputation: 13
I have a class Item. Item has 'status' property. The status can be 'A' - active and 'I' - inactive. Time to time the status changes. Item has some other properties e.g. 'name' etc. that can be indexed. Users of the application can search items by name etc. After that they are shown with a list of relevant items. Inactive items should not be shown.
To filter out inactive items I declared a filter:
@FullTextFilterDef(name = "statusFilter", impl = StatusFilterFactory.class)
public class Item
{ ... }
public class StatusFilterFactory {
@Factory
public Filter getFilter() {
BooleanQuery query = new BooleanQuery();
Term statusTerm = new Term("status", "A");
query.add(new TermQuery(statusTerm), BooleanClause.Occur.MUST);
return new CachingWrapperFilter(new QueryWrapperFilter(query));
}
}
And when I need to create a list of items I use enableFullTextFilter("statusFilter") method:
fullTextQuery.setSort(sort).setFirstResult(offset).setMaxResults(limit).enableFullTextFilter("statusFilter");
but if I don't use this method, I have the same result. The inactive items are filtered out.
The questions are:
Thanks in advance.
Upvotes: 1
Views: 2576
Reputation: 6107
If you don't want to use @FullTextFilterDef you can use
org.hibernate.search.FullTextQuery.setFilter(Filter)
But the declarative definition is recommended, as the above method is semi-deprecated and being considered to be removed. (Actually please let us know if you really need it to stay).
No, a Filter instance has no effect on index updates. Something else is affecting your test, for example don't forget that index updated are performed at commit time, not before.
You might also want to consider using an indexing interceptor. The effect compared to a Filter is similar:
Upvotes: 1