boolean query for multiple values on a specific field

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

boolean query for multiple values on a specific field

G.Long
Hi :)

I would like to retrieve a document from my index which must have a
field called "tag" for which the value must be "(01) value1" or
"value2". I'm using the lucene java api.

My code is the following:

String expression = "tag:(\"(01) value1\" value2)"
QueryParser parser = new QueryParser(Version.LUCENE_35, field,
RepositoryManager.getPerFieldAnalyzerWrapper(Version.LUCENE_35));
Query query = parser.parse(expression);
BooleanQuery bQuery = new BooleanQuery();
bQuery.add(query, Occur.MUST);

The tag field is associated to a keyword analyzer.

My problem is that the query parser removes the " characters. It returns
the query tag:(01) value1 tag:value2 which becomes
+(tag:(01) value1 tag:value2) when added to the boolean query and when
the query is executed it becomes +(tag:(UE) default_field:value1
tag:value2)

So it will return documents which have their tag field having the value
"value2" but not those with "(01) value1".

In the end I would like to obtain the query +(tag:"(01) value1"
tag:"value2").

Thanks,
Gary




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: boolean query for multiple values on a specific field

Jack Krupansky-3
Do you have other code you are not showing us? For example, what could are
you using to get the text of the parsed query?

Make sure your quotes are true ASCII quotes (double quote) and not the
curly quotes that word processors like to insert.

What is this Repository Manager? I mean, I see no code that would tell the
analyzer that "tag" is a defined field.

Also, I see no value to having the single-clause BooleanQuery wrapped
around the actual query.

-- Jack Krupansky

On Wed, Jan 27, 2016 at 12:52 PM, G.Long <[hidden email]> wrote:

> Hi :)
>
> I would like to retrieve a document from my index which must have a field
> called "tag" for which the value must be "(01) value1" or "value2". I'm
> using the lucene java api.
>
> My code is the following:
>
> String expression = "tag:(\"(01) value1\" value2)"
> QueryParser parser = new QueryParser(Version.LUCENE_35, field,
> RepositoryManager.getPerFieldAnalyzerWrapper(Version.LUCENE_35));
> Query query = parser.parse(expression);
> BooleanQuery bQuery = new BooleanQuery();
> bQuery.add(query, Occur.MUST);
>
> The tag field is associated to a keyword analyzer.
>
> My problem is that the query parser removes the " characters. It returns
> the query tag:(01) value1 tag:value2 which becomes
> +(tag:(01) value1 tag:value2) when added to the boolean query and when the
> query is executed it becomes +(tag:(UE) default_field:value1 tag:value2)
>
> So it will return documents which have their tag field having the value
> "value2" but not those with "(01) value1".
>
> In the end I would like to obtain the query +(tag:"(01) value1"
> tag:"value2").
>
> Thanks,
> Gary
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>