1
votes

I have found Sitecore NGram. how to set up auto complete with NGram for sitecore 7. I am trying to repeat it but I am confused about some parts:

IComputedIndexField implementation that is never calls. I have setup it in Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config like here:

<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>

only one different with example is read property value:

 return item.Fields["Title"].Value; 

2 Added configuration to schema.xml - fieldType name="auto_complete" Code:

<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 Restarted Solr and Rebuild sitecore index

4 I am confused that property name I should use for search (looks like setting for IComputedIndexField)

using (var context = ContentSearchManager.GetIndex(_searchIndexName).CreateSearchContext())
{
    var dataQuery = context.GetQueryable<SearchResultItem>().Where(i =>i["titlesearch_ac"] == searchString).Take(20);
    return dataQuery;                
}

it is no any error, but I can't get auto-complete results....

1

1 Answers

1
votes

Double check you are declaring your computed field in the right place - it should be added in the section that has raw:AddcomputedIndexField at the top.

 <fields hint="raw:AddComputedIndexField">
      <field fieldName="_content"  returnType="string">Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor,Sitecore.ContentSearch</field>

The property name ("titlesearch_ac") should be the name of your field in the index.

Just a side note- you can achieve auto complete just using Solr. More info here:

http://www.norconex.com/serving-autocomplete-suggestions-fast/