-->
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.  [ 7 posts ] 
Author Message
 Post subject: Faceted Search on numeric fields?
PostPosted: Tue May 10, 2011 5:57 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
Hi all,

I use HibernateSearch 3.4.0.Final and implemented some faceted search which works fine on string fields or date fields. But when I try to request the facets on numeric fields I always get one facet with value like this "|"...

So my question: it's possible to use facet search on numeric fields? If yes, how?

I don't want to use a range request, I want to get all possible numeric values instead.

My facet request looks like:

Code:
FacetingRequest facetingRequest = queryBuilder.facet().name("facet").onField("myNumericProperty")
         .discrete().orderedBy(FacetSortOrder.COUNT_DESC).includeZeroCounts(false).createFacetingRequest();


Regards, jacquipre.


Top
 Profile  
 
 Post subject: Re: Faceted Search on numeric fields?
PostPosted: Wed May 11, 2011 5:29 am 
Hibernate Team
Hibernate Team

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

have you added @NumericField to the numeric field as well? If so it should work.
Maybe post the annotated entity as well.

--Hardy


Top
 Profile  
 
 Post subject: Re: Faceted Search on numeric fields?
PostPosted: Wed May 11, 2011 9:09 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
No, I use a FieldBrigde for this case which writes a NumericField to the index.

My entity looks like:

Code:
public class MyEntity {
...
    @Field
    @FieldBridge(impl=PropertiesBridge.class)
    protected List<Property> properties;
...
}


The field bridge converts the properties to fields like this:

Code:
public class PropertiesBridge implements FieldBridge {
   public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
      if (value != null && value instanceof List<?>) {
          List<Property> properties = (List<Property>) value;
          for (Property property: properties) {
               if (property.getType() == PropertyType.Double) {
                  NumericField field = new NumericField(property.getName(), Store.YES, true);
                  field.setDoubleValue((Double)property.getValue());
                  document.add(field);
          }
      }
    }
}


Isn't that the same like a @NumericField?


Top
 Profile  
 
 Post subject: Re: Faceted Search on numeric fields?
PostPosted: Thu May 12, 2011 9:09 am 
Hibernate Team
Hibernate Team

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

thanks for your feedback. The faceting API is still in the beginnings and we still need to improve on it.
At the moment there are still several limitations to its usage. First of all you can only facet on a field if there is one single field value per field name. You cannot facet, if you write multiple fields with the same name. Not sure how this works out in regards w/ your new NumericField(property.getName(), Store.YES, true);. The second limitation is that if you are using discrete faceting, you cannot use a numeric field. If you need the numeric field for something else you can write a second string based (just a normal Field instance) field and facet on this.

I hope this helps.

--Hardy


Top
 Profile  
 
 Post subject: Re: Faceted Search on numeric fields?
PostPosted: Fri May 13, 2011 2:58 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
Thanks for the information!

I solved it like you suggested it by writing a second field like this:

Code:
if (property.getType() == PropertyType.Double) {
                  NumericField field = new NumericField(property.getName(), Store.YES, true);
                  field.setDoubleValue((Double)property.getValue());
                  document.add(field);

                  Field fieldForFacet = new Field(property.getName() + ".facet", Double.toString((Double)property.getValue()), Store.YES, Index.NOT_ANALYZED);
        document.add(fieldForFacet);
          }


The facet search now uses the "<fieldName>.facet" field now which works well.

-- jacquipre


Top
 Profile  
 
 Post subject: Re: Faceted Search on numeric fields?
PostPosted: Fri May 13, 2011 3:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Awesome. I think this is a good enough work around for now. We will be improving the faceting API over the coming releases. So stay tuned.

--Hardy


Top
 Profile  
 
 Post subject: Re: Faceted Search on numeric fields?
PostPosted: Fri May 13, 2011 8:25 am 
Beginner
Beginner

Joined: Mon Apr 11, 2011 7:56 am
Posts: 38
Hardy: Can you put this information (just like the restriction of single valued fields) as a note ("current limitations"?) in the documentation? I was currently facing this same problem.

Have a nice weekend.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.