【问题标题】:Lucene.net not returning search resultsLucene.net 不返回搜索结果
【发布时间】:2019-09-20 09:38:37
【问题描述】:

我有 8 个文本文件,其中包含大约 500 万行类似的编码数据-

-通过文档 #12478901 将 TRNS_Legacy 类型的路径 TRNS_Legacy_773 分配给 DEV\svcInformational_1_7。现在有35个 使用 1 的此类路径

-Msg (len:482) 在 TRNS_Legacy_773 上发送:'FETCHIT IMG 771777777291;1;577;17;SAI13761671;1;577;IMG 771777771191;1;1;15;707747 261174767;23;19;07;187;314;315;316;318;327;486;480;670;230;238;239;247;279;427;421;109;512;924;935;936; IMG 771777777501;1;1;15;707747 261174767;9;5;64;65;66;01;06;122;184;940;IMG 771777777641;1;1;15;82748/4141541 ;9;245;246;249;248;244;243;242;241;620;IMG 771777771321;1;1;15;707747 261174767;29;4;19;25;20;62;64;65;66;07;87;81;82;122;187;194;241;245;370;315;316;319;579;517; 512;525;587;027;935;936;'

-消息 rcvd 并在 TRNS_Legacy_773 上相关,相关因子为“IAS1376167”。响应时间为 31 毫秒。

我已经使用 lucene.net 标准分析器对文件进行了索引。当我尝试搜索“4141541”或“FETCHIT”等子字符串时,搜索返回 0 个结果。我使用了 Luke,可以看到索引中存在数据。我可以使用行号进行搜索,但不能使用文本。有人可以帮帮我吗?

我尝试过使用通配符搜索,尝试不同的查询,尝试不同的分析器,将我的文本保持为标记化和未标记化,但它要么返回 0 个结果,要么只返回 1 或 2 行,即使应该返回 1000 行.

private Analyzer analyzer = new StandardAnalyzer();

建筑索引-

public void BuildIndex(string item)
    {

        string indexPath = string.Format(baseIndexPath, item);
        if (System.IO.Directory.Exists(indexPath))
        {
            System.IO.Directory.Delete(indexPath, true);
        }

        luceneIndexDirectory = FSDirectory.GetDirectory(indexPath);
        writer = new IndexWriter(indexPath, analyzer, true);
        //writer = new IndexWriter(luceneIndexDirectory, analyzer, true);

        string file = string.Format(@"LogFile.txt");
        string line=string.Empty;
        int count = 0;
        StreamReader fileReader = new StreamReader(file);
        while ((line = fileReader.ReadLine()) != null)
        {
            count++;
            Document doc = new Document();
            doc.Add(new Field("LineNumber", count.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
            doc.Add(new Field("LineText", line, Field.Store.YES, Field.Index.UN_TOKENIZED));

            writer.AddDocument(doc);
        }
        writer.Optimize();
        writer.Flush();
        writer.Close();
        luceneIndexDirectory.Close();
    }

公共 IEnumerable 搜索(字符串 searchTerm) {

        IndexSearcher searcher = new IndexSearcher(luceneIndexDirectory);
        QueryParser parser = new QueryParser("LineText", analyzer);
        TermQuery tQuery = new TermQuery(new Term("LineText",searchTerm));
        Query query = parser.Parse(searchTerm);
        Hits hitsFound = searcher.Search(query); //returns 0 results
        hitsFound = searcher.Search(tQuery); //returns 0 results
        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");


            results.Add(sampleDataFileRow);
        }

        return results.ToList();
    }

【问题讨论】:

  • 请说明您使用哪个Analyzer创建索引以及使用哪个Analyzer搜索索引。
  • 已添加到上面的代码中。私有 Analyzer 分析器 = new StandardAnalyzer();

标签: .net lucene lucene.net


【解决方案1】:

我怀疑问题在于 StandardAnalyzer 如何分解令牌。当您使用 Luke 时,我怀疑您不会将 4141541 或 FETCHIT 视为 LineText 术语中的单个标记,如果您想搜索这些值并获得结果,则需要它们。

【讨论】:

  • 谢谢,那我该如何解决呢?
  • 您能否确认在 Luke 中您没有将 4141541 或 FETCHIT 视为单独的标记?
猜你喜欢
  • 2018-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-26
  • 1970-01-01
相关资源
最近更新 更多