-->
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: Correct to use ignoreFieldBridge for "subentity.field" DSL?
PostPosted: Sun Feb 06, 2011 7:16 am 
Beginner
Beginner

Joined: Wed Sep 30, 2009 5:29 am
Posts: 29
Hibernate 3.6.0, HSearch 3.3.0. I wonder if anyone could clarify if I am right to solve my problem by using ignoreFieldBridge(), when I actually would benefit from the bridging of the fields in question (using my PadNumberBridge).

I have a CategoryEntity which has indexed 'left' and 'right' properties. Other entities hold attributes of type CategoryEntity and index their fields using @IndexedEmbedded, so I have:

Code:
@Entity
class CategoryEntity {
   @Column(name="lft")
   @Field(name="left", index=Index.UN_TOKENIZED, store=Store.YES)
   @FieldBridge(impl=PadNumberBridge.class,
         params = { @Parameter(name="pad", value="4") }
   )
   private int left;
   ... same for 'right' ...
}

@Entity
class ItemEntity {
   @IndexedEmbedded(depth=1)
   private CategoryEntity category;
}


This results in each Lucene document for ItemEntity being represented with a "category.left" and "category.right" field. Luke shows an ItemEntity being indexed with, for example,

Quote:
category.left = 0004
category.right = 0012


Until now I've used Hibernate Search query building, with a @FilterDef on the CategoryEntity class allowing me to enable the filter on the FullTextSession and specify the left and right values easily as 'int' parameters. The conversion from 4 to "0004" was done for me.

Now, I'm trying to change my code to use Hibernate Search query DSL and a QueryBuilder to build the same basic query. I find that I have trouble specifying a search for ItemEntity's with specific category.left and category.right values. If I use some naive code like:

Code:
qb.range().onField("category.left").above(searchCat.getLeft()).createQuery())


I get an exception saying it doesn't know what FieldBridge to use for "category.left". I cannot see how to specify a search on a sub-entity's field.

I ran into ignoreFieldBridge(), and tried it thus:

Code:
qb.range().onField("category.left").ignoreFieldBridge().above(searchCat.getLeft()).createQuery())


This does generate a Lucene query, but does not pad the 'left' integer, so I get e.g. "category.left:[4 TO *]" and the search returns no results.

If I pad the number manually and pass the resulting string "0004" to the above() clause of the QueryBuilder, to make "category.left:[0004 TO *]", then the search executes correctly and returns results, however it feels wrong to do this.

So, is there a better way to specify a search on "category.left" of my ItemEntity's? I feel the documentation (5.1.2. Building a Lucene query with the Hibernate Search query DSL) is lacking guidance in this area.

Thanks!
Nick


Top
 Profile  
 
 Post subject: Re: Correct to use ignoreFieldBridge for "subentity.field" DSL?
PostPosted: Sun Feb 06, 2011 8:03 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Nick,
thanks for spotting this, I think it would be nice to have the DSL to provide exactly what you was expecting, but I don't think the fieldBridge on indexedEmbedded is being taken in consideration in the current implementation.

Please open a JIRA about it; you're also welcome to provide a testcase and a prototype of a solution; It shouldn't be hard, we have the list of bridges per attribute of each entity, just the linked entities are not being searched for in this case.

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


Top
 Profile  
 
 Post subject: Re: Correct to use ignoreFieldBridge for "subentity.field" DSL?
PostPosted: Wed Feb 09, 2011 7:39 am 
Beginner
Beginner

Joined: Wed Sep 30, 2009 5:29 am
Posts: 29
Thanks. I've opened http://opensource.atlassian.com/project ... SEARCH-682. I'm extremely busy with work and a newborn baby.

I failed to create a simple test case for a recent JIRA (http://opensource.atlassian.com/project ... SEARCH-678) , I doubt very much I will be able to create one and propose a solution for this issue. I would have to study how to do it and I don't think I have the required time or energy. If you point at a template unit test .java that should work, I'll probably be able to knock up a unit test?


Top
 Profile  
 
 Post subject: Re: Correct to use ignoreFieldBridge for "subentity.field" DSL?
PostPosted: Wed Feb 09, 2011 9:24 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, thanks for the JIRA and congratulations for the baby.

In case you have some time, this should facilitate things: ContributingtoHibernateSearch, ignore the last part about releasing it, jump straight to cloning the GIT repository and coding conventions.

Writing a testcase is very simple as long as you extend our SearchTestCase, this setups the basic things you need and has some methods you can override to customize configuration - especially which annotated entities are relevant for you test. Add one (or more) entities to use it;

org.hibernate.search.test.RamDirectoryTest is a good example to take as a base to write a new test.

sometimes you can find an existing test which is very close to what you need, you're free to add a new method to an existing test and reuse some model for your purpose.

_________________
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.