Umbraco检查搜索查询空值



我正在尝试修复我的搜索引擎。问题是,当我搜索我现有的博客项目时,它总是说

Did not match in any document

无论我搜索什么,它总是给我错误信息。

有什么方法可以解决这个问题吗?或者我的代码有问题吗?

@using Examine.LuceneEngine.SearchCriteria
@inherits Umbraco.Web.Macros.PartialViewMacroPage
string searchTerm = Request.QueryString["search"];
var searcher = ExamineManager.Instance.SearchProviderCollection["MySiteSearcher"];
var searchCriteria = searcher.CreateSearchCriteria();
var query = searchCriteria.Field("nodeName", searchTerm).Or().Field("bodyText", searchTerm).Compile();
var searchResults = searcher.Search(query);
@if (searchResults.Any()){
    <ul class="search-results">
        @foreach (var result in searchResults)
        {
            IPublishedContent node = Umbraco.Content(result.Fields["id"]);
            <li>
                <a href="@umbraco.library.NiceUrl(result.Id)">
                    @if (result.Fields.ContainsKey("nodeName")) {
                        @node.GetPropertyValue("blogItemTitle")
                    }
                </a>
                <p>@result.Fields["blogbodyText"]</p>
            </li>
        }
    </ul>
} else {
    <p class="error-result">
        Your search
        @if (!String.IsNullOrEmpty(searchTerm))
        {
            <strong><text>'@searchTerm'</text></strong>
        }
        did not match any documents.
    </p>
}

这是我的设置

<?xml version="1.0"?>
<!-- 
Umbraco examine is an extensible indexer and search engine.
This configuration file can be extended to add your own search/index providers.
Index sets can be defined in the ExamineIndex.config if you're using the standard provider model.
More information and documentation can be found on CodePlex: http://umbracoexamine.codeplex.com
-->
<Examine>
  <ExamineIndexProviders>
    <providers>
      <add name="InternalIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
           supportUnpublished="true"
           supportProtected="true"
           interval="10"
           analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
      <add name="InternalMemberIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine"
           supportUnpublished="true"
           supportProtected="true"
           interval="10"
           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="MySiteIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine"
           supportUnpublished="false" 
           supportProtected="true" 
           interval="10" 
           analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
           enableDefaultEventHandler="true"/>
    </providers>
  </ExamineIndexProviders>
  <ExamineSearchProviders defaultProvider="ExternalSearcher">
    <providers>
      <add name="InternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
           analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
      <add name="InternalMemberSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
           analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" enableLeadingWildcard="true"/>
      <add name="ExternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" />      
      <add name="MySiteSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" 
           analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
           enableLeadingWildcards="true"
           indexSet="MySiteIndexSet"/>
    </providers>
  </ExamineSearchProviders>
</Examine>

ExaminerIndex.config

<?xml version="1.0"?>
<!-- 
Umbraco examine is an extensible indexer and search engine.
This configuration file can be extended to create your own index sets.
Index/Search providers can be defined in the UmbracoSettings.config
More information and documentation can be found on CodePlex: http://umbracoexamine.codeplex.com
-->
<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" EnableSorting="true"/>
      <add Name="name" EnableSorting="true"/>
      <add Name="updateDate" />
      <add Name="writerName" />
      <add Name="loginName" />
      <add Name="email" />
      <add Name="bodyText"/>
      <add Name="blogItemTitle" />
      <add Name="nodeTypeAlias" />
    </IndexAttributeFields>
    <IndexUserFields>
      <add Name="bodyText"/>
      <add Name="tags"/>
      <add Name="content"/>
      <add Name="tags" />
      <add Name="category" />
    </IndexUserFields>
    <IncludeNodeTypes>
      <add Name="article" />
      <add Name="note" />
      <add Name="KnowledgebaseItem" />
    </IncludeNodeTypes>
  </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="MySiteIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/MySiteSearcher/" />
</ExamineLuceneIndexSets>

需要检查的几件事,首先,检查索引是否实际正确填充。您可以从这里下载工具Luke(需要Java(。这个方便的工具可以让您查看索引的内容。

如果你启动Luke并将其指向/App_Data/TEMP/EExamineIndexes/MySiteSearcher中的索引文件夹,它应该会显示索引器中有多少项以及它们包含的字段。检查a(索引中是否有文档,b(索引是否正在为您正在搜索的字段编制索引。

如果一切看起来都正常,那可能是搜索的语法问题。查看您的代码,您最终会发现搜索需要nodeName与搜索项匹配,bodyText中有一个可选匹配项(默认搜索运算符为AND,这意味着查询中的第一个项必须始终匹配(。如果你想在其中匹配,你需要使用以下代码将搜索的deafult运算符设置为或:

var searchCriteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);

相关内容

  • 没有找到相关文章

最新更新