Copied to clipboard

Flag this post as spam?

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


  • shanem 39 posts 93 karma points
    Mar 29, 2011 @ 20:03
    shanem
    0

    Searching multiple indexes with Examine

    I have 2 custom index sets generating with Examine in Umbraco 4.7RC. They both index all the fields I want correctly. When it comes to searching I select the provider using this line of code:

    var criteria = ExamineManager.Instance.SearchProviderCollection[indexName].CreateSearchCriteria(IndexTypes.Content, BooleanOperation.Or);

    I'm assuming that this should select the index search provider I specify in the variable indexName? But this doesn't happen as I only ever get results back for the correct index when I change the defaultProvider value in ExamineSettings.config.

    How do you search multiple indexes? Examine seems to only use the defaultProvider and ignores the rest.

  • Gerty Engrie 130 posts 490 karma points c-trib
    Mar 29, 2011 @ 22:01
    Gerty Engrie
    0

    You could for example:

    var searchProvider = ExamineManager.Instance.SearchProviderCollection["RegularSearcher"];
    //RegularSearcher & PDFSearcher are the names you set up in the <ExamineSearchProviders settings in ExamineSettings.config
    var searchProviderPdf = ExamineManager.Instance.SearchProviderCollection["PDFSearcher"];

    IEnumerable<SearchResult> searchResultsAll = searchProvider.Search(searchstring,true);
    searchResultsAll = searchResultsAll.Concat(searchProviderPdf.Search(searchstring,true));

    searchResultsAll = searchResultsAll.OrderByDescending(n => n.Score);
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Mar 30, 2011 @ 08:37
    Ismail Mayat
    0

    Guys,

    The latest version of examine has multi index search provider, not used it myself but its there see http://examine.codeplex.com/releases/view/62313

    Regards

    Ismail

  • shanem 39 posts 93 karma points
    Mar 30, 2011 @ 10:13
    shanem
    0

    Thank you for the replies. I don't want to combine the search results I am just trying to search each index seperatley. So I have MethodA which searches IndexA and returns results, and MethodB which searches IndexB and returns results. It seems if MethodA uses SearcherA I get the IndexA results, but when MethobB uses SearcherB I get no results. MethodB will only return results if I change the defaultProvider field to SearcherB, but then MethodA doesn't return any results.

    Both Lucene queries generated in C# return results in Luke.

    I'm going to update to Umbraco 4.7 final and make sure I have the latest Examine dll. I still think you should be able to search 2 indexes with 2 different providers and get back 2 different results, or am I mistaken?

    Looking forward to your response :)

  • shanem 39 posts 93 karma points
    Mar 30, 2011 @ 10:50
    shanem
    0

    Here is my method where I pass in the indexName (plus other parameters)

            public static IEnumerable<SearchResult> Search(string indexName, string[] searchTerms, string[] fields, string[] nodeTypeAliases)
            {
                IEnumerable<SearchResult> results = null;
    
                if (searchTerms != null)
                {
                    // Make sure there are no empty search terms.
                    var nonEmptySearchTerms = searchTerms.Where(x => !string.IsNullOrEmpty(x));
                    if (nonEmptySearchTerms.Count() > 0)
                    {
                        // Get the search criteria by using our searcher provider and looking only in the content tree of Umbraco.
                        var criteria = ExamineManager.Instance.SearchProviderCollection[indexName].CreateSearchCriteria(IndexTypes.Content, BooleanOperation.Or);
    
                        // Build the search query.
                        Examine.SearchCriteria.IBooleanOperation query = null;                    
                        foreach (var searchTerm in nonEmptySearchTerms)
                        {
                            // Add search fields.
                            foreach (var field in fields)
                            {
                                query = query == null ? criteria.Field(field, searchTerm.Escape().Value.MultipleCharacterWildcard()) :
                                    query.Or().Field(field, searchTerm.Escape().Value.MultipleCharacterWildcard());
                            }
                        }
    
                        // Perform the search.
                        results = ExamineManager.Instance.Search(query.Compile());
                        results = results.OrderByDescending(x => x.Score); // Relevance.
    
                        // TODO: Do this in the query not sure how yet?
                        if (nodeTypeAliases != null)
                        {
                            results = results.Where(x => nodeTypeAliases.Contains(x.Fields["nodeTypeAlias"]));
                        }
                    }
                }
    
                return results;
            }
  • Stephen 767 posts 2273 karma points c-trib
    Mar 30, 2011 @ 11:22
    Stephen
    0

    We have a very similar method, and... it just work (latest 4.7), ie it picks results for the selected index. But I remember facing a similar issue in the past. Can you check that you do have the latest Examine DLLs?

  • shanem 39 posts 93 karma points
    Mar 30, 2011 @ 15:13
    shanem
    0

    I tried to upgrade from 4.7RC to 4.7 final. The upgrade all works except umbraco.MacroEngines.dll. I get this message on all my Razor scripts:

    Error loading Razor Script *.cshtml Method not found: 'System.Collections.Generic.IEnumerable`1 umbraco.MacroEngines.DynamicNodeList.get_Items()'.

    If I use the 4.7RC umbraco.MacroEngines.dll it works.

    umbraco.MacroEngines.dll 4.7RC (version 1.0.0.0, size 89Kb) - this works!
    umbraco.MacroEngines.dll 4.7 (version 1.0.0.0, size 97Kb) - this doesn't work!

    Any one else have this problem?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 30, 2011 @ 16:41
    Morten Bock
    0

    You have to specify which searcher to search. Not only to create the query:

    ISearchResults searchResults = ExamineManager.Instance.SearchProviderCollection["MySearcher"].Search(query.Compile());

     

  • shanem 39 posts 93 karma points
    Mar 30, 2011 @ 16:57
    shanem
    0

    That works! Quite obvious - thank you :)

    Any ideas on the umbraco.MacroEngines.dll error I'm expriencing updating?

  • Stephen 767 posts 2273 karma points c-trib
    Mar 30, 2011 @ 17:04
    Stephen
    0

    @Morten: we indeed do that, and I failed to spot the difference... you're the boss!

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 30, 2011 @ 22:43
    Morten Bock
    0

    Glad it worked. I don't have an answer on the razor issue. sorry.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies