-->
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.  [ 2 posts ] 
Author Message
 Post subject: bool.must with potentially null values
PostPosted: Tue Jun 25, 2013 4:21 am 
Beginner
Beginner

Joined: Mon Nov 26, 2012 4:08 am
Posts: 24
Hi all!
We have a problem restricting the output in one of our Hibernate search queries.
We would like to restrict the result to only allow results with a certain status.
We check the status on several fields in the query. Here is an extract of our code.
The problem we have is that field2 below sometimes can be null and that is OK but we would like to build the query somehow like
"if field1.field2 == null or field1.field2.status.statusId == 3"
Is that possible?

// status check, doesn't work if field2 is null
bool.must(queryBuilder
.keyword()
.onField("field1.field2.status.statusId")
.matching(3)
.createQuery());
bool.must(queryBuilder
.keyword()
.onField("field1.status.statusId")
.matching(3)
.createQuery());
bool.must(queryBuilder
.keyword()
.onField("status.statusId")
.matching(3)
.createQuery());


Top
 Profile  
 
 Post subject: Re: bool.must with potentially null values
PostPosted: Thu Jun 27, 2013 3:39 am 
Beginner
Beginner

Joined: Mon Nov 26, 2012 4:08 am
Posts: 24
We have solved the problem.
We ended up using The Lucine API and the QueryParser.
We also used @IndexedEmbedded(indexNullAs = IndexedEmbedded.DEFAULT_NULL_TOKEN) on field2.

bool.must(parser.parse("field1.field2:_null_" + " OR field1.field2.status.statusId:3"));

Have we found a bug or is there a logical explanation to the following?
As you can see above, we use the constant IndexedEmbedded.DEFAULT_NULL_TOKEN which holds the value "__DEFAULT_NULL_TOKEN__".
First we tried parser.parse("field1.field2:"+IndexedEmbedded.DEFAULT_NULL_TOKEN but this didn't work. When I looked in the index with Luke, it was indexed as _null_.
Then I tried @IndexedEmbedded(indexNullAs = "MY_NULL_VALUE"), the index showed "MY_NULL_VALUE" in Luke but the query still didn't work when I used "MY_NULL_VALUE" in the query.
I an only get it to work if I use @IndexedEmbedded(indexNullAs = IndexedEmbedded.DEFAULT_NULL_TOKEN) and _null_ as value in the query.

If only IndexedEmbedded.DEFAULT_NULL_TOKEN is an accepted value, why can we choose a value in the first place?
And why does "__DEFAULT_NULL_TOKEN__" get translated to "_null_" in the index?

Anyone have an explanation to this behaviour?

Regards
Andreas


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