使用 NGram 自动完成 Sitecore 和 Solr 搜索
Sitecore & Solr search auto-complete using NGram
我找到了 Sitecore NGram。如何使用 NGram 为 sitecore 7 设置自动完成。
我试图重复它,但我对某些部分感到困惑:
永远不会调用的 IComputedIndexField 实现。我已经在 Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config 中设置了它,如下所示:
<fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap,
Sitecore.ContentSearch.SolrProvider">
<typeMatches>
<typeMatch typeName="autoComplete" type="System.String" fieldNameFormat="{0}_ac" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration,
Sitecore.ContentSearch.SolrProvider" />
</typeMatches>
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="titlesearch" returnType="autoComplete">MyLib.AutoCompleteTitle, MyLib</field>
</fieldNames>
</fieldMap>
只读了一个与示例不同的属性值:
return item.Fields["Title"].Value;
2 添加配置到 schema.xml - fieldType 名称="auto_complete" 代码:
<fieldType name="auto_complete" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="30" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
3 重新启动 Solr 并重建 sitecore 索引
4 我很困惑 属性 我应该用于搜索的名称(看起来像是 IComputedIndexField 的设置)
using (var context = ContentSearchManager.GetIndex(_searchIndexName).CreateSearchContext())
{
var dataQuery = context.GetQueryable<SearchResultItem>().Where(i =>i["titlesearch_ac"] == searchString).Take(20);
return dataQuery;
}
没有任何错误,但我无法获得自动完成结果....
仔细检查您是否在正确的位置声明了计算字段 - 它应该添加到顶部 raw:AddcomputedIndexField
的部分。
<fields hint="raw:AddComputedIndexField">
<field fieldName="_content" returnType="string">Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor,Sitecore.ContentSearch</field>
属性 名称 ("titlesearch_ac")
应该是您的字段在索引中的名称。
附带说明 - 您只需使用 Solr 即可实现自动完成。更多信息在这里:
http://www.norconex.com/serving-autocomplete-suggestions-fast/
我找到了 Sitecore NGram。如何使用 NGram 为 sitecore 7 设置自动完成。 我试图重复它,但我对某些部分感到困惑:
永远不会调用的 IComputedIndexField 实现。我已经在 Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config 中设置了它,如下所示:
<fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap,
Sitecore.ContentSearch.SolrProvider">
<typeMatches>
<typeMatch typeName="autoComplete" type="System.String" fieldNameFormat="{0}_ac" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration,
Sitecore.ContentSearch.SolrProvider" />
</typeMatches>
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="titlesearch" returnType="autoComplete">MyLib.AutoCompleteTitle, MyLib</field>
</fieldNames>
</fieldMap>
只读了一个与示例不同的属性值:
return item.Fields["Title"].Value;
2 添加配置到 schema.xml - fieldType 名称="auto_complete" 代码:
<fieldType name="auto_complete" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="30" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
3 重新启动 Solr 并重建 sitecore 索引
4 我很困惑 属性 我应该用于搜索的名称(看起来像是 IComputedIndexField 的设置)
using (var context = ContentSearchManager.GetIndex(_searchIndexName).CreateSearchContext())
{
var dataQuery = context.GetQueryable<SearchResultItem>().Where(i =>i["titlesearch_ac"] == searchString).Take(20);
return dataQuery;
}
没有任何错误,但我无法获得自动完成结果....
仔细检查您是否在正确的位置声明了计算字段 - 它应该添加到顶部 raw:AddcomputedIndexField
的部分。
<fields hint="raw:AddComputedIndexField">
<field fieldName="_content" returnType="string">Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor,Sitecore.ContentSearch</field>
属性 名称 ("titlesearch_ac")
应该是您的字段在索引中的名称。
附带说明 - 您只需使用 Solr 即可实现自动完成。更多信息在这里:
http://www.norconex.com/serving-autocomplete-suggestions-fast/