Hello everybody, I need your help.
I implemented fulltext search in my entitys using lucene.
Here is part of entity class.
Code:
@Indexed
@FullTextFilterDefs({
@FullTextFilterDef(name = "company", impl = CompanyFilter.class, cache = false),
@FullTextFilterDef(name = "roleFilter", impl = RoleFilter.class, cache = false)
})
@Entity
@Table(name="project")
public class EdsProject extends EdsObject implements Indexable {
public static final String PROJECT_STATUS = "_PROJECT_STATUS";
public static final String ONGOING="ONGOING";
public static final String NOT_STARTED="NOT_STARTED";
public static final String COMPLETED="COMPLETED";
@Field(index = Index.UN_TOKENIZED)
@DocumentId
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Integer objectID;
public Integer getObjectID() {
return objectID;
}
public void setObjectID(Integer objectID) {
this.objectID = objectID;
}
Here - code, which returns the search query result
FullTextQuery query = getFullTextQuery(fields, keyword);
Also, I have Integer[] of id's, and I should show to user not the whole query.getResultList() but only that results, which id's is in array.
I.E. - if query.getResultList() returns EdsProjects with id's 1, 5, 7 and 10
but in array I have only 5 and 7, I must not show 10 and 1 to user.
I suggested do this using filter
(RoleFilter) - and here is it
public class RoleFilter extends Filter{
Integer[] ids;
public Integer[] getIds() {
return ids;
}
public void setIds(Integer[] ids) {
this.ids = ids;
}
@Override
public BitSet bits(IndexReader reader) throws IOException {
BitSet bitSet = new BitSet(reader.maxDoc());
for (Integer id : ids) {
TermDocs termDocs = reader.termDocs(new Term("id", id.toString()));
while (termDocs.next()) {
bitSet.set(termDocs.doc());
}
}
return bitSet;
}
}
But it doesn't works.
After applyin' this filter - via
(projectIds - Integer[], contains allowed id's)
query.enableFullTextFilter("roleFilter").setParameter("ids", projectIds);
there are no elements in query at all (
I successfully implemented filters by another fields, but by this field (id) - I cannot ((