2015-08-14 28 views
1

我找到了Sitecore NGram。如何設置自動完成與NGRAM爲sitecore 7. 我想重複它,但我對某些部分感到困惑:Sitecore&Solr搜索自動完成使用NGram

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 - 字段類型名稱= 「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;     
} 

它是沒有任何錯誤,但我不能讓自動完成結果....

回答

1

仔細檢查您是否在正確的位置聲明瞭您的計算字段 - 應將其添加到頂部爲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/

+0

是的,我在你的答案之前做過。任何方式感謝你。 –

+0

沒問題,祝你好運。 –