You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Sudhanya Chatterjee <su...@persistent.co.in> on 2008/05/08 08:25:03 UTC

AND OR operators for untokenized fields

Hi,

 

In our application we are adding multiple fields to lucene document while
indexing.

Analyzer used is StandardAnalyzer.

Few fields are tokenized and few untokenized.

While searching QueryParser returns proper results for fields which are
tokenized and not for untokenized.

We also need to support AND , OR operators in search phrase.

With QueryParser these operators are supported.

For untokenized fields the queries are created using phraseQuery.

We need to support AND OR operators for all fields.

How to achieve this?

 

Thanks,

Sudhanya


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

RE: AND OR operators for untokenized fields

Posted by Michael Garski <mg...@myspace.com>.
Could you provide some examples of the data in the untokenized fields?  At first glance there really is no need to use a PhraseQuery for the untokenized fields - a simple term query would suffice for that case.

How should your clauses be grouped?

Like:
(<searchTerm1> AND < searchTerm2>) OR (< searchTerm3> AND < searchTerm4>)

Or:
<searchTerm1> AND (< searchTerm2> OR < searchTerm3>) AND < searchTerm4>

You can create a BooleanQuery with other BooleanQueries as clauses to group them as desired.

Michael

-----Original Message-----
From: Sudhanya Chatterjee [mailto:sudhanya_chatterjee@persistent.co.in] 
Sent: Thursday, May 08, 2008 12:09 AM
To: lucene-net-user@incubator.apache.org
Subject: RE: AND OR operators for untokenized fields

We are creating the query in the following way - 
For tokenized fields - 

QueryParser queryParse = new QueryParser(field, new StandardAnalyzer()));
Query qry = queryParse.Parse(field + ":" + searchTerm);
bq.Add(qry, BooleanClause.Occur.SHOULD); //bq is the Boolean query

For Untokenized fields - 

PhraseQuery queryPhrase = new PhraseQuery();
queryPhrase.SetSlop(0);
queryPhrase.Add(new Term(field, searchTerm.Trim().ToLower()));
bq.Add(queryPhrase, BooleanClause.Occur.SHOULD); //bq is the Boolean query

In the above two situations how to construct queries of the following type -

<searchTerm1> AND < searchTerm2> OR < searchTerm3> AND < searchTerm4>

Thanks,
Sudhanya
-----Original Message-----
From: Jokin Cuadrado [mailto:jokin.c@gmail.com] 
Sent: Thursday, May 08, 2008 12:18 PM
To: lucene-net-user@incubator.apache.org
Subject: Re: AND OR operators for untokenized fields

i'm not very sure of what are your needs,  but if queryparser don't
suit them, you can always construct  the query programatically.

On 5/8/08, Sudhanya Chatterjee <su...@persistent.co.in> wrote:
> Hi,
>
>
>
> In our application we are adding multiple fields to lucene document while
> indexing.
>
> Analyzer used is StandardAnalyzer.
>
> Few fields are tokenized and few untokenized.
>
> While searching QueryParser returns proper results for fields which are
> tokenized and not for untokenized.
>
> We also need to support AND , OR operators in search phrase.
>
> With QueryParser these operators are supported.
>
> For untokenized fields the queries are created using phraseQuery.
>
> We need to support AND OR operators for all fields.
>
> How to achieve this?
>
>
>
> Thanks,
>
> Sudhanya
>
>
> DISCLAIMER
> ==========
> This e-mail may contain privileged and confidential information which is
the
> property of Persistent Systems Ltd. It is intended only for the use of the
> individual or entity to which it is addressed. If you are not the intended
> recipient, you are not authorized to read, retain, copy, print, distribute
> or use this message. If you have received this communication in error,
> please notify the sender and delete all copies of this message. Persistent
> Systems Ltd. does not accept any liability for virus infected mails.
>


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

RE: AND OR operators for untokenized fields

Posted by Sudhanya Chatterjee <su...@persistent.co.in>.
We are creating the query in the following way - 
For tokenized fields - 

QueryParser queryParse = new QueryParser(field, new StandardAnalyzer()));
Query qry = queryParse.Parse(field + ":" + searchTerm);
bq.Add(qry, BooleanClause.Occur.SHOULD); //bq is the Boolean query

For Untokenized fields - 

PhraseQuery queryPhrase = new PhraseQuery();
queryPhrase.SetSlop(0);
queryPhrase.Add(new Term(field, searchTerm.Trim().ToLower()));
bq.Add(queryPhrase, BooleanClause.Occur.SHOULD); //bq is the Boolean query

In the above two situations how to construct queries of the following type -

<searchTerm1> AND < searchTerm2> OR < searchTerm3> AND < searchTerm4>

Thanks,
Sudhanya
-----Original Message-----
From: Jokin Cuadrado [mailto:jokin.c@gmail.com] 
Sent: Thursday, May 08, 2008 12:18 PM
To: lucene-net-user@incubator.apache.org
Subject: Re: AND OR operators for untokenized fields

i'm not very sure of what are your needs,  but if queryparser don't
suit them, you can always construct  the query programatically.

On 5/8/08, Sudhanya Chatterjee <su...@persistent.co.in> wrote:
> Hi,
>
>
>
> In our application we are adding multiple fields to lucene document while
> indexing.
>
> Analyzer used is StandardAnalyzer.
>
> Few fields are tokenized and few untokenized.
>
> While searching QueryParser returns proper results for fields which are
> tokenized and not for untokenized.
>
> We also need to support AND , OR operators in search phrase.
>
> With QueryParser these operators are supported.
>
> For untokenized fields the queries are created using phraseQuery.
>
> We need to support AND OR operators for all fields.
>
> How to achieve this?
>
>
>
> Thanks,
>
> Sudhanya
>
>
> DISCLAIMER
> ==========
> This e-mail may contain privileged and confidential information which is
the
> property of Persistent Systems Ltd. It is intended only for the use of the
> individual or entity to which it is addressed. If you are not the intended
> recipient, you are not authorized to read, retain, copy, print, distribute
> or use this message. If you have received this communication in error,
> please notify the sender and delete all copies of this message. Persistent
> Systems Ltd. does not accept any liability for virus infected mails.
>


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

Re: AND OR operators for untokenized fields

Posted by Jokin Cuadrado <jo...@gmail.com>.
i'm not very sure of what are your needs,  but if queryparser don't
suit them, you can always construct  the query programatically.

On 5/8/08, Sudhanya Chatterjee <su...@persistent.co.in> wrote:
> Hi,
>
>
>
> In our application we are adding multiple fields to lucene document while
> indexing.
>
> Analyzer used is StandardAnalyzer.
>
> Few fields are tokenized and few untokenized.
>
> While searching QueryParser returns proper results for fields which are
> tokenized and not for untokenized.
>
> We also need to support AND , OR operators in search phrase.
>
> With QueryParser these operators are supported.
>
> For untokenized fields the queries are created using phraseQuery.
>
> We need to support AND OR operators for all fields.
>
> How to achieve this?
>
>
>
> Thanks,
>
> Sudhanya
>
>
> DISCLAIMER
> ==========
> This e-mail may contain privileged and confidential information which is the
> property of Persistent Systems Ltd. It is intended only for the use of the
> individual or entity to which it is addressed. If you are not the intended
> recipient, you are not authorized to read, retain, copy, print, distribute
> or use this message. If you have received this communication in error,
> please notify the sender and delete all copies of this message. Persistent
> Systems Ltd. does not accept any liability for virus infected mails.
>