选择性地从Sitecore的Lucene搜索索引中排除项目-使用IndexViewer进行重建时有效,但使用Sitecore的内置工具时则无效

如何解决选择性地从Sitecore的Lucene搜索索引中排除项目-使用IndexViewer进行重建时有效,但使用Sitecore的内置工具时则无效

| 在由Sitecore 6.2驱动的网站上,我需要为用户提供从搜索结果中选择性排除项目的功能。 为此,我添加了一个名为“包含在搜索结果中”的复选框字段,并创建了一个自定义数据库搜寻器来检查该字段的值: 〜\\ App_Config \\ Include \\ Search Indexes \\ Website.config:
<search>
  <configuration type=\"Sitecore.Search.SearchConfiguration,Sitecore.Kernel\" singleInstance=\"true\">
    <indexes hint=\"list:AddIndex\">
      <index id=\"website\" singleInstance=\"true\" type=\"Sitecore.Search.Index,Sitecore.Kernel\">
        ...

        <locations hint=\"list:AddCrawler\">
          <master type=\"MyProject.Lib.Search.Indexing.CustomCrawler,MyProject\">
            ...
          </master>

          <!-- Similar entry for web database. -->
        </locations>
      </index>
    </indexes>
  </configuration>
</search>
〜\\ Lib \\ Search \\ Indexing \\ CustomCrawler.cs:
using Lucene.Net.Documents;
using Sitecore.Search.Crawlers;
using Sitecore.Data.Items;

namespace MyProject.Lib.Search.Indexing
{
  public class CustomCrawler : DatabaseCrawler
  {
    /// <summary>
    ///   Determines if the item should be included in the index.
    /// </summary>
    /// <param name=\"item\"></param>
    /// <returns></returns>
    protected override bool IsMatch(Item item)
    {
      if (item[\"include in search results\"] != \"1\")
      {
        return false;
      }

      return base.IsMatch(item);
    }
  }
}
有趣的是,如果我使用Index Viewer应用程序重建索引,则一切正常。未选中“包括在搜索结果中”复选框的项目将不包括在搜索索引中。 但是,当我在Sitecore控制面板应用程序中使用搜索索引重建器时,或者当IndexingManager自动更新搜索索引时,所有项目都会被包括在内,无论其“包括在搜索结果中”复选框的状态如何。 我还在自定义搜寻器类中设置了多个断点,当我使用内置索引器重建搜索索引时,应用程序从不命中任何一个。当我使用Index Viewer时,它确实会达到我设置的所有断点。 如何获得Sitecore的内置索引编制过程来尊重我的“包含在搜索结果中”复选框?     

解决方法

        昨天我与Alex Shyba进行了交谈,我们能够弄清楚发生了什么。我的配置存在一些问题,导致一切无法正常工作: 正如Seth所指出的,Sitecore中有两个不同的搜索API。我的配置文件同时使用了它们。要使用较新的API,只需设置
sitecore/search/configuration
部分(除了我在OP中发布的内容外,我还在
sitecore/indexes
和ѭ4adding中添加了索引,这是不正确的)。 我应该覆盖
AddItem()
,而不是覆盖
IsMatch()
。由于Lucene的工作方式,您无法就地更新文档。相反,您必须先删除它,然后添加更新的版本。 当
Sitecore.Search.Crawlers.DatabaseCrawler.UpdateItem()
运行时,它将检查
IsMatch()
以查看是否应删除并重新添加该项目。如果
IsMatch()
返回false,则即使该项目本来不应该从索引中删除也不会被删除。 通过覆盖ѭ6,我可以指示搜寻器是否应在删除现有文档后将其添加到索引中。这是更新后的类的样子: 〜\\ Lib \\ Search \\ Indexing \\ CustomCrawler.cs:
using Sitecore.Data.Items;
using Sitecore.Search;
using Sitecore.Search.Crawlers;

namespace MyProject.Lib.Search.Indexing
{
  public class CustomCrawler : DatabaseCrawler
  {
    protected override void AddItem(Item item,IndexUpdateContext context)
    {
      if (item[\"include in search results\"] == \"1\")
      {
        base.AddItem(item,context);
      }
    }
  }
}
Alex还指出,我的某些可伸缩性设置不正确。特别:
InstanceName
设置为空,这可能在临时(云)实例上引起问题,在这些实例上计算机名称可能在两次执行之间更改。我们在每个实例上将此设置更改为具有恒定且不同的值(例如
CMS
CD
)。
Indexing.ServerSpecificProperties
设置必须为
true
,以便每个实例保留其上一次更新其搜索索引的时间的记录。
EnableEventQueues
设置必须为
true
,以防止搜索索引编制和高速缓存刷新过程之间的争用情况。 开发时,应将
Indexing.UpdateInterval
设置为相对较小的值(例如
00:00:15
)。这不适用于生产环境,但是可以减少对搜索索引问题进行故障排除时的等待时间。 确保为每个Web数据库(包括远程发布目标)打开了历史记录引擎:
<database id=\"production\">
  <Engines.HistoryEngine.Storage>
    <obj type=\"Sitecore.Data.$(database).$(database)HistoryStorage,Sitecore.Kernel\">
      <param connectionStringName=\"$(id)\" />
      <EntryLifeTime>30.00:00:00</EntryLifeTime>
    </obj>
  </Engines.HistoryEngine.Storage>
  <Engines.HistoryEngine.SaveDotNetCallStack>false</Engines.HistoryEngine.SaveDotNetCallStack>
</database>
要手动重建CD实例上的搜索索引,由于无法访问Sitecore后端,我还安装了RebuildDatabaseCrawlers.aspx(来自本文)。     ,我想我已经找到了解决方案。 这是来自ѭ22的有趣片段,由控制面板应用程序中的搜索索引重建器调用:
for (int i = 0; i < database.Indexes.Count; i++)
{
  database.Indexes[i].Rebuild(database);
  ...
}
database.Indexes
包含一组of25ѭ,它们不使用数据库搜寻器来重建索引! 换句话说,内置的搜索索引器在重建完全忽略ѭ26中的搜索配置设置的搜索索引时会使用完全不同的类。 要解决此问题,我更改了以下文件: 〜\\ App_Config \\ Include \\ Search Indexes \\ Website.config:
<indexes>
  <index id=\"website\" ... type=\"MyProject.Lib.Search.Indexing.CustomIndex,MyProject\">
    ...
  </index>

  ...
</indexes>
〜\\ Lib \\ Search \\ Indexing \\ CustomIndex.cs:
using Sitecore.Data;
using Sitecore.Data.Indexing;
using Sitecore.Diagnostics;

namespace MyProject.Lib.Search.Indexing
{
  public class CustomIndex : Index
  {
    public CustomIndex(string name)
      : base(name)
    {
    }

    public override void Rebuild(Database database)
    {
      Sitecore.Search.Index index = Sitecore.Search.SearchManager.GetIndex(Name);
      if (index != null)
      {
        index.Rebuild();
      }
    }
  }
}
此方法的唯一警告是它将为每个数据库重建索引,而不仅仅是为选定数据库重建索引(我想这就是为什么Sitecore有两种完全独立的重建索引方法)的原因。     ,        Sitecore 6.2使用旧的和较新的搜索API,因此我相信索引的构建方式有所不同。 CMS 6.5(即将发布)仅使用较新的api-例如Sitecore.Search     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-