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 Gaston <ga...@artentis.com> on 2005/12/29 13:42:12 UTC

QueryParser over multiple fields

Hallo,


in my index every document consistsof multiple fields like 
url,contents,description etc.I want to search for documents in the url 
and the contents field.
My problem is that the constructor of QueryParser only provide one field 
like "Query query=QueryParser.parse("query",field1,analyzer);"
Is there an oppurtinity to construct an query Object like "Query 
query=QueryParser.parse("query",field1,field2,analyzer);" to provide a 
search over field1 and field2 ?
I solved this problem in a very unelegant way I think because I 
introduced two searching procedures in my application, one for field1 
and the another one for field2. But this is very bad for the performance 
because the application has to search two times.

I am glad about every suggestion


Greetings


Gaston


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


Re: QueryParser over multiple fields

Posted by eu...@cologne-systems.de.
>

>
> That's a perfectly good approach as well.  I didn't mean to imply
> that there were only "two options", just that the two I suggested
> were the most commonly used ones.
>
> 	Erik
>


Ah, for a moment i thought i had overlooked a "canonical" solution, i'm
quite new to lucene. Thanks.

BTW, Lucene in Action is a great book.

Ernst-Udo



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


Re: QueryParser over multiple fields

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Dec 29, 2005, at 9:31 AM, euw@cologne-systems.de wrote:
>>
>> Two options - MultiFieldQueryParser or building an aggregate single
>> field to search.  I use the aggregate field option, which entails
>> building an additional field for each document, I call it "contents",
>> and index _all_ of the searchable text into that field.
>>
>> 	Erik
>
>
> How about a BooleanQuery? I have documents with text, headlines, and
> keywords, each needing a different analyzer and boost factor. I'm
> experimenting with PerFieldAnalyzerWrapper and KeywordAnalyzer (as
> described in your book), constructing the Query from a
> QueryParser.parse(query, field, analyzer) query on each of the fields,
> connected as a BooleanQuery. Like this, i can use a different boost  
> factor
> and a different analyzer for each field, and tune the whole thing  
> quite
> easily. The drawback is that analyzer and query construction look a  
> little
> cumbersome.
>
> As i said, i've been only experimenting with this. I don't know if  
> this
> would work in production code, but i don't see why not. What's your  
> take
> on this?

That's a perfectly good approach as well.  I didn't mean to imply  
that there were only "two options", just that the two I suggested  
were the most commonly used ones.

	Erik


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


Re: QueryParser over multiple fields

Posted by eu...@cologne-systems.de.
>
> Two options - MultiFieldQueryParser or building an aggregate single
> field to search.  I use the aggregate field option, which entails
> building an additional field for each document, I call it "contents",
> and index _all_ of the searchable text into that field.
>
> 	Erik


How about a BooleanQuery? I have documents with text, headlines, and
keywords, each needing a different analyzer and boost factor. I'm
experimenting with PerFieldAnalyzerWrapper and KeywordAnalyzer (as
described in your book), constructing the Query from a
QueryParser.parse(query, field, analyzer) query on each of the fields,
connected as a BooleanQuery. Like this, i can use a different boost factor
and a different analyzer for each field, and tune the whole thing quite
easily. The drawback is that analyzer and query construction look a little
cumbersome.

As i said, i've been only experimenting with this. I don't know if this
would work in production code, but i don't see why not. What's your take
on this?

Ernst-Udo Wallenborn



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


Re: QueryParser over multiple fields

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Dec 29, 2005, at 7:42 AM, Gaston wrote:
> in my index every document consistsof multiple fields like  
> url,contents,description etc.I want to search for documents in the  
> url and the contents field.
> My problem is that the constructor of QueryParser only provide one  
> field like "Query query=QueryParser.parse("query",field1,analyzer);"
> Is there an oppurtinity to construct an query Object like "Query  
> query=QueryParser.parse("query",field1,field2,analyzer);" to  
> provide a search over field1 and field2 ?
> I solved this problem in a very unelegant way I think because I  
> introduced two searching procedures in my application, one for  
> field1 and the another one for field2. But this is very bad for the  
> performance because the application has to search two times.

Two options - MultiFieldQueryParser or building an aggregate single  
field to search.  I use the aggregate field option, which entails  
building an additional field for each document, I call it "contents",  
and index _all_ of the searchable text into that field.

	Erik


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