Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Scott Leslie 28 posts 143 karma points
    Aug 08, 2016 @ 15:29
    Scott Leslie
    0

    Examine MultiIndexSearcher Example

    Hi,

    Trying to get a searcher in razor using the MultiIndexSearcher provider.

    <add name="MultiIndexSearcher"
        type="Examine.LuceneEngine.Providers.MultiIndexSearcher, Examine"
        indexSets="ExternalIndexSet,CustomIndexSet" enableLeadingWildcards="true"
        />
    

    This results in zero results.

    Does anyone have an example or code snippet for using the MultiIndexSearcher as I am clearly missing something.

    Thanks

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Aug 09, 2016 @ 11:25
    Ismail Mayat
    0

    Scott,

    That looks fine to me. Can you write out the generated lucene query and then test that query on both indexes.

    Regards

    Ismail

  • Scott Leslie 28 posts 143 karma points
    Aug 10, 2016 @ 11:15
    Scott Leslie
    0

    Ismail - thanks for the reply. May have found the problem in that my query was returning nothing as the fieldnames were different . Once i tidy up my code i will post a code snippet here for others.

    Using your code from the hour course from last years UmbracoFestival - cheers

  • blackhawk 313 posts 1368 karma points
    Mar 28, 2017 @ 19:49
    blackhawk
    0

    Scott I just ran into the same issue. What did you mean when you said you field names were not the same? How did you solve this issue of getting no results with the MultiIndexSearcher?

    Thanks

  • blackhawk 313 posts 1368 karma points
    Mar 28, 2017 @ 20:03
    blackhawk
    0

    Using Umbraco 7.5.1.1. Did something recently change in Examine when it comes to multi indexing? I currently have the following setup in my ExaminSettings.config ...

    <!--Searcher for Multiple Indexes-->
      <add name="MultiIndexSearcher" type="Examine.LuceneEngine.Providers.MultiIndexSearcher, Examine" indexSets="MediaIndexSet,AlphaIndexSet" enableLeadingWildcards="true" />
    

    But no matter what, I always get 0 results displayed when using the search tool.

  • Scott Leslie 28 posts 143 karma points
    Mar 28, 2017 @ 20:58
    Scott Leslie
    0

    That will work.

    I would firstly check in Examine manager in Backoffice Devlopment section that the 2 index are upto date - rebuild them if necessary.

    What is your razor code?

    My issue was i was searching for different fields. eg Content and External Index (they had different fields) so i used a Examine Event to create a common field which combined the fields together.. ("combinedFields")

    and used that in the Examine query: e.g. examineQuery = criteria.Field("combinedFields"), searchTerm)

  • blackhawk 313 posts 1368 karma points
    Mar 28, 2017 @ 21:34
    blackhawk
    0

    Yes my 2 indexes are up-to-date. My Alphaindexer and Mediaindexer look good. I clicked the "Rebuild Index" button for both of them. On the same page, under "Seachers" I can go to AlphaSearcher and MediaSearcher, and use their search tool to search for results. But the moment I use MultiIndexSearcher, I get 0 results.

    On my ExaminIndex.config file, my indexes look like this...

      <!-- Indexset for Alpha Documents-->
      <IndexSet SetName="AlphaIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Alpha">
      <!--the standard properties-->
      <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName" />
      <add Name="updateDate" />
      <add Name="writerName" />
      <add Name="path" />
      <add Name="nodeTypeAlias" />
      <add Name="parentID" />
      </IndexAttributeFields>
      <!--the document type properties we created - use exact alias-->
      <IndexUserFields>
      <add Name="alpha summary"/>
      <add Name="alpha description"/>
      </IndexUserFields>
      <!--confine to nodes of document type Alpha-->
      <IncludeNodeTypes>
      <add Name="alpha"/>
      </IncludeNodeTypes>
      </IndexSet>
    
    
    <!--using the CogUmbracoExamineMediaIndexer-->
    <IndexSet SetName="MediaIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/MediaIndexSet">
    <IndexAttributeFields>
    <add Name="id" />
    <add Name="nodeName" />
    <add Name="updateDate" />
    <add Name="writerName" />
    <add Name="path" />
    <add Name="nodeTypeAlias" />
    <add Name="parentID" />
    </IndexAttributeFields>
    <!--the doc type properties we created - use the property alias-->
    <IndexUserFields>
    <add Name="friendlyFileName"/>
    </IndexUserFields>
    </IndexSet>
    

    You mentioned...

    I used a Examine Event to create a common field which combined the fields together.. ("combinedFields")

    Where & How can I learn to do that? How is that different from this tutorial?

    Thanks for the help!

  • Scott Leslie 28 posts 143 karma points
    Mar 28, 2017 @ 22:42
    Scott Leslie
    0

    Do you mean in the Examine Management in Developer section?

    "..But the moment I use MultiIndexSearcher, I get 0 results."

    If so this doesn't work for MultiIndexSearcher

  • blackhawk 313 posts 1368 karma points
    Mar 31, 2017 @ 20:03
    blackhawk
    0

    ahhh that's probably my problem! back to testing...

  • Scott Leslie 28 posts 143 karma points
    Mar 31, 2017 @ 20:22
    Scott Leslie
    1

    I have code i can share - will get it in a fit state over weekend.

  • blackhawk 313 posts 1368 karma points
    Apr 03, 2017 @ 21:03
    blackhawk
    0

    Just sharing code. I finally got something reeeaal basic to work

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Web.Mvc.Html
    @using Umbraco.Web
    @using UmbracoExamine
    @using Examine.SearchCriteria;
    @using Examine.LuceneEngine.SearchCriteria;
    @using Examine.LuceneEngine;
    @using Examine.LuceneEngine.Providers;
    @{
        Layout = "alpha.cshtml";
        string term = Request["Query"];
    }
    <strong>Search for:</strong> @term<br />
     <ul>
        @{
    
            //container for the searcher
            Examine.Providers.BaseSearchProvider searcher = null;
    
            //container for the results
            ISearchResults searchResults;
    
            //my desired searcher
            searcher = ExamineManager.Instance.SearchProviderCollection["MultiIndexSearcher"];
    
            if (term == null)
            {
                <p>no query set yet</p>
            }
            else
            {
    
                //create search criteria
                var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
    
                //the criteria our search term as a raw query
                var query = searchCriteria.RawQuery(term);
    
                //action a search based on our query
                searchResults = searcher.Search(query);
    
                foreach (var searchResult in searchResults)
                {
                    if (searchResult.Fields["nodeTypeAlias"].ToString().ToLower() == "file")
                    {
                        //we have found a physical file in the media folder structure
                        //note that this is the line where we can capitalise on that Media File custom property we created - friendlyFileName
                        var media = Umbraco.Media(searchResult.Id);
                        <li>
                            <a href="@media.Url" target="_blank">@searchResult.Fields["friendlyName"]</a>
                        </li>
                    }
                    else
                    {
                        //we are a content type other than a file
                        <li>
                            <a href="@Umbraco.NiceUrl(searchResult.Id)">@searchResult.Fields["nodeName"]</a>
                        </li>
                    }
                }
    
            }
        }
    </ul>
    

    This works for me and I feel this is a good starting point for me to grow from. I need more references to take this to the next level.

    Thanks for helping me think / walk through this!

  • Scott Leslie 28 posts 143 karma points
    Apr 04, 2017 @ 20:43
    Scott Leslie
    1

    Hi,

    i have a sample umbraco site with some code concepts for basic searching. It is by no means perfect code - but does have some useful code.

    https://bitbucket.org/sleslie/umbraco-multisearcher-demo

    S>

Please Sign in or register to post replies

Write your reply to:

Draft