我有一个自定义搜索索引,我想索引pdf文件内容。主索引似乎正在索引pdf文件,而sitecore的内置搜索功能可以很好地搜索pdf文件。我似乎在尝试索引PDF字段然后搜索其内容时遇到了问题。
在我的indexConfiguration中,我按名称添加字段
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="publication pdf" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
...
</fieldNames>
我的结果项目包含索引字段定义
[IndexField("publication pdf")]
public virtual string PDF { get; set; }
然而,当我创建搜索上下文并尝试在PDF中找到某些内容时,我得到0结果。
var query = context.GetQueryable<ResultItem>();
query = query.Where(p => p.PDF.Equals(SearchString));
非常感谢任何帮助。
答案 0 :(得分:4)
我猜测你的出版物PDF&#34; field是媒体库项目的某种引用字段。事实上,PDF的内容并不是您当前项目的内容。这意味着您需要编写一个自定义计算字段,该字段将提取该媒体库项并对其内容进行爬网。
如果要抓取媒体项的内容,可能需要使用某个反射器来检查Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor
类的代码。 Sitecore使用它来获取媒体项目的内容,如Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config
中所定义:
<field fieldName="_content" type="Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor,Sitecore.ContentSearch">
<mediaIndexing ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/mediaIndexing"/>
</field>
您需要首先获取媒体项,然后使用从此类复制的代码来获取PDF的内容。
<强> BUT 强>
是的,总有but
。如果媒体库项目已更改且您的项目未更改,则您的项目不会自动重新编制索引。因此,如果您计划更改pdfs(上传新项目并选择它应该没问题),您需要考虑自定义代码,该代码将执行对您的pdf文件的引用的项目的重建索引,或者手动重新索引您的项目。