lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Granroth, Neal V." <neal.granr...@thermofisher.com>
Subject RE: Searching Multiple Fields
Date Mon, 09 Jun 2008 16:56:44 GMT

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

Mime
View raw message