Copied to clipboard

Flag this post as spam?

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


  • Frans de Jong 550 posts 1862 karma points MVP 4x c-trib
    Mar 17, 2015 @ 11:51
    Frans de Jong
    0

    Sitesearch with examine

    Hi all,

    I have some trouble with the examine sitesearch in Umbraco 7.2.2. The sitesearch is working when I only use the attributes of the result like Id and Name.

    When I use the folowing code the searchresults stays empty. I can't find any solution...

    @{
        string searchTerm = Request.QueryString["keywords"];
        if (String.IsNullOrWhiteSpace(searchTerm))
        {
            searchTerm = "";
        }      
    
        var searcher = ExamineManager.Instance;
        var searchCriteria = searcher.CreateSearchCriteria();
        var query = searchCriteria.GroupedOr(new[] { "nodeName", "name", "title", "bodyText", "seo" }, searchTerm).Compile();
        var searchResults = searcher.Search(query).Where(r => r["__IndexType"] == "content").ToList();
    }
    
    
    @if (@searchResults.Any())
    { ... Do stuff with it ...}
    

    Is this a old code snippet? Or am I doing something wrong?

    Frans

    edit: oops, wrong topic....

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 20, 2015 @ 10:46
    Dave Woestenborghs
    0

    I think you need to specify the index you want to search. By default there are 3 searchers configured by Umbraco (in examinesettings.config) . InternalSearcher, InternalMemberSearcher and ExternalSearcher. For searching on your site you will need to use the ExternalSearcher because this one only searches through published content.

    You specify which searcher to use like this :

    var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]

    Dave

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Mar 20, 2015 @ 10:56
    Ismail Mayat
    0

    Frans,

    One other thing you do not need to use linq to specifically search on content so the line

    searcher.Search(query).Where(r => r["__IndexType"]=="content").ToList();

    Is not needed, you can do 

    searcher.CreateSearchCriteria(IndexTypes.Content);

    also in your searcher.Search(query)

    that should be 

    query.Compile()

    If you stll get no results then after the search line can you do 

    searchCriteria.ToString()

    and post back here the generated lucene query that will give indication as to what is going on.

    Regards

    Ismail

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 20, 2015 @ 10:59
    Dave Woestenborghs
    0

    Hi Ismail,

    Is it not needed to specify a searcher to use  ?

    Dave

  • Frans de Jong 550 posts 1862 karma points MVP 4x c-trib
    Mar 20, 2015 @ 11:25
    Frans de Jong
    0

    Thanks for the reply's guys,

    I've added Daves sugestion and included all the variables in this post.

    @Ismail: If I change the code to your sugestion I get a error: Compiler Error Message: CS0103: The name 'IndexTypes' does not exist in the current context

    @{
        string searchTerm = Request.QueryString["keywords"];
        if (String.IsNullOrWhiteSpace(searchTerm))
        {
            searchTerm = "";
        }
    
        var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
        var searchCriteria = searcher.CreateSearchCriteria();
        var query = searchCriteria.GroupedOr(new[] {"nodeName", "title", "subTitle", "contentgrid", "mainHeader", "contentgrid","metaTitle" }, searchTerm).Compile();
        var searchResults = searcher.Search(query).Where(r => r["__IndexType"] == "content").ToList();
    
    }
    
    
    <p>
        @searcher.ToString()<br/><br/>
        @searchCriteria.ToString()<br/><br/>
        @query.ToString()<br/><br/>
        @searchResults.ToString()<br/><br/>
    </p>
    
    • searcher: UmbracoExamine.UmbracoExamineSearcher

    • searchCriteria: { SearchIndexType: , LuceneQuery: +(nodeName:ipsum title:ipsum subTitle:ipsum contentgrid:ipsum mainHeader:ipsum contentgrid:ipsum metaTitle:ipsum) }

    • query: { SearchIndexType: , LuceneQuery: +(nodeName:ipsum title:ipsum subTitle:ipsum contentgrid:ipsum mainHeader:ipsum contentgrid:ipsum metaTitle:ipsum) }

    • searchResults: System.Collections.Generic.List`1[Examine.SearchResult]

    Thanks

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Mar 20, 2015 @ 11:45
    Ismail Mayat
    0

    Francs,

    You need one of these usings

    using Examine;

    using Examine.LuceneEngine.SearchCriteria;

    using Examine.Providers;

    using Examine.SearchCriteria;

    using UmbracoExamine;

    not sure which ;-} 

    I can see the generated lucene query, can you download luke (https://code.google.com/p/luke/downloads/list need 3.5.0 you will also need to have java installed) and open the index with that and then run the generated query see if that works.

     

Please Sign in or register to post replies

Write your reply to:

Draft