【问题标题】:Umbraco Examine Search query null valueUmbraco 检查搜索查询空值
【发布时间】:2015-07-22 10:05:03
【问题描述】:

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

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>

检查Index.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>

【问题讨论】:

  • 代替Lucene.Net.Analysis.Standard.StandardAnalyzer 尝试使用Lucene.Net.Analysis.WhitespaceAnalyzer
  • @DZL 谢谢,但我没有改变任何东西。我认为 /App_Data/TEMP/ExamineIndexes/MySiteSearcher 中的索引没有价值我正在尝试修复,你知道吗?
  • 尝试拨打ExamineManager.Instance.IndexProviderCollection["MySiteSearcher"].RebuildIndex()
  • 它给了我这个错误,加载部分视图脚本时出错(文件:~/Views/MacroPartials/Search Results.cshtml)..
  • 那是你的问题,试着用 .RebuildIndex() 包裹 try catch 看看异常是什么。

标签: .net search-engine umbraco7 examine


【解决方案1】:

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

如果您启动 Luke 并将其指向 /App_Data/TEMP/ExamineIndexes/MySiteSearcher 中的索引文件夹,它应该会显示索引器中有多少项目以及它们包含哪些字段。检查 a) 索引中有文档,b) 索引正在索引您正在搜索的字段。

如果一切正常,则可能是搜索的语法。查看您的代码,您最终会得到要求 nodeName 与搜索词匹配的搜索,在 bodyText 中有一个可选匹配(默认搜索运算符是 AND,这意味着查询中的第一项必须始终匹配)。如果您想匹配其中任何一个,您需要将搜索的默认运算符设置为 or,使用以下代码:

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

【讨论】:

  • 感谢蒂姆的回复,我的索引没有填充任何字段 [screencast.com/t/34d7LC55p4b] 我该如何解决这个问题?我认为我的 ExamineSettings 有问题? .
  • 我看不出配置有任何明显错误。 ExamineIndexes 文件夹中的其他索引是否有任何内容?
  • 我尝试打开外部索引,是的,它有字段screencast.com/t/900ajpKKo
  • 嗨,谢谢 Guy 的帮助 :),问题已解决,因为我的索引没有创建字段“我只需要删除 /App_Data/TEMP/ExamineIndexes/MySiteSearcher 中的索引,然后重新启动我的 IIS和浏览器..感谢上帝保佑!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-16
  • 1970-01-01
相关资源
最近更新 更多