0
我有簿條目:Hibernate Search的布爾過濾
@Entity
@Indexed
public class Book extends BaseEntity {
@Field
private String subtitle;
@DateBridge(resolution = Resolution.DAY)
private Date publicationDate;
@Field
private int score;
@IndexedEmbedded
@ManyToMany(fetch = FetchType.EAGER)
@Cascade(value = {CascadeType.ALL})
private List<Author> authors = new ArrayList<Author>();
@Field
@FieldBridge(impl = BooleanBridge.class)
private boolean prohibited;
和過濾布爾場 「phohibited」
public class BFilter extends Filter {
@Override
public DocIdSet getDocIdSet(IndexReader indexReader) throws IOException {
OpenBitSet bitSet = new OpenBitSet(indexReader.maxDoc());
TermDocs termDocs = indexReader.termDocs(new Term("prohibited","false"));
while (termDocs.next()) {
bitSet.set(termDocs.doc());
}
return bitSet;
}
}
搜索方法
public List<T> findByQuery(Class c, String q) throws InterruptedException {
FullTextSession fullTextSession = Search.getFullTextSession(session);
fullTextSession.createIndexer().startAndWait();
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(c).get();
Query luceneQuery = qb
.keyword()
.fuzzy()
.onFields("title", "subtitle", "authors.name", "prohibited", "score")
.matching(q)
.createQuery();
FullTextQuery createFullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Book.class, BaseEntity.class);
createFullTextQuery.setFilter(new BFilter());
return createFullTextQuery.list();
}
,如果我申請的是過濾器 - 搜索結果是空的。數據庫中的條目100%在那裏。我究竟做錯了什麼?如果將過濾器字段替換爲「分數」,表示所有工作,並且結果不爲空。不要搜索它在一個布爾字段