Umbraco检查搜索索引

时间:2014-09-24 16:10:02

标签: c# search umbraco umbraco7 examine

我已经在umbraco 7中配置了检查索引,它索引了一些页面而不是全部,例如我有两个相同文档类型的页面,其中一个是搜索中的索引,但是富文本编辑器中的图像上方文本内容的一部分那个图像内容也不是索引? 无法弄清楚错误,这是我的检查配置

ExamineIndex.config:

<ExamineLuceneIndexSets>
  <!-- The internal index set used by Umbraco back-office - DO NOT REMOVE -->
  <IndexSet SetName="InternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Internal/"/>

  <!-- The internal index set used by Umbraco back-office for indexing members - DO NOT REMOVE -->
  <IndexSet SetName="InternalMemberIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/InternalMember/">
    <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName"/>
      <add Name="updateDate" />
      <add Name="writerName" />
      <add Name="loginName" />
      <add Name="email" />
      <add Name="nodeTypeAlias" />
    </IndexAttributeFields>
  </IndexSet>

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


  <IndexSet SetName="MySearch" IndexPath="~/App_Data/ExamineIndexes/MySearch/">
    <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName"/>
      <add Name="updateDate" />
      <add Name="writerName" />
      <add Name="nodeTypeAlias" />
    </IndexAttributeFields>
    <IndexUserFields>

      <add Name="pageBodyText"/>
      <add Name="bodyText"/>
      <add Name="title"/>
      <add Name="summary"/>
      <add Name="projectTitle"/>
      <add Name="projectDescription"/>     
      <add Name="rightBoxContent"/>
      <add Name="leftBoxContent"/>

      <!--<add Name="siteName"/>-->
    </IndexUserFields>
    <IncludeNodeTypes>
      <!--<add Name="umbHomePage" />-->
      <add Name="umbHomePage" />
      <add Name="Page" />
      <add Name="NewsItem" />
      <add Name="Project" />
      <add Name="Service" />  
      <add Name="Client" />


      <!--<add Name="PageWithPlugin" />-->
    <!--NewsItem,Project,Service,Page,umbHomePage,Client-->
    </IncludeNodeTypes>
  </IndexSet>

  <!--<IndexSet SetName="MySearchIndexer" IndexPath="~/App_Data/TEMP/ExamineIndexes/MySearchIndexer/" />-->

</ExamineLuceneIndexSets>

ExamineSettings.config:

<Examine>
  <ExamineIndexProviders>
    <providers>
      <add name="InternalIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
           supportUnpublished="true"
           supportProtected="true"
           analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>

      <add name="InternalMemberIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine"
           supportUnpublished="true"
           supportProtected="true"
           analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>

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

      <add name="MySearchIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
      supportUnpublished="false"
      supportProtected="true"
      interval="10"
      analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
      indexSet="MySearch"/>


      <!--<add name="MySearchSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
      analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="MySearch" enableLeadingWildcards="true"/>-->



    </providers>
  </ExamineIndexProviders>

  <ExamineSearchProviders defaultProvider="ExternalSearcher">
    <providers>
      <add name="InternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
           analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>

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

      <add name="InternalMemberSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
           analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" enableLeadingWildcard="true"/>

      <add name="MySearchSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
      analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="MySearch" enableLeadingWildcards="true" />

    </providers>
  </ExamineSearchProviders>

</Examine>

宏代码:

@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Examine.LuceneEngine.SearchCriteria

@{
    if (!string.IsNullOrEmpty(Request.QueryString["search"]))
    {
        var q = Request.QueryString["search"];
        var Searcher = Examine.ExamineManager.Instance.SearchProviderCollection["MySearchSearcher"];

        var searchResults = Searcher.Search(q, true).OrderByDescending(x => x.Score).TakeWhile(x => x.Score > 0.05f);
        bool isRecordFound = false;
    <ul>
        @foreach (var item in searchResults)
        {
            IPublishedContent node = Umbraco.Content(item.Fields["id"]);        
            <li>
                <a href="@node.Url">
                    @node.Name
                </a>
            </li>
            isRecordFound = true;

        }
    </ul>       

        if (!isRecordFound)
        {
    <div>
        <h1>No Record Found</h1>
    </div>
        }

    }
 }

1 个答案:

答案 0 :(得分:0)

if (!string.IsNullOrEmpty(Request.QueryString["search"]))

我在这里遇到了同样的问题。所以这就是我做错了什么。现在,你已经&#34;请求&#34; a&#34; QueryString&#34;命名&#34;搜索&#34;。你没有那个查询字符串。另一方面,您需要创建它。

您现在拥有的只是名为string的{​​{1}},而不是"search",因此QueryString会返回值Request.Querystring["search"]

我在控制器中使用MVC并且我的逻辑最终告诉我,我应该做的是搜索我的模型以获取名为&#34; search&#34;的变量。基本上我用

替换原来的if
null

这是告诉控制器去找到名为&#34;搜索&#34;的变量。在我的&#34;模型&#34;和&#34;如果&#34; !string.IsNullOrEmpty,然后在下面执行我的代码。

我还没有阅读你的整个代码,正如我所说的那样我在使用MVC时,所以根据需要将其调整为你自己的代码。