lucene - Sitecore 自定义索引配置语言

标签 lucene sitecore sitecore8.1

我在 Sitecore 8.1 环境中创建了一个自定义 Lucene 索引,如下所示:

<?xml version="1.0"?>
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="Products_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
            <param desc="name">$(id)</param>
            <param desc="folder">$(id)</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
            <configuration ref="contentSearch/indexConfigurations/ProductIndexConfiguration" />
            <strategies hint="list:AddStrategy">
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
            </strategies>
            <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
              <policies hint="list:AddCommitPolicy">
                <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
              </policies>
            </commitPolicyExecutor>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>master</Database>
                <Root>/sitecore/content/General/Product Repository</Root>
              </crawler>
            </locations>
            <enableItemLanguageFallback>false</enableItemLanguageFallback>
            <enableFieldLanguageFallback>false</enableFieldLanguageFallback>
          </index>
        </indexes>
      </configuration>

      <indexConfigurations>
        <ProductIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
          <initializeOnAdd>true</initializeOnAdd>
          <analyzer ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/analyzer" />
          <documentBuilderType>Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder, Sitecore.ContentSearch.LuceneProvider</documentBuilderType>
          <fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
            <fieldNames hint="raw:AddFieldByFieldName">
              <field fieldName="_uniqueid" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>
              <field fieldName="key" storageType="YES" indexType="UNTOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>
            </fieldNames>
          </fieldMap>
          <documentOptions type="Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilderOptions, Sitecore.ContentSearch.LuceneProvider">
            <indexAllFields>true</indexAllFields>
            <include hint="list:AddIncludedTemplate">
              <Product>{843B9598-318D-4AFA-B8C8-07E3DF5C6738}</Product>
            </include>
          </documentOptions>
          <fieldReaders ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/fieldReaders"/>
          <indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexFieldStorageValueFormatter"/>
          <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexDocumentPropertyMapper"/>
        </ProductIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

实际上是一个指向根的非常简单的索引,包括一个模板并存储一个字段。一切正常。但我需要一些额外的东西:

  • 将索引中的条目限制为最新版本
  • 将索引中的条目限制为一种语言(英语)

我知道这也可以在查询中轻松触发,但我想让我的索引更小,以便它们(重新)构建得更快。

第一个可以通过索引 web 而不是 master 来解决,但在这种情况下我实际上还想要未发布的。我很确定为此我需要一个自定义爬虫。

第二个(限制语言)实际上更重要,因为我在其他索引中也需要它。简单的答案可能也是使用自定义爬虫,但我希望有一种方法可以在没有自定义代码的情况下进行配置。是否可以将自定义索引配置为仅包含一组已定义的语言(一种或多种)而不是全部?

最佳答案

经过一些研究,我得出结论,要满足所有要求,自定义爬虫是唯一的解决方案。博文代码:http://ggullentops.blogspot.be/2016/10/custom-sitecore-index-crawler.html

主要原因是我们真的必须能够为每个索引设置它——这在过滤器方法中是不可能的。此外,当我们添加新版本时,必须从索引中删除以前的版本——如果没有爬虫也是不可能的……

有很多代码,所以我不会在这里全部复制,但我们必须覆盖 SitecoreItemCrawler 的 DoAdd 和 DoUpdate 方法,对于语言,我们还必须对 Update 方法进行一个小的覆盖。

关于lucene - Sitecore 自定义索引配置语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39350744/

相关文章:

powershell - Sitecore powershell 搜索所有包含该关键字的项目

sitecore - 借助 Sitecore,如何使用 cshtml 文件和模型来呈现自定义字段?

java - Lucene:单个术语中的多个单词

elasticsearch - 如何在 Elasticsearch 中建立索引和 bool 查询,以在某些字段上执行前缀匹配并在其他字段上执行精确短语匹配?

solr - 为什么必须在长查询字符串中的每个数字之间添加 OR?

c# - 具有多个来源的 Sitecore 下拉列表

solr - 限制用户访问的 Lucene 索引

c# - SearchManager 与 ContentSearchManager?

sitecore - 如何将 Sitecore 从 7.5 升级到 8.1 Update 3?

youtube - Sitecore 和 YouTube 集成模块 - 安装过程中的错误