代码之家  ›  专栏  ›  技术社区  ›  Sam Jones

使用lucene将boosting添加到Umbraco中的特定文档类型

  •  1
  • Sam Jones  · 技术社区  · 8 年前

    我试图增加特定的Umbraco文档类型,但是当使用Luke查看分数时,分数为0.0035。

    我在用Lucene.net网站版本2.9.4.1。

    enter image description here

    我试图通过使用 DocumentWriting 事件,我的代码如下,它确实会被调用,我能够单步执行并确保到达正确的boost行:

    using System;
    using Examine;
    using Examine.LuceneEngine;
    using Examine.LuceneEngine.Providers;
    using Spurs.Site.Models.Enums;
    using Umbraco.Core;
    
    namespace Spurs.Site.Infrastructure
    {
        public class UmbracoEvents : ApplicationEventHandler
        {
            public UmbracoEvents()
            {
                var indexer = (LuceneIndexer)ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"];
    
                indexer.DocumentWriting += Indexer_DocumentWriting;
            }
    
            private void Indexer_DocumentWriting(object sender, DocumentWritingEventArgs e)
            {
                string nodeTypeAlias;
                var hasNodeTypeAlias = e.Fields.TryGetValue("nodeTypeAlias", out nodeTypeAlias);
    
                if (!hasNodeTypeAlias)
                    return;
    
                DocumentTypeAlias documentType = (DocumentTypeAlias)Enum.Parse(typeof(DocumentTypeAlias), nodeTypeAlias, true);
    
                switch (documentType)
                {
                    case DocumentTypeAlias.playerPage:
                        e.Document.SetBoost(1000f);
                        break;
                    case DocumentTypeAlias.fixturePage:
                        e.Document.SetBoost(500f);
                        break;
                    default:
                        e.Document.SetBoost(1f);
                        break;
                }
            }
        }
    }
    

    我一定是丢了什么东西,好像 e.Document.SetBoost 没有保存。

    0 回复  |  直到 7 年前