对我有用的是:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<databases>
<database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
<Engines.HistoryEngine.Storage>
<obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
<param connectionStringName="$(id)" />
<EntryLifeTime>30.00:00:00</EntryLifeTime>
</obj>
</Engines.HistoryEngine.Storage>
<Engines.HistoryEngine.SaveDotNetCallStack>false</Engines.HistoryEngine.SaveDotNetCallStack>
</database>
</databases>
<search>
<configuration>
<indexes>
<index id="newsArticles" type="Sitecore.Search.Index, Sitecore.Kernel">
<param desc="name">$(id)</param>
<param desc="folder">newsArticle</param>
<Analyzer ref="search/analyzer" />
<locations hint="list:AddCrawler">
<master type="Sitecore.SharedSource.SearchCrawler.Crawlers.AdvancedDatabaseCrawler,Sitecore.SharedSource.SearchCrawler">
<Database>master</Database>
<Root>/sitecore/content/Data</Root>
<IndexAllFields>true</IndexAllFields>
<MonitorChanges>true</MonitorChanges>
<include hint="list:IncludeTemplate">
<News>{EF11A8D0-D373-4A4B-90BA-16984D277612}</News>
</include>
现在我已经包含了我需要搜索索引来搜索的模板 ID。当我构建时,我可以看到包含此特定模板 ID 的项目存在。
现在搜索:
try
{
List<Item> items = new List<Item>();
Sitecore.Search.Index indx = SearchManager.GetIndex("newsArticles");
using (IndexSearchContext searchContext = indx.CreateSearchContext())
{
var db = Sitecore.Context.Database;
CombinedQuery query = new CombinedQuery();
QueryBase catQuery = new FieldQuery("category", GuidsToSearchFor); //FieldName, FieldValue.
SearchHits results = searchContext.Search(catQuery); //Searching the content items by fields.
SearchResultCollection result = results.FetchResults(0, numOfArticles);
RetrieveUrlListings(myItems, db, result, true);
}
}
您的结果将包含索引查看器中存在的项目列表。
希望这可以帮助!查看此链接了解更多信息。