.netsearch-engineumbraco7examine

Umbraco Examine Search query null value


I am trying to fix my search engine. The problem is that when I search for my existing blog item, it always says

Did not match in any document

What ever I search for, it always give me that error message.

Is there any way to fix this or does my code have a problem?

@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>
}

here's my Setting

<?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>

ExamineIndex.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>

Solution

  • A couple of things to check, firstly, check that your index is actually populating correctly. You can download the tool Luke from here (requires Java). This handy tool lets you view the contents of your index.

    If you fire up Luke and point it at the index folder in /App_Data/TEMP/ExamineIndexes/MySiteSearcher it should show you how many items are in the indexer and what fields they contain. Check that a) there are documents in the index, and b) that the index is indexing the fields that you are searching on.

    If everything looks OK, it could be the syntax of the search. Looking at your code, you're going to end up with the search requiring the nodeName to match the search term, with an optional match in the bodyText (the default search operator is AND, which means the first item in the query MUST always match). If you want to match in either, you'll need to set the deafult operator of the search to be or, using the following code:

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