本文介绍了建筑物检查(lucene.net)用逗号分隔的索引ID列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用检查它是基于lucene.net搜索一个一把umbraco网站。我是pretty大量尝试,究竟是什么在下面的文章中所描述的事:

I have an Umbraco website that is using Examine search which is based on lucene.net. I am pretty much trying to do exactly what is described in the following article:

Querying对一个逗号分隔与ID列表检查和Lucene.net

我的问题是,当我尝试使用下面的code创建索引:

The problem I have is when I am trying to create the index using the following code:

// Loop through articles
        foreach (var a in articles)
        {
            yield return new SimpleDataSet()
            {
                NodeDefinition = new Examine.IndexedNode()
                {
                    NodeId = a.Id,
                    Type = "Article"

                },
                RowData = new Dictionary<string, string>()
                {
                    {"Name", a.Name},
                    {"Url", a.NiceUrl},
                    {"Category", "1234"},
                    {"Category", "5678"}
                }
            };
        }

我收到以下错误:

I am receiving the following error:

具有相同键的项已被添加。

有谁知道我怎样才能解决这个问题?

Does anyone know how I can get around this issue?

推荐答案

下面是做Lucene的,然而由于检查说一个完整的例子似乎在字典有输入​​限制flexiblity。然而改变检查处理它应该很简单。

Here is a full example of doing it in lucene, however as said Examine seems to limit the flexiblity by having input in a Dictionary. However changing examine to handle it should be simple.

public static void Main (string[] args)
    {
        Analyzer analyser = new StandardAnalyzer (Lucene.Net.Util.Version.LUCENE_CURRENT);
        Directory dir = new RAMDirectory ();

        using (IndexWriter iw = new IndexWriter (dir, analyser, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED)) {

            Document doc1 = new Document ();
            doc1.Add (new Field("title", "multivalued", Field.Store.YES, Field.Index.ANALYZED));
            doc1.Add (new Field("multival", "val1", Field.Store.YES, Field.Index.ANALYZED));
            doc1.Add (new Field("multival", "val2", Field.Store.YES, Field.Index.ANALYZED));
            iw.AddDocument (doc1);
            Document doc2 = new Document ();
            doc2.Add (new Field("title", "singlevalued", Field.Store.YES, Field.Index.ANALYZED));
            doc2.Add (new Field("multival", "val1", Field.Store.YES, Field.Index.ANALYZED));        
            iw.AddDocument (doc2);
        }

        using (Searcher searcher = new IndexSearcher (dir, true)) {
            var q1 = new TermQuery (new Term ("multival", "val1"));
            var q1result = searcher.Search (q1, 1000);

            //Will print "Found 2 documents"
            Console.WriteLine ("Found {0} documents", q1result.TotalHits);

            var q2 = new TermQuery (new Term ("multival", "val2"));
            var q2result = searcher.Search (q2, 1000);
            //Will print "Found 1 documents"
            Console.WriteLine ("Found {0} documents", q2result.TotalHits);
        }
    }

这篇关于建筑物检查(lucene.net)用逗号分隔的索引ID列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:34