-->
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: Hibernate Search: Sorting case insensitive wildcard queries
PostPosted: Fri Feb 19, 2010 7:04 am 
Newbie

Joined: Mon Aug 31, 2009 6:46 am
Posts: 11
Hi,

I have an AnalyzerDefinition:

@AnalyzerDef(name = "CustomAnalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = { @TokenFilterDef(factory = LowerCaseFilterFactory.class) }
)

This works well, as I can do case insensitive searches, however, I sort my results, but lowercase names remain at the end of the list of results. For example:

Name
Mobile phone
Monitor
Searching
Testing
mobile defib

I would like to sort case insensitively, so mobile defib would appear between Name & Mobile phone.

note, I am using wildcard queries for the search.

Is this possible?

Thanks in advance,

Kevin.


Top
 Profile  
 
 Post subject: Re: Hibernate Search: Sorting case insensitive wildcard queries
PostPosted: Fri Feb 19, 2010 9:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
It should work. Can you post your annotated entities and your search/sort code?


Top
 Profile  
 
 Post subject: Re: Hibernate Search: Sorting case insensitive wildcard queries
PostPosted: Fri Feb 19, 2010 11:04 am 
Newbie

Joined: Mon Aug 31, 2009 6:46 am
Posts: 11
Hi,

I was reading that when you use a wildcard query, then the filters in a Analyzer are not used, so I suspected this was the case.

I managed to get the sorting working using a custom SortComparator by extending the SortComparator, however I am now receiving a null pointer exception, because not all of the fields have values.

Here was my existing code before I implemented the SortComparator:

Code:
Entity
@Indexed
@Table(name = "ASSET")
@AnalyzerDef(name = "TycoAnalyzer",
             tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
             filters = { @TokenFilterDef(factory = LowerCaseFilterFactory.class) }
            )
public class Asset extends ViewableEntity implements Comparable<Asset>
{

   /** Serial version UID. */
   private static final long serialVersionUID = 3889097101406806622L;
   
   /** List of asset attributes. */
   @IndexedEmbedded
   @OneToMany(mappedBy = "asset", cascade = CascadeType.REMOVE)
   @Fetch(FetchMode.JOIN)
   private List<Attribute> attributes = new ArrayList<Attribute>();
   
   /** The type of asset this is. */
   @IndexedEmbedded
   @ManyToOne
   private AssetType assetType;
   
   /** Current GPS position. */
   @Column(name = "gps", length = Constants.VARCHAR_128)
   private String gps;
   
   /** <code>Date</code> the <code>Asset</code> was installed in the building. */
   @Column(name = "installation_date")
   private Date installationDate;
   
   /** The current location in the building. */
   @Column(name = "location", length = Constants.VARCHAR_128, nullable=false)
   @Fields({
       @Field(index = Index.TOKENIZED, store = Store.YES),
       @Field(name = "location_forSort", index = Index.UN_TOKENIZED, store = Store.NO)
   })
   private String location = "";
... Rest of class ommitted.



Search Code

Code:
FullTextQuery results = getDaoFacade().getAssetDao().searchForAssetsInIndex(query,
                                                                                    fullTextSession,
                                                                                    analyzer,
                                                                                    searchResult.getStart(),
                                                                                    searchResult.getNoOfResultsToReturn());




Code:
@Override
    public FullTextQuery searchForAssetsInIndex(Query query, FullTextSession fullTextSession, Analyzer analyzer, int beginResult, int noOfRows)
    {
        //We need to use projection as we want to highlight terms in the results.
        FullTextQuery squery = fullTextSession.createFullTextQuery(query, Asset.class);
        squery.setProjection(FullTextQuery.THIS, FullTextQuery.DOCUMENT_ID, FullTextQuery.DOCUMENT, FullTextQuery.SCORE);
        squery.setFirstResult(beginResult); //Where should we start the results from?
        squery.setMaxResults(noOfRows); //How many results should we return?
        return squery;
    }




Sort Code
Code:
results.setSort(new Sort(new SortField(searchResult.getSortingColumnName() + "_forSort", searchResult.isReverseOrder())));


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.