Help with Query String Query

Hi,

I'm trying to do text search with boolean using QueryString query but it's
not hehaving as expected.

Let's say i have a field call *headline *in my database and i have the
following two headlines...

headline 1: "some random headline"
headline 2: "some other headline"

{"query_string":{
"default_field":"headline",
"query":"some AND random OR other"}
}

The above query should return both docs right? If not, what is wrong with
my query?

If i can change the query to "some OR random OR other", then it does return
both docs, but why didn't the AND work?

Thanks in advance for the help.

--

I am not sure AND has a higher priority than OR in Lucene. I would try
"grouping":

"some AND (random OR other)"

see
http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Booleanoperators

-- Raffaele

On Tue, Nov 6, 2012 at 1:59 PM, gchen kevinch84@gmail.com wrote:

Hi,

I'm trying to do text search with boolean using QueryString query but it's
not hehaving as expected.

Let's say i have a field call *headline *in my database and i have the
following two headlines...

headline 1: "some random headline"
headline 2: "some other headline"

{"query_string":{
"default_field":"headline",
"query":"some AND random OR other"}
}

The above query should return both docs right? If not, what is wrong with
my query?

If i can change the query to "some OR random OR other", then it does
return both docs, but why didn't the AND work?

Thanks in advance for the help.

--

--

Thanks Raffaele, grouping works. I agree with you, from what I've learn,
AND has higher precedence, so that means the query should also work
without grouping right? Unless i'm missing something fundamental?

On Tuesday, November 6, 2012 5:06:36 PM UTC-5, Raffaele Sena wrote:

I am not sure AND has a higher priority than OR in Lucene. I would try
"grouping":

"some AND (random OR other)"

see
http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Booleanoperators

-- Raffaele

On Tue, Nov 6, 2012 at 1:59 PM, gchen <kevi...@gmail.com <javascript:>>wrote:

Hi,

I'm trying to do text search with boolean using QueryString query but
it's not hehaving as expected.

Let's say i have a field call *headline *in my database and i have the
following two headlines...

headline 1: "some random headline"
headline 2: "some other headline"

{"query_string":{
"default_field":"headline",
"query":"some AND random OR other"}
}

The above query should return both docs right? If not, what is wrong
with my query?

If i can change the query to "some OR random OR other", then it does
return both docs, but why didn't the AND work?

Thanks in advance for the help.

--

--

Hello,

From what I understand by reading these two:
http://www.mail-archive.com/java-user@lucene.apache.org/msg00008.html
https://issues.apache.org/jira/browse/LUCENE-1823

This seems to be an issue with the way Lucene parses queries, which is
not resolved yet. So I think the best approach here is to use explicit
grouping through those parenthesis.

Best regards,
Radu

http://sematext.com/ -- ElasticSearch -- Solr -- Lucene

On Wed, Nov 7, 2012 at 1:44 AM, gchen kevinch84@gmail.com wrote:

Thanks Raffaele, grouping works. I agree with you, from what I've learn, AND
has higher precedence, so that means the query should also work without
grouping right? Unless i'm missing something fundamental?

On Tuesday, November 6, 2012 5:06:36 PM UTC-5, Raffaele Sena wrote:

I am not sure AND has a higher priority than OR in Lucene. I would try
"grouping":

"some AND (random OR other)"

see
http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Boolean
operators

-- Raffaele

On Tue, Nov 6, 2012 at 1:59 PM, gchen kevi...@gmail.com wrote:

Hi,

I'm trying to do text search with boolean using QueryString query but
it's not hehaving as expected.

Let's say i have a field call headline in my database and i have the
following two headlines...

headline 1: "some random headline"
headline 2: "some other headline"

{"query_string":{
"default_field":"headline",
"query":"some AND random OR other"}
}

The above query should return both docs right? If not, what is wrong
with my query?

If i can change the query to "some OR random OR other", then it does
return both docs, but why didn't the AND work?

Thanks in advance for the help.

--

--

--

