lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Rod.Mad...@ferguson.com>
Subject RE: MultiField Query
Date Mon, 17 Jul 2006 03:08:03 GMT
 
> I can think of two ways to do what you want, one with a parsed query
and one without.  With a parsed query:

> Query q = QueryParser.parse("+field1:silly +(field2:example
field3:example)",
>                             "field1", new StopAnalyzer());

When I try this ( using Lucene 2.0 API ) I get the error:
"..The method parse(String) is not applicable for arguments (String,
String, StopAnalyzer)


> If you already know the exact structure of the query, then you can
just build it up yourself, i.e. without the 
> QueryParser, like so:

> TermQuery t1 = new TermQuery(new Term("field1", "silly")); TermQuery
t2 = new TermQuery(new Term("field2", "example")); > TermQuery t3 = new
TermQuery(new Term("field3", "example")); Query subq = new
BooleanQuery(); 
> subq.add(t2, BooleanClause.Occur.Should); subq.add(t3,
BooleanClause.Occur.Should); 
> Query q = new BooleanQuery();
> q.add(t1,   BooleanClause.Occur.MUST);
> q.add(subq, BooleanClause.Occur.MUST);

When I try this I get the error:
The method add(TermQuery, BooleanClause.Occur) is undefined for type
Query

Could this be a 2.0 issue ?

Rod


-----Original Message-----
From: Michael D. Curtin [mailto:mike@curtin.com] 
Sent: Sunday, July 16, 2006 8:04 PM
To: java-user@lucene.apache.org
Subject: Re: MultiField Query

Rod.Madden@ferguson.com wrote:
> I am using Lucene 2.0 and trying to use the MultiFieldQueryParser in 
> my search.
>  
> I want to limit my search to documents which have "silly"
> in "field1" ...within that subset of documents, I want documents which

> have "example" in "field2" OR "field3"
>  
> The code fragment below is my attempt at this ...code blows on the : 
> Query query = qp.parse(...
> statement ...
>  
> Besides blowing, I believe that the MUST / MUST for field2 and field3 
> is inappropriate ...I really want to say ..if field1 has "silly"
> return documents with "example" in field2 OR field3.
> 
> Any suggestions for accomplishing this ? 
>  
> Someone suggested BooleanQuery but I was not sure how to merge that 
> concept in with the MultiFieldQueryParser ..

I can think of two ways to do what you want, one with a parsed query and
one without.  With a parsed query:

Query q = QueryParser.parse("+field1:silly +(field2:example
field3:example)",
                             "field1", new StopAnalyzer());

If you already know the exact structure of the query, then you can just
build it up yourself, i.e. without the QueryParser, like so:

TermQuery t1 = new TermQuery(new Term("field1", "silly")); TermQuery t2
= new TermQuery(new Term("field2", "example")); TermQuery t3 = new
TermQuery(new Term("field3", "example")); Query subq = new
BooleanQuery(); subq.add(t2, BooleanClause.Occur.Should); subq.add(t3,
BooleanClause.Occur.Should); Query q = new BooleanQuery();
q.add(t1,   BooleanClause.Occur.MUST);
q.add(subq, BooleanClause.Occur.MUST);

Good luck!

--MDC

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message