lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Granroth, Neal V." <>
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 []
Sent: Monday, June 09, 2008 11:07 AM
Subject: Searching Multiple Fields

Hi, I have the following code that is working:

    Public Function SearchCities(ByVal SearchQuery As String) As
        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?


View raw message