-->
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: Is there a default field for Hibernate Search index?
PostPosted: Wed May 23, 2007 5:28 pm 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
I used to use Compass to integrate Lucene and Hibernate. In compass you can specify whether a field is included in a default "all" field. For example, if I have a property named "title", I can index the the property into a "title" field as well as the default "all" field, unless I declare excluded-from-all="true". When I search for "+(some_title_word)", or " +title:some_title_word", the entity with "some_title_word" in the title will return. How do I achieve the same effect in Hibernate Search? Right now in my test, it seems that I have to use "title:" prefix to search for words in titles.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 9:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I never understood the need for a "all" field
you can achieve it by using MultiFieldQueryParser, plus MultiFieldQueryParser has the benefit of supporting per field boosting which I found very useful in most multi field usecases.

Here is an example (first part of it)

Code:
private static String[] productFields = {"title",
         "description", "actors.name", "categories.name"};

   private Query searchQuery(String searchQuery)
   {
      //lucene part
      Map<String,Float> boostPerField = new HashMap<String,Float>(4);
      boostPerField.put( "title", (float) 4);
      boostPerField.put( "description", (float) 2);
      boostPerField.put( "actors.name", (float) 2);
      boostPerField.put( "categories.name", (float) .5);

      QueryParser parser = new MultiFieldQueryParser(productFields, new StandardAnalyzer(), boostPerField);

      org.apache.lucene.search.Query luceneQuery;
      try
      {
         luceneQuery = parser.parse(searchQuery);
      }
      catch (ParseException e)
      {
         //do something here
         throw new RuntimeException("Unable to parse query: " + searchQuery, e);
      }

      //Hibernate Search
      FullTextSession ftSession =
            org.hibernate.search.Search.createFullTextSession(
                  (Session) em.getDelegate() );
      return ftSession.createFullTextQuery(luceneQuery, Product.class);

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 11:34 pm 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
Thanks for the example. I don't think the "all" field is obviously better. I just wonder whether there is a straight forward migration from Compass. Luckily MultiFieldQueryParser is easy to do.

I do have a further question. If you assign boost factors to the search terms, how are those related to the boost factors assigned to fields during indexing? Do you really just need to do one of the two?


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.