3

I'm using hibernate search 3.4, and I'm running in to a small problem. I have a filter I'm attempting to use (CourseStatusFilterFactory), but every time I enable it, no results are returned. I have another filter that works without issues (DeletedFilterFactory), so I'm not sure what the problem is.

Here is the object I am trying to search:

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Indexed
@FullTextFilterDefs({
    @FullTextFilterDef(name = "statusFilter", impl = CourseStatusFilterFactory.class, cache = FilterCacheModeType.NONE),
    @FullTextFilterDef(name = "deletedCourse", impl = DeletedFilterFactory.class, cache = FilterCacheModeType.NONE)})
public class Course extends LightEntity implements Serializable {

    private static final long serialVersionUID = 21L;
    @Id
    @DocumentId
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Field(name = "title", index = Index.TOKENIZED, store = Store.YES)
    private String title;
    @Field(name = "coursestatus", index = Index.TOKENIZED, store = Store.YES)
    @Enumerated(EnumType.STRING)
    private CourseStatus status;}

Any my FilterFactory:

public class CourseStatusFilterFactory {

private CourseStatus status;

public void setStatus(CourseStatus status) {
    this.status = status;
}

@Key
public FilterKey getKey() {
    StandardFilterKey key = new StandardFilterKey();
    key.addParameter(status);
    return key;
}

@Factory
public Filter getFilter() {
    String statusString = new EnumBridge().objectToString(this.status);
    Query query = new TermQuery(new Term("coursestatus", statusString));
    CachingWrapperFilter cachingWrapperFilter = new CachingWrapperFilter(new QueryWrapperFilter(query));
     return cachingWrapperFilter;
}}

and to enable my filter:

persistenceQuery.enableFullTextFilter("statusFilter").setParameter("status", CourseStatus.PUBLISHED);

When debugging the code, I can see that my query in the filter does get set to "coursestatus:PUBLISHED", but I still have 0 results, even though there should be dozens.

Any ideas of where to start?

1 Answer 1

3

Thanks to the help of some people in the hibernate forum I was able to fix the problem.

I needed to change

@Field(name = "coursestatus", index = Index.TOKENIZED, store = Store.YES)

to

@Field(name = "coursestatus", index = Index.UN_TOKENIZED, store = Store.YES)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.