C# Sitecore 7搜索索引问题
我想限制Sitecore 7中的搜索索引只扫描内容树的一个节点 当前结构如下所示:C# Sitecore 7搜索索引问题,c#,.net,sitecore,lucene.net,sitecore7,C#,.net,Sitecore,Lucene.net,Sitecore7,我想限制Sitecore 7中的搜索索引只扫描内容树的一个节点 当前结构如下所示: 站点核心 内容 基本节点 $Company节点 索引正在索引BaseNode和$Company Node,但我只希望它索引$Company Node 我已经更新了sitecore.ContentSearch.config、sitecoretentsearch.Lucene.DefaultIndexConfiguration.config、sitecore.ContentSearch.Lucene.In
- 站点核心
- 内容
- 基本节点
- $Company节点
- 内容
BaseNode
和$Company Node
,但我只希望它索引$Company Node
我已经更新了sitecore.ContentSearch.config
、sitecoretentsearch.Lucene.DefaultIndexConfiguration.config
、sitecore.ContentSearch.Lucene.Index.Master
和sitecore.ContentSearch.LuceneIndex.Web.config
中的默认路径。当我将
元素更新为指向/sitecore/content/$CompanyNode
时,我在尝试重建索引时遇到以下异常
我需要做些什么来限制Lucene只索引一些项目,而不是所有项目
Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Sitecore.Configuration.Factory.AssignProperties(Object obj, Object[] properties)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
at Sitecore.Search.SearchManager.get_SearchConfiguration()
at Sitecore.Shell.Applications.Search.RebuildSearchIndex.RebuildSearchIndexForm.GetIndexes()
at Sitecore.Shell.Applications.Search.RebuildSearchIndex.RebuildSearchIndexForm.BuildIndexes()
Nested Exception
Exception: System.InvalidOperationException
Message: Root item is not defined
Source: Sitecore.Kernel
at Sitecore.Diagnostics.Assert.IsNotNull(Object value, String message)
at Sitecore.Search.Crawlers.DatabaseCrawler.Initialize(Index index)
at Sitecore.Search.Index.AddCrawler(ICrawler crawler)
我相信您正在试图修改主Lucene索引文件。我相信这最终会破坏很多东西,我建议您创建一个新的Lucene索引文件 如果要创建新索引:请将此索引放置在App\u Config/Include文件夹中 Sitecore.ContentSearch.Lucene.Index.Alexander.config 在该配置中,您将爬虫设置为搜索节点
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<configuration type="Sitecore.ContentSearch.LuceneProvider.LuceneSearchConfiguration, Sitecore.ContentSearch.LuceneProvider">
<indexes hint="list:AddIndex">
<index id="alexander_search_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
<!-- This initializes index property store. Id has to be set to the index id -->
<param desc="propertyStore" ref="contentSearch/databasePropertyStore" param1="$(id)" />
<strategies hint="list:AddStrategy">
<!-- NOTE: order of these is controls the execution order -->
<strategy ref="contentSearch/indexUpdateStrategies/onPublishEndAsync" />
</strategies>
<commitPolicy hint="raw:SetCommitPolicy">
<policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
</commitPolicy>
<commitPolicyExecutor hint="raw:SetCommitPolicyExecutor">
<policyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch" />
</commitPolicyExecutor>
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.LuceneProvider.Crawlers.DefaultCrawler, Sitecore.ContentSearch.LuceneProvider">
<Database>web</Database>
<Root>/sitecore/content/$Company Node</Root>
</crawler>
</locations>
</index>
</indexes>
</configuration>
</contentSearch>
</sitecore>
</configuration>
$(id)
$(id)
网状物
/sitecore/content/$Company节点
上述索引将索引该节点下的所有内容。
在C#中,您可以轻松地将其称为
ContentSearchManager.GetIndex("alexander_search_index").Rebuild();
using (var searchContext = ContentSearchManager.GetIndex("alexander_search_index").CreateSearchContext())
{
var result = searchContext.GetQueryable<SearchResultItem>()
.Where(//Put Query Here);
//do ForEach if you return multiple and so on.
if (result != null)
Context.Item = result.GetItem();
}
ContentSearchManager.GetIndex(“alexander_search_index”).Rebuild();
使用(var searchContext=ContentSearchManager.GetIndex(“alexander\u search\u index”).CreateSearchContext())
{
var result=searchContext.GetQueryable()
.Where(//将查询放在这里);
//如果返回多个,则执行ForEach,以此类推。
如果(结果!=null)
Context.Item=result.GetItem();
}
您还可以通过进入Sitecore->Control Panel->Indexing->Indexing Manager来重建索引并验证它们是否正常工作。这样做之后,您应该会看到索引
另一编辑:
您还可以在内容树中的该项目下执行C#搜索,并仅使用web数据库
Item bucketItem = //Code to get $Company Node as a Sitecore Item
//Probably Sitecore.Context.Database.GetItem("Guid for $Company Node")
using (var searchContext = ContentSearchManager.GetIndex(bucketItem as IIndexable).CreateSearchContext())
{
try
{
var result = searchContext.GetQueryable<SearchResultItem>().Where(x => x.Name == itemName).FirstOrDefault();
if (result != null)
Context.Item = result.GetItem();
}
catch (Exception)
{
//Do something
}
}
Item bucketItem=//将$Company节点作为Sitecore项获取的代码
//可能是Sitecore.Context.Database.GetItem(“用于$Company节点的Guid”)
使用(var searchContext=ContentSearchManager.GetIndex(bucketItem作为IIndexable.CreateSearchContext())
{
尝试
{
var result=searchContext.GetQueryable()。其中(x=>x.Name==itemName.FirstOrDefault();
如果(结果!=null)
Context.Item=result.GetItem();
}
捕获(例外)
{
//做点什么
}
}
请标记正确答案或提供更多信息。:)嗨,安德鲁,我正在与另一个资源合作收集更多信息。我想我们会实施你的解决方案,但现在这个任务被卡在了“等待”任务列表上。