如何从Lucene中的Hits迁移到Topdocs c#

时间:2018-01-22 20:52:44

标签: c# lucene

我有一个用lucene 2.9编写的程序,我正在尝试将其迁移到lucene 3.0,我有下一个代码:

    public IEnumerable<SampleDataFileRow> Search(string searchTerm)
    {
        IndexSearcher searcher = new IndexSearcher(luceneIndexDirectory);
        QueryParser parser = new QueryParser("LineText", analyzer);

        Query query = parser.Parse(searchTerm);
        Hits hitsFound = searcher.Search(query);
        List<SampleDataFileRow> results = new List<SampleDataFileRow>();
        SampleDataFileRow sampleDataFileRow = null;

        for (int i = 0; i < hitsFound.Length(); i++)
        {
            sampleDataFileRow = new SampleDataFileRow();
            Document doc = hitsFound.Doc(i);
            sampleDataFileRow.LineNumber = int.Parse(doc.Get("LineNumber"));
            sampleDataFileRow.LineText = doc.Get("LineText");
            float score = hitsFound.Score(i);
            sampleDataFileRow.Score = score;

            results.Add(sampleDataFileRow);
        }

        return results.OrderByDescending(x => x.Score).ToList();
    }

我已经有了这个:

    public IEnumerable<SampleDataFileRow> Search(string searchTerm)
    {
        IndexSearcher searcher = new IndexSearcher(luceneIndexDirectory);
        QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, 
                                                "LineText", analyzer);
        Query query = parser.Parse(searchTerm);
        TopDocs topdocs = searcher.Search(query, 1000);
        List<SampleDataFileRow> results = new List<SampleDataFileRow>();
        SampleDataFileRow sampleDataFileRow = null;

        for (int i = 0; i < topdocs.ScoreDocs.Length; i++)
        {
            sampleDataFileRow = new SampleDataFileRow();
            Document doc = searcher.Doc(i);
            sampleDataFileRow.LineNumber = int.Parse(doc.Get("LineNumber"));
            sampleDataFileRow.LineText = doc.Get("LineText");
            float score = topdocs.ScoreDocs(i);
            sampleDataFileRow.Score = score;

            results.Add(sampleDataFileRow);
        }

        return results.OrderByDescending(x => x.Score).ToList();

    }

但我对这部分有疑问:

   float score = topdocs.ScoreDocs(i);

如何获得点击率?非常感谢提前!

0 个答案:

没有答案