Umbraco examine search media folder 中的pdf文件

可以参考的文章

http://sleslie.me/2015/selecting-media-using-razor-slow-performance-examine-to-the-rescue/

 

http://stackoverflow.com/questions/21710897/umbraco-fulltextsearch-including-search-of-media-section

我自己在项目中实现了对media folder中pdf文件的search功能,使用的依然是Umbraco中的 ExternalSearcher, Index 也是 UmbracoContentIndexer

ExamineSettings.config 如下:

<Examine>
  <ExamineIndexProviders>
    <providers>
  
        <!-- default external indexer, which excludes protected and unpublished pages-->
        <add name="ExternalIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"/>

    </providers>
  </ExamineIndexProviders>

  <ExamineSearchProviders defaultProvider="ExternalSearcher">
    <providers>
           <add name="ExternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" />

    </providers>
  </ExamineSearchProviders>

</Examine>

ExamineIndex.config

<ExamineLuceneIndexSets>
 
    
  <!-- Default Indexset for external searches, this indexes all fields on all types of nodes-->
  <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/{machinename}/External/">

  </IndexSet>
</ExamineLuceneIndexSets>

在代码层面是这样写的:

 internal const string SearcherGeneral = "ExternalSearcher";

  var provider = Examine.ExamineManager.Instance.SearchProviderCollection[SearcherGeneral];
   
var searchCriteria = provider.CreateSearchCriteria(UmbracoExamine.IndexTypes.Media);         
  var filter = searchCriteria.Field("umbracoExtension","pdf").Compile();
   var results = provider.Search(filter);

 

posted on 2017-05-08 10:50  新西兰程序员  阅读(174)  评论(0编辑  收藏  举报