【问题标题】:Lucene.net 4.8: Order of adding facetfields of importance?Lucene.net 4.8:添加重要的 facetfields 的顺序?
【发布时间】:2017-12-12 21:39:27
【问题描述】:

假设我有 2 个文档,每个文档有 2 个标签。

文档 1:标签 1、标签 2 文档 2:标签 2,标签 1

我正在像这样在 lucene 中构建一个文档:

        var doc = new Document
        {
            new StoredField("Id", blogPost.Id),
            new Int32Field("ModuleId", blogPost.ModuleId, Field.Store.YES),
            new TextField("Title", blogPost.Title, Field.Store.YES),
            new StringField("Slug", blogPost.Slug, Field.Store.YES),
            new StoredField("ImagePath", blogPost.ImagePath),
            new TextField("Intro", blogPost.Intro, Field.Store.YES),
            new TextField("Html", blogPost.Title, Field.Store.YES),
            new Int64Field("PublishDate", blogPost.PublishDate.Ticks, Field.Store.YES),
            new FacetField("PublishDateTag", blogPost.PublishDate.Year.ToString(), blogPost.PublishDate.Month.ToString(), blogPost.PublishDate.Year.ToString())
        };

        foreach (var tag in blogPost.TagObjects)
        {
            doc.Add(new Int32AssociationFacetField(1,"Tags", tag.Name));
            doc.Add(new StringField("Tag", tag.Name, Field.Store.YES));

            doc.Add(new Int32AssociationFacetField(1, "TagSlugs", tag.Slug));
            doc.Add(new StringField("TagSlug", tag.Slug, Field.Store.YES));

获取方面并没有像我想要的那样强硬。当我进行这样的搜索时:

        var facetsConfig = ConfigFacets();

        IList<FacetResult> results = new List<FacetResult>();

        using (var indexReader = DirectoryReader.Open(IndexDir))
        using (var taxoReader = new DirectoryTaxonomyReader(TaxoDir))
        {
            var searcher = new IndexSearcher(indexReader);
            var facetsCollector = new FacetsCollector();

            // MatchAllDocsQuery is for "browsing" (counts facets
            // for all non-deleted docs in the index); normally
            // you'd use a "normal" query:
            FacetsCollector.Search(searcher, new MatchAllDocsQuery(), 10, facetsCollector);

            // Retrieve results
            Facets tags = new TaxonomyFacetSumInt32Associations("$tag", taxoReader, facetsConfig, facetsCollector);
            results.Add(tags.GetTopChildren(10, "Tags"));

        } // Disposes indexReader and taxoReader

        if (results[0] == null)
            return new Dictionary<string, int>();

        return results.Where(x => x.Dim == "Tags").SelectMany(x => x.LabelValues).ToDictionary(x => x.Label, x => Convert.ToInt32(x.Value));

结果如下:标签1(1),标签1(1),标签2(1),标签2(1)

看起来标签的顺序在某种程度上起到了作用,这是我完全不想要的。我该如何解决这个问题?

【问题讨论】:

  • 没有人可以帮助我吗? :(

标签: lucene.net faceted-search


【解决方案1】:

该死的!原来是个愚蠢的错误。

我正在拆分字符串,但之后没有修剪它。所以我为第一个文档添加了“Tag 1”、“Tag 2”,为第二个文档添加了“Tag 2”、“Tag 1”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    • 2018-07-31
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多