-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Adding Enum Search Filter returns 0 results
PostPosted: Wed Jun 15, 2011 3:02 pm 
Newbie

Joined: Wed Jun 15, 2011 2:53 pm
Posts: 2
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:

Code:
@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(index = Index.TOKENIZED)
    @FieldBridge(impl=EnumBridge.class)
    @Enumerated(EnumType.STRING)
    private CourseStatus status;}


The enum:

Code:
public enum CourseStatus {
    DRAFT, PUBLISHED, INACTIVE;
}


Any my FilterFactory:

Code:
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("status", statusString));
    CachingWrapperFilter cachingWrapperFilter = new CachingWrapperFilter(new QueryWrapperFilter(query));
     return cachingWrapperFilter;
}}


and to enable my filter:

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


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

Any ideas of where to start?


Top
 Profile  
 
 Post subject: Re: Adding Enum Search Filter returns 0 results
PostPosted: Thu Jun 16, 2011 3:16 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi kevmo,
I think that your filter is not matching any result, very likely the string you're getting as output of
Code:
String statusString = new EnumBridge().objectToString(this.status);

is not the same as is stored in the index.

I suspect that the actual text you have in the index is lowercased, because you're using @Field(index = Index.TOKENIZED) on the status, while you likely want @Field(index = Index.UN_TOKENIZED)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Adding Enum Search Filter returns 0 results
PostPosted: Thu Jun 16, 2011 5:47 pm 
Newbie

Joined: Wed Jun 15, 2011 2:53 pm
Posts: 2
You are a genius. That was my problem. Thank you so much!!


Top
 Profile  
 
 Post subject: Re: Adding Enum Search Filter returns 0 results
PostPosted: Fri Jun 17, 2011 4:07 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
just some experience with the most common problems ;)
Remember: the Analyzer always processes the indexed text unless you use un_tokenized, which indexes the literal string. The search engine then searches for an exact match between your queries and indexed terms, so you should always be carefull to have your searches analyzed the same way you're indexing. That's why the QueryParser takes an analyzer argument, and why we made the QueryBuilder to make sure people match it properly.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.