How do I setup the following boolean search?
 
(A OR B) AND C?
 
here is my code snippet:
 
 
            Dim OccurAs As BooleanClause.Occur = BooleanClause.Occur.SHOULD
            Dim custSort As Sort = New Sort(New SortField() {New
SortField("MsgDate"), SortField.FIELD_SCORE})
            Dim analyzer As Analyzer = New StandardAnalyzer()
            Dim query As BooleanQuery = New BooleanQuery()
            If BodyQuery <> "" Then
                For Each token As String In Split(BodyQuery, " ")
                    If token <> "" Then
                        query.Add(New SpanTermQuery(New Term("Body",
token)), OccurAs)
                    End If
                Next
            End If
            If (CategoryId > -1) Then
                query.Add(New SpanTermQuery(New Term("CategoryId",
CategoryId)), BooleanClause.Occur.MUST)
            End If
            Dim df1 As RangeFilter = Nothing
            
            Dim hits As Hits = Nothing
            Dim searchInitRetry As Integer = 20
            Dim searcher As IndexSearcher = Nothing
            searcher = New
IndexSearcher(ConfigurationManager.AppSettings("SearchIndexDir") &
RAMContainer.GetInstance().CurrentStore)
            hits = searcher.Search(query, df1, custSort)
            Dim ResultCount As Integer = Math.Min(hits.Length(),
QuestionSearchService.MaxResults)
            If QuestionSearchService.DebugWriteMode Then
                Debug.WriteLine("QSSearch: " & hits.Length() & " hits ")
            End If
 
>From this, the BodyQuery is the (A OR B) part and the CategoryId is the AND
C part.  As it is right now, it seems to behave more like (A OR B) OR C
since it is all in one boolean query.
 
Thanks in advance,
Michael
 

Reply via email to