Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Lucene.net-TopDocs缺少totalHits?_C#_Asp.net_Vb.net_Lucene_Lucene.net - Fatal编程技术网

C# Lucene.net-TopDocs缺少totalHits?

C# Lucene.net-TopDocs缺少totalHits?,c#,asp.net,vb.net,lucene,lucene.net,C#,Asp.net,Vb.net,Lucene,Lucene.net,我使用NuGet Package Manager下载了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.Stand

我使用NuGet Package Manager下载了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(据说已经过时)的示例代码

下面是示例C#代码:


这是因为您使用VB,目前Lucene不符合CLS

认为这与将在下一版本中修复的bug有关。

这是因为您使用VB,目前Lucene不符合CLS

认为这与将在下一版本中修复的bug有关。 我知道这可能有点晚了,但希望它能在将来帮助你或其他人

为了解决2.9.4中的问题,我在TopDocs类中编辑了源代码。它不起作用的原因是VB不区分大小写,而C#区分大小写(我们都知道)

TopDocs类具有totalHits int属性和totalHits int属性。查看代码后,我意识到TotalHits属性只是获取/设置TotalHits变量。所以我只是在类中将totalHits变量的名称更改为totalHits\u,然后重新构建库

一旦它建立起来,我的另一个项目就能够从我的VB.Net代码中访问TotalHits属性。

我知道这可能有点晚了,但希望它能在将来帮助您或其他人

为了解决2.9.4中的问题,我在TopDocs类中编辑了源代码。它不起作用的原因是VB不区分大小写,而C#区分大小写(我们都知道)

TopDocs类具有totalHits int属性和totalHits int属性。查看代码后,我意识到TotalHits属性只是获取/设置TotalHits变量。所以我只是在类中将totalHits变量的名称更改为totalHits\u,然后重新构建库


一旦它建立起来,我的另一个项目就可以从我的VB.Net代码中访问TotalHits属性。

谢谢。如果您能够访问totalHits属性,请告诉我您使用的是哪个版本的Lucene.net程序集?你是用NuGet添加的吗?我现在用的是Lucene.Net 2.9.2.1,不是通过NuGet添加的,只是下载了源代码,构建并添加了dll。谢谢。如果您能够访问totalHits属性,请告诉我您使用的是哪个版本的Lucene.net程序集?你是用NuGet添加的吗?我目前使用的是Lucene.Net 2.9.2.1,不是通过NuGet添加的,只是下载了源代码,构建了它并添加了dll。没错,我手动更新到Lucene.Net 2.9.4g并使topDocs类工作。没错,我手动更新到Lucene.Net 2.9.4g并使topDocs类工作。
TopDocs topDocs = searcher.Search(query, luceneHitsLimit);
if (topDocs != null) {
    int totalResults = topDocs.totalHits;
    ScoreDoc[] scoreDocs = topDocs.scoreDocs;
    foreach(ScoreDoc scoreDoc in scoreDocs) {
        Document doc = searcher.Doc(scoreDoc.doc);
        ...
    }
}