-->
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: Checking for existence of fields Querybuilder
PostPosted: Mon Jan 09, 2012 8:53 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

In my entities sometimes an indexed (keyword) property will be null and therefore not exist in the index.

According to some Lucene forums, the way to test for this in Lucene is +fieldname:[* TO *]

However, when I do
Code:
QueryBuilder qb = fts.getSearchFactory().buildQueryBuilder()
      .forEntity(MyEntity.class).get();

Query q = qb.range().onField("target.id").from("*").to("*").createQuery();



I don't get any results. Just wondering what the prescribed way for doing this is? I could add an indexed boolean that checks for the existence of the field, but I imagine, there must be a better way.

Marc


Top
 Profile  
 
 Post subject: Re: Checking for existence of fields Querybuilder
PostPosted: Wed Jan 11, 2012 6:38 am 
Hibernate Team
Hibernate Team

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

I think the problem is that the Lucene example +fieldname:[* TO *] assumes a QueryParser and uses the Lucene query syntax.

Using qb.range().onField("target.id").from("*").to("*").createQuery(); uses a TermRangeQuery under the hood.

Does that help?

--Hardy


Top
 Profile  
 
 Post subject: Re: Checking for existence of fields Querybuilder
PostPosted: Tue Jan 17, 2012 9:18 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Right, so if I revert back to plain Lucene, I should be able to do this. Perhaps this is something to support in the querybuilder as well?


Top
 Profile  
 
 Post subject: Re: Checking for existence of fields Querybuilder
PostPosted: Thu Jan 26, 2012 7:27 am 
Hibernate Team
Hibernate Team

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

Quote:
Perhaps this is something to support in the querybuilder as well?


Maybe. The DSL and the query parser have slightly different usecases though (imo). What the DSL range query tries to do is to save you the time to convert your from and to parameters (remember search parameters are strings). You can pass dates, strings, numbers etc to from and to and Search will transparently apply the right bridge and analyzer to generate the actual search strings.

Lucene's query parser is much higler level. It is basically there to allow internet search engine like queries. In a way it is its own DSL. You can combine Search DSL queries and Lucene query-parser queries using boolean queries.

Should the from and to have something similar than the '*' - maybe. In this case I would imagine though that it would be better to extend the DSL by adding new methods to the range query. Or maybe from and to should be optional and if omitted represent the equivalent to '*'. I haven't thought this through all the way and I am not sure whether there would be any problems with this approach, but it sounds ok on first thought. WDYT?

Maybe you want to create a Jira issue describing your usecase.

--Hardy


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.