I agree with Radu here. The operator precedence in the QueryParsers is
very messy and best handled through brackets.

On Wednesday, November 7, 2012 7:39:26 PM UTC+11, Radu Gheorghe wrote:

Hello,

From what I understand by reading these two:
http://www.mail-archive.com/java-user@lucene.apache.org/msg00008.html
https://issues.apache.org/jira/browse/LUCENE-1823

This seems to be an issue with the way Lucene parses queries, which is
not resolved yet. So I think the best approach here is to use explicit
grouping through those parenthesis.

Best regards,
Radu

http://sematext.com/ -- ElasticSearch -- Solr -- Lucene

On Wed, Nov 7, 2012 at 1:44 AM, gchen <kevi...@gmail.com <javascript:>>
wrote:

Thanks Raffaele, grouping works. I agree with you, from what I've learn,
AND
has higher precedence, so that means the query should also work without
grouping right? Unless i'm missing something fundamental?

On Tuesday, November 6, 2012 5:06:36 PM UTC-5, Raffaele Sena wrote:

I am not sure AND has a higher priority than OR in Lucene. I would try
"grouping":

"some AND (random OR other)"

see

http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Boolean

operators

-- Raffaele

On Tue, Nov 6, 2012 at 1:59 PM, gchen kevi...@gmail.com wrote:

Hi,

I'm trying to do text search with boolean using QueryString query but
it's not hehaving as expected.

Let's say i have a field call headline in my database and i have the
following two headlines...

headline 1: "some random headline"
headline 2: "some other headline"

{"query_string":{
"default_field":"headline",
"query":"some AND random OR other"}
}

The above query should return both docs right? If not, what is wrong
with my query?

If i can change the query to "some OR random OR other", then it does
return both docs, but why didn't the AND work?

Thanks in advance for the help.

--

--

--

Thanks for the help everyone!

--

Hey folks,

I usually recommend to use prefix operators: "+some +random other"
this way its pretty clear what is meant and you won't run into weird
brackets problems.

here http://java.dzone.com/articles/use-prefix-operators-instead is a
good writeup related to this too

simon

On Wednesday, November 7, 2012 11:31:31 AM UTC+1, Chris Male wrote:

I agree with Radu here. The operator precedence in the QueryParsers is
very messy and best handled through brackets.

On Wednesday, November 7, 2012 7:39:26 PM UTC+11, Radu Gheorghe wrote:

Hello,

From what I understand by reading these two:
http://www.mail-archive.com/java-user@lucene.apache.org/msg00008.html
https://issues.apache.org/jira/browse/LUCENE-1823

This seems to be an issue with the way Lucene parses queries, which is
not resolved yet. So I think the best approach here is to use explicit
grouping through those parenthesis.

Best regards,
Radu

http://sematext.com/ -- ElasticSearch -- Solr -- Lucene

On Wed, Nov 7, 2012 at 1:44 AM, gchen kevi...@gmail.com wrote:

Thanks Raffaele, grouping works. I agree with you, from what I've
learn, AND
has higher precedence, so that means the query should also work without
grouping right? Unless i'm missing something fundamental?

On Tuesday, November 6, 2012 5:06:36 PM UTC-5, Raffaele Sena wrote:

I am not sure AND has a higher priority than OR in Lucene. I would try
"grouping":

"some AND (random OR other)"

see

http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Boolean

operators

-- Raffaele

On Tue, Nov 6, 2012 at 1:59 PM, gchen kevi...@gmail.com wrote:

Hi,

I'm trying to do text search with boolean using QueryString query but
it's not hehaving as expected.

Let's say i have a field call headline in my database and i have the
following two headlines...

headline 1: "some random headline"
headline 2: "some other headline"

{"query_string":{
"default_field":"headline",
"query":"some AND random OR other"}
}

The above query should return both docs right? If not, what is wrong
with my query?

If i can change the query to "some OR random OR other", then it does
return both docs, but why didn't the AND work?

Thanks in advance for the help.

--

--

--