BooleanQuery工作但不是SpanNearQuery

时间:2012-09-05 05:04:06

标签: vb.net lucene.net

我有以下代码......

Dim term1 As Lucene.Net.Index.Term = New Lucene.Net.Index.Term("contents", "technical")
    Dim term2 As Lucene.Net.Index.Term = New Lucene.Net.Index.Term("contents", "c++")
    Dim span1 As SpanQuery = New SpanTermQuery(term1)
    Dim span2 As SpanQuery = New SpanTermQuery(term2)

    Dim spanQuery As SpanNearQuery = New SpanNearQuery(New SpanQuery() {
                                              span1,
                                              span2},
                                              2000000,
                                              False
                                          )

    Dim booleanQuery As BooleanQuery = New BooleanQuery()
    booleanQuery.SetMinimumNumberShouldMatch(0)

    booleanQuery.Add(span1, BooleanClause.Occur.SHOULD)
    booleanQuery.Add(span2, BooleanClause.Occur.SHOULD)

现在,如果我搜索布尔查询然后它返回一些文档,但如果我搜索SpanNearQuery然后它不返回任何文档..

这是我的索引代码..

    Dim indexLocation As String = "C:/index"

    Dim directory As Lucene.Net.Store.Directory = Lucene.Net.Store.FSDirectory.Open(New DirectoryInfo(indexLocation))

    'create an analyzer to process the text
    Dim analyzer As Lucene.Net.Analysis.Analyzer = New Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)

    'creating an index writer to write the doc to index
    Dim deletionPolicy As Lucene.Net.Index.IndexDeletionPolicy = New Lucene.Net.Index.KeepOnlyLastCommitDeletionPolicy()
    Dim indexWriter As Lucene.Net.Index.IndexWriter = New Lucene.Net.Index.IndexWriter(directory, analyzer, True, deletionPolicy, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED)

    Dim files() As String
    files = System.IO.Directory.GetFiles("C:\ResumeDirectory\")
    For i As Integer = 0 To files.Length - 1
        Dim streamReader As StreamReader = New StreamReader(files(i))

        Dim docField1 As Field = New Field("contents", streamReader, Lucene.Net.Documents.Field.TermVector.YES)
        Dim docField2 As Field = New Field("CandidateID", files(i), Field.Store.YES, Field.Index.NOT_ANALYZED)
        Dim doc As Document = New Document()
        doc.Add(docField1)
        doc.Add(docField2)

        'writing the document to index
        indexWriter.AddDocument(doc)
        streamReader.Close()
    Next

    'optimize and close the writer
    indexWriter.Optimize()
    indexWriter.Dispose()
End Sub

我的SpanNearQuery代码有什么问题吗?

0 个答案:

没有答案