1

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>
Am_I_Helpful
  • 17,636
  • 7
  • 44
  • 68
kenshin
  • 29
  • 5
  • Instead of `Lucene.Net.Analysis.Standard.StandardAnalyzer` try using `Lucene.Net.Analysis.WhitespaceAnalyzer` – Davor Zlotrg Jul 24 '15 at 07:18
  • @DZL thanks, but i does not change anything. i think the index in /App_Data/TEMP/ExamineIndexes/MySiteSearcher has no value i'm trying to fix that have you any idea? – kenshin Jul 24 '15 at 08:18
  • Try calling `ExamineManager.Instance.IndexProviderCollection["MySiteSearcher"].RebuildIndex()` – Davor Zlotrg Jul 24 '15 at 09:30
  • it gives me this error, Error loading Partial View script (file: ~/Views/MacroPartials/Search Results.cshtml) .. – kenshin Jul 24 '15 at 09:54
  • that is your problem, try wrapping `.RebuildIndex()` around try catch and see what the exception is. – Davor Zlotrg Jul 24 '15 at 09:56
  • how do i wrap .RebuildIndex()? sorry i am new in umbraco .. – kenshin Jul 24 '15 at 10:04
  • write `try { ExamineManager.Instance.IndexProviderCollection["MySiteSearcher"].RebuildIndex(‌​); } catch(Exception ex) { }` and put a breakpoint inside catch to see what the exception is. – Davor Zlotrg Jul 24 '15 at 10:07
  • @DZL Hi sorry again..i can't figure out to make your code work maybe is there a sample site or article? .. is there code need to insert inside catch?? and where should i placed that whole code? thanks very much! :) – kenshin Jul 24 '15 at 11:40
  • @DZL sorry done with try and catch. Yes i tried it and i get this error http://screencast.com/t/Lng4TN5z6I what does it mean? thanks in advance – kenshin Jul 24 '15 at 13:49
  • That means your index was not found. Try installing https://our.umbraco.org/projects/backoffice-extensions/examine-inspector/ and see if that helps – Davor Zlotrg Jul 24 '15 at 13:58
  • @DZL Hi i used luke toolbox to check my index examine, and it shows no fields has been created on my index http://screencast.com/t/34d7LC55p4b. how can it be not creating any fields on my index?? but the other indexes in ExamineIdexes are good. http://screencast.com/t/900ajpKKo – kenshin Jul 27 '15 at 07:53
  • Hi thanks Guy for your help :), The problem solve for my index not creating a fields "I just have to delete the index inside /App_Data/TEMP/ExamineIndexes/MySiteSearcher , then restart my IIS and browser .. thanks Godbless! – kenshin Jul 27 '15 at 10:45

1 Answers1

1

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);
Tim
  • 4,167
  • 1
  • 13
  • 21
  • Thanks for reply Tim, my Index is not populating any fields [http://screencast.com/t/34d7LC55p4b] how can i fix that? I think there's a problem in my ExamineSettings? . – kenshin Jul 24 '15 at 04:47
  • I can't see anything obviously wrong with the config. Do the other indexes in the ExamineIndexes folder have anything in? – Tim Jul 24 '15 at 12:26
  • I tried opening External Indexes and Yes it has fields http://screencast.com/t/900ajpKKo – kenshin Jul 24 '15 at 13:44
  • Hi thanks Guy for your help :), The problem was solved for my index not creating a fields "I just had to delete the index inside /App_Data/TEMP/ExamineIndexes/MySiteSearcher , then restart my IIS and browser .. thanks Godbless! – kenshin Jul 28 '15 at 03:09