-->
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.  [ 3 posts ] 
Author Message
 Post subject: Lucene Sorting NOT Ignoring NULL values
PostPosted: Tue Oct 14, 2008 4:49 am 
Newbie

Joined: Fri Sep 26, 2008 1:44 am
Posts: 5
Hibernate search version : hibernate-search-3.1.0.Beta1
Lucene: lucene-core-2.3.2.jar

Hi,

I am a newbie.

I just configured lucene using hibernate search. But I find that the sorting does NOT ignore null values.

I am searching using one field, say X and want to sort the results using another, say Y (Which can have null values). But I am expecting Sort to ignore all the null values and just sort only records that has values in Y field.

How can I achieve this. Is there anywhere I can set the flag in SortField that specifies it to ignore all the null values ?

Please help.

Code:
   FullTextSession fullTextSession = Search.getFullTextSession(session);
   QueryParser parser = new MultiFieldQueryParser(new String[]{"keywords", "title"}, new StandardAnalyzer());
   Query query = parser.parse(keywordText);
   FullTextQuery hibernateQueryObj = fullTextSession.createFullTextQuery(query, SearchObject.class);
   
   Sort sortCriteria = new Sort(new SortField("lastUpdatedDate",
         SortField.STRING,
         true));
   hibernateQueryObj.setSort(sortCriteria);
   hibernateQueryObj.setFirstResult(0);


In the above code "lastUpdatedDate" can be null value. But I don't want null to be considered by my Sort .

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2008 3:45 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

What do you mean with "I don't want null to be considered by my Sort "? If records with null values for this field are in the result set the sort will have to take care of this, meaning you can sort them to the beginning or end of the result list. Sorting does not remove any result from the result list.

If you want to ignore the null values you could for example write a query which combines title and lastUpdateDate. In case you want to explicitly search for values which are null you will have to implement a custom bridge though, since per default null values are not indexed at all. However, with a custom bridge you can insert a chosen 'null' token. See also http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-115.

Hope this helps,
Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2008 6:55 pm 
Newbie

Joined: Fri Sep 26, 2008 1:44 am
Posts: 5
Hardy, Thanks for your reply.

I resolved this by using my custom filter that ignores all the fields that has "null" in them

Code:
public class NotNullRangeFilter extends org.apache.lucene.search.Filter {
    private RangeFilter rangeFilter;
    public BitSet bits(IndexReader reader) throws IOException {
        rangeFilter = RangeFilter.More("lastUpdatedDate"/*Field to sort*/,
"" /*atleast an empty string but not null*/);
        return rangeFilter.bits(reader);
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.