我試圖設置使用Ngram進行內容搜索的自動完成功能。 這裏是我的Lucene索引: 使用NGram的Sitecore&Lucene搜索自動完成
<autocompleteSearchConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<indexAllFields>false</indexAllFields>
<initializeOnAdd>true</initializeOnAdd>
<analyzer ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/analyzer" />
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field
fieldName="page_title"
storageType="YES"
indexType="TOKENIZED"
vectorType="NO"
boost="1.5f"
nullValue="NULL"
emptyString="EMPTY"
type="System.String"
settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.NGramAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
</field>
</fieldNames>
</fieldMap>
<fields hint="raw:AddComputedIndexField">
<field fieldName="page_title" storageType="yes">Client.Website.Code.Search.AutoCompleteTitle, Client.Website</field>
</fields>
<fieldReaders ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/fieldReaders"/>
<indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexFieldStorageValueFormatter"/>
<indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexDocumentPropertyMapper"/>
<documentBuilderType>Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder, Sitecore.ContentSearch.LuceneProvider</documentBuilderType>
</autocompleteSearchConfiguration>
請注意,我現在用的是NgramAnalyzer(參考:Sitecore.ContentSearch.LuceneProvider.Analyzers)。
當我以盧克的眼光來看這個指數時,我可以看到它顯示了正確的數據。 但是,以下iQueryable不保留任何結果。
var index = ContentSearchManager.GetIndex("INDEX NAME GOES HERE");
using (var context = index.CreateSearchContext())
{
var query = context.GetQueryable<AutocompleteSearchResult>().Where(i => i.PageTitle == term)
var result = query.GetResults();
}
在http://www.ehabelgindy.com/sitecore-7-solr-search-auto-complete-using-ngram/中,作者建議不要使用.startswith()。 –
這是Solr。也許他們使==的行爲有所不同?當你使用StartsWith會發生什麼? – TheSoftwareJedi