You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Micky McQuade <mi...@vintagesoftware.com> on 2008/06/09 18:06:54 UTC
Searching Multiple Fields
Hi, I have the following code that is working:
Public Function SearchCities(ByVal SearchQuery As String) As
Lucene.Net.Search.Hits
Dim Analyzer As New Lucene.Net.Analysis.WhitespaceAnalyzer()
Dim QueryParser As New
Lucene.Net.QueryParsers.QueryParser("contents", Analyzer)
Dim Query As Lucene.Net.Search.Query = QueryParser.Parse(SearchQuery)
Return _CitySearcher.Search(Query)
End Function
It is searching the "contents" field. Is it possible to have it
search more than one field at the same time without having to run two
different searches. If I do have to run the searches separate, is
there a way to "merge" the results?
Thanks!
Micky
RE: Searching Multiple Fields
Posted by Digy <di...@gmail.com>.
"contents" is the default field to search when no fieldname is specified in
the query string.
A query string can also be like that
"+contents:aword +anotherfield:anotherword"
or
"contents:aword anotherfield:anotherword"
DIGY
-----Original Message-----
From: Micky McQuade [mailto:micky@vintagesoftware.com]
Sent: Monday, June 09, 2008 7:07 PM
To: lucene-net-user@incubator.apache.org
Subject: Searching Multiple Fields
Hi, I have the following code that is working:
Public Function SearchCities(ByVal SearchQuery As String) As
Lucene.Net.Search.Hits
Dim Analyzer As New Lucene.Net.Analysis.WhitespaceAnalyzer()
Dim QueryParser As New
Lucene.Net.QueryParsers.QueryParser("contents", Analyzer)
Dim Query As Lucene.Net.Search.Query =
QueryParser.Parse(SearchQuery)
Return _CitySearcher.Search(Query)
End Function
It is searching the "contents" field. Is it possible to have it
search more than one field at the same time without having to run two
different searches. If I do have to run the searches separate, is
there a way to "merge" the results?
Thanks!
Micky
RE: Searching Multiple Fields
Posted by "Granroth, Neal V." <ne...@thermofisher.com>.
Rather than directly searching with the Query returned by QueryParser you can combine that Query with other Queries using the BooleanQuery class, then call search using the composite BooleanQuery. For example:
BooleanQuery bq = new BooleanQuery();
bq.Add( Lucene.Net.QueryParsers.QueryParser.Parse( criteria, "_contents", new StandardAnalyzer() ), BooleanClause.Occur.SHOULD);
bq.Add( new TermQuery(new Term("filetype","txt")), BooleanClause.Occur.MUST_NOT);
hits = indexSearcher.Search(bq);
In this case I am searching for both information in the field "_contents" and for information in a field "filetype".
-- Neal
-----Original Message-----
From: Micky McQuade [mailto:micky@vintagesoftware.com]
Sent: Monday, June 09, 2008 11:07 AM
To: lucene-net-user@incubator.apache.org
Subject: Searching Multiple Fields
Hi, I have the following code that is working:
Public Function SearchCities(ByVal SearchQuery As String) As
Lucene.Net.Search.Hits
Dim Analyzer As New Lucene.Net.Analysis.WhitespaceAnalyzer()
Dim QueryParser As New
Lucene.Net.QueryParsers.QueryParser("contents", Analyzer)
Dim Query As Lucene.Net.Search.Query = QueryParser.Parse(SearchQuery)
Return _CitySearcher.Search(Query)
End Function
It is searching the "contents" field. Is it possible to have it
search more than one field at the same time without having to run two
different searches. If I do have to run the searches separate, is
there a way to "merge" the results?
Thanks!
Micky