我使用 NuGet 包管理器下载了 Lucene.net 2.9.4.1 并使用以下代码创建了一个测试索引:
Dim sysDir As New System.IO.DirectoryInfo(Server.MapPath("~/index"))
Dim indexDir As Store.Directory = Store.FSDirectory.Open(sysDir)
Dim analyzer As Analysis.Analyzer = New Analysis.Standard.StandardAnalyzer(Util.Version.LUCENE_29)
Dim indexWriter As Index.IndexWriter = New Index.IndexWriter(indexDir, analyzer, True, Index.IndexWriter.MaxFieldLength.UNLIMITED)
Dim doc As Documents.Document = New Documents.Document()
Dim fldContent As Documents.Field = New Documents.Field("content", "The quick brown fox jumps over the lazy dog", Documents.Field.Store.YES, Documents.Field.Index.ANALYZED, Documents.Field.TermVector.YES)
doc.Add(fldContent)
indexWriter.AddDocument(doc)
indexWriter.Optimize()
indexWriter.Close()
indexDir.Close()
接下来,当我开始编写执行搜索的代码时,我无法访问 TopDocs 类的 totalHits 属性。这是代码:
Dim sysDir As New System.IO.DirectoryInfo(Server.MapPath("~/index"))
Dim indexDir As Store.Directory = Store.FSDirectory.Open(sysDir)
Dim searcher As Search.IndexSearcher = New Search.IndexSearcher(indexDir, True)
Dim searchTerm As Index.Term = New Index.Term("content", "fox")
Dim query As Search.Query = New Search.TermQuery(searchTerm)
Dim tdocs As Search.TopDocs = searcher.Search(query, Nothing, 100)
当我在下一行键入“tdocs”后跟一个点时,我只能访问 GetMaxScore 和 SetMaxScore 方法以及 MaxScore 属性 - 我看不到任何显示“totalHits”的属性。
我错过了什么吗?有没有人有一些示例代码,他们使用 Lucene.net.Search.TopDocs 而不是 Lucene.net.Search.Hits(据说已经过时)。