Copied to clipboard

Flag this post as spam?

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


  • Jeff Subat 28 posts 159 karma points
    Jun 30, 2017 @ 04:02
    Jeff Subat
    0

    Cogworks.ExamineFileIndexer duplicate results with MultiIndexSearcher

    With ExamineFileIndexer, I get duplicate results when:

    1. Using a MultiIndexSearcher, and
    2. The same term is found in two files

    I do not get duplicate results when the same term is found in two document types.

    Here's the element I added for the searcher:

    <add name="MultiIndexSearcher" type="Examine.LuceneEngine.Providers.MultiIndexSearcher, Examine" analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSets="ExternalIndexSet,MediaIndexSet" enableLeadingWildcards="false" />
    

    The ExternalIndexSet and the MediaIndexSet referred to are the out-of-box set and the media set inserted when I installed the ExamineFileIndexer package, respectively.

    Here's code from my test page:

        @using Examine.SearchCriteria
    @using Examine
    @{
        Layout = null;
    
        string term = "control";
    
        // Get a searcher
        Examine.Providers.BaseSearchProvider searcher = ExamineManager.Instance.SearchProviderCollection["MultiIndexSearcher"];
    
        // Create search criteria instance
        ISearchCriteria searchCriteria = searcher.CreateSearchCriteria();
    
        // Pass the search criteria instance our search term as a raw query
        ISearchCriteria query = searchCriteria.RawQuery(term);
    
        // Search using the criteria in our query. Receive results.
        ISearchResults searchResults = searcher.Search(query);
    
    }
    
    <ul>
        @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["nodeName"]</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>
    

    In my database, there are two .pdf files and two document types with the word "control" in them.

    When I use the MultiIndexSearcher, I get six results: one each for the doc types, and two each for the files (duplicates, in other words).

    When I use the MediaIndexSearcher, I get two results -- one for each file. Also, if I remove the ExternalIndexSet from the MultiIndexSearcher, I get the proper number of results (one for each file).

    I know I could, of course, query the indexes separately and combine the results. I'd rather figure out how to make the MultiIndexSearcher work, though. Any help would be appreciated!

Please Sign in or register to post replies

Write your reply to:

Draft