You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Maurice Coyle <ma...@ucd.ie> on 2003/10/30 15:13:43 UTC
MultiFieldQueryParser default operator
are there any plans to implement some sort of
MultiFieldQueryParser.setOperator(int) method so folk can search using AND
by default?
or has anyone worked around the lack of such a method and managed to search
over multiple fields using a default-AND query?
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: MultiFieldQueryParser default operator
Posted by Maurice Coyle <ma...@ucd.ie>.
thanks otis, it was on the lucene-dev list (to which i'm not subscribed).
the link to the message containing bernhard's solution is below
http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg03863.html
happy days.
----- Original Message -----
From: "Otis Gospodnetic" <ot...@yahoo.com>
To: "Lucene Users List" <lu...@jakarta.apache.org>
Sent: Thursday, October 30, 2003 2:31 PM
Subject: Re: MultiFieldQueryParser default operator
> I believe a person just sent an email with a solution yesterday or the
> day before. Look for a message with MultiFieldQueryParser in its
> Subject.
>
> Otis
>
> --- Maurice Coyle <ma...@ucd.ie> wrote:
> > are there any plans to implement some sort of
> > MultiFieldQueryParser.setOperator(int) method so folk can search
> > using AND
> > by default?
> >
> > or has anyone worked around the lack of such a method and managed to
> > search
> > over multiple fields using a default-AND query?
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> >
>
>
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: MultiFieldQueryParser default operator
Posted by Michael Giles <mg...@visionstudio.com>.
This would be great to get fixed (I think I emailed a similar question a
month or so ago). If MultiFieldQueryParser is being mucked with, the
constructor should be updated to take an array of fields instead of the
single field it takes currently. The code snippet below is actually
passing the query ("britney spears") into the constructor instead of a
default field. If you made that single change to the constructor, no other
changes would be necessary, as you could simply call the parse(String)
method from QueryParser to do your work.
-Mike
At 10:03 AM 10/30/2003, you wrote:
>It was posted on lucene-dev, not lucene-user. I've pasted it below.
>
>I will be fixing this at some point in the near future based on this fix
>and other related ones needed.
>
> Erik
>
>-----
>
>From: Bernhard Messer <be...@intrafind.de>
>Date: Wed Oct 29, 2003 11:27:02 AM US/Eastern
>To: Lucene Developers List <lu...@jakarta.apache.org>
>Subject: MultiFieldQueryParser, can't change default search operator
>Reply-To: "Lucene Developers List" <lu...@jakarta.apache.org>
>
>hi all,
>
>just played around with the MultiFieldQueryParser and didn't find a
>working way to change the "operator" value.
>
>The problem is that MultiFieldQueryParser is implementing two public
>static methods "parse" only. Calling one of those, in the extended
>superclass, the static method implementation for "parse" is called. Due to
>the fact that the QueryParser class creates a new Instance for each call
>thru the static method, the "operator" flag is simply ignored.
>
>There would be a simple fix within MultiFieldQueryParser class without
>touching the rest of the system. One have to add a new non static method
>"parse" which could look like this:
>
>/***********************************************************/
>public Query parse(String query, String[] fields) throws ParseException {
> BooleanQuery bQuery = new BooleanQuery();
>
> for (int i = 0; i < fields.length; i++)
> {
> QueryParser parser = new QueryParser(fields[i], analyzer);
> parser.setOperator(getOperator());
> Query q = parser.parse(query);
> bQuery.add(q, false, false);
> }
> return bQuery;
> }
>/***********************************************************/
>
>
>To test the new implementation, following code fragment can be used:
>
>/***********************************************************/
> Directory directory =
> FSDirectory.getDirectory("/tmp/idx-test", false);
> Analyzer analyzer = new SimpleAnalyzer();
> Searcher searcher = new IndexSearcher(directory);
> Hits hits = null;
> String[] fields = { "contents", "title" };
> MultiFieldQueryParser parser = new
> MultiFieldQueryParser("britney spears", analyzer);
>
>parser.setOperator(QueryParser.DEFAULT_OPERATOR_AND);
> Query query = parser.parse("britney spears",
> fields);
> System.out.println("Query: " + query.toString());
> hits = searcher.search(query);
>
> System.out.println ("Results: " + hits.length());
> searcher.close();
>/***********************************************************/
>
>
>best regards
>
>Bernhard
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: MultiFieldQueryParser default operator
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
It was posted on lucene-dev, not lucene-user. I've pasted it below.
I will be fixing this at some point in the near future based on this
fix and other related ones needed.
Erik
On Thursday, October 30, 2003, at 09:31 AM, Otis Gospodnetic wrote:
> I believe a person just sent an email with a solution yesterday or the
> day before. Look for a message with MultiFieldQueryParser in its
> Subject.
>
> Otis
>
> --- Maurice Coyle <ma...@ucd.ie> wrote:
>> are there any plans to implement some sort of
>> MultiFieldQueryParser.setOperator(int) method so folk can search
>> using AND
>> by default?
>>
>> or has anyone worked around the lack of such a method and managed to
>> search
>> over multiple fields using a default-AND query?
-----
From: Bernhard Messer <be...@intrafind.de>
Date: Wed Oct 29, 2003 11:27:02 AM US/Eastern
To: Lucene Developers List <lu...@jakarta.apache.org>
Subject: MultiFieldQueryParser, can't change default search operator
Reply-To: "Lucene Developers List" <lu...@jakarta.apache.org>
hi all,
just played around with the MultiFieldQueryParser and didn't find a
working way to change the "operator" value.
The problem is that MultiFieldQueryParser is implementing two public
static methods "parse" only. Calling one of those, in the extended
superclass, the static method implementation for "parse" is called. Due
to the fact that the QueryParser class creates a new Instance for each
call thru the static method, the "operator" flag is simply ignored.
There would be a simple fix within MultiFieldQueryParser class without
touching the rest of the system. One have to add a new non static
method "parse" which could look like this:
/***********************************************************/
public Query parse(String query, String[] fields) throws ParseException
{
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.length; i++)
{
QueryParser parser = new QueryParser(fields[i], analyzer);
parser.setOperator(getOperator());
Query q = parser.parse(query);
bQuery.add(q, false, false);
}
return bQuery;
}
/***********************************************************/
To test the new implementation, following code fragment can be used:
/***********************************************************/
Directory directory =
FSDirectory.getDirectory("/tmp/idx-test", false);
Analyzer analyzer = new SimpleAnalyzer();
Searcher searcher = new IndexSearcher(directory);
Hits hits = null;
String[] fields = { "contents", "title" };
MultiFieldQueryParser parser = new
MultiFieldQueryParser("britney spears", analyzer);
parser.setOperator(QueryParser.DEFAULT_OPERATOR_AND);
Query query = parser.parse("britney
spears", fields);
System.out.println("Query: " + query.toString());
hits = searcher.search(query);
System.out.println ("Results: " + hits.length());
searcher.close();
/***********************************************************/
best regards
Bernhard
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: MultiFieldQueryParser default operator
Posted by Otis Gospodnetic <ot...@yahoo.com>.
I believe a person just sent an email with a solution yesterday or the
day before. Look for a message with MultiFieldQueryParser in its
Subject.
Otis
--- Maurice Coyle <ma...@ucd.ie> wrote:
> are there any plans to implement some sort of
> MultiFieldQueryParser.setOperator(int) method so folk can search
> using AND
> by default?
>
> or has anyone worked around the lack of such a method and managed to
> search
> over multiple fields using a default-AND query?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org