Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 338 posts 987 karma points
    Jun 02, 2014 @ 17:41
    Neil Hodges
    0

    Examine - Multiple filters on an MNTP property

    Hi

    I have a legacy Umbraco 4.7.1 install im working on and want to do some Ajax search using Examine.

    I have this so far:

    @using Examine.LuceneEngine.SearchCriteria
    @using umbraco.MacroEngines
    @using UmbracoExamine.SearchCriteria
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var searchQuery = Request["searchstring"];
        var filterList = Request["filters"]; //1122,1133,1347
        var filterIds = new List<string>();
    
    
        var searcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];
        var searchCriteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
        var query = searchCriteria.Field("partnerTitle", searchQuery).Or().Field("shortDescription", searchQuery).Compile();
    
    
    
        var searchResults = searcher.Search(query);
    }
    
    @{
    
        foreach (var item in searchResults)
        {
            var nodeurl = Model.NodeById(item.Fields["id"]);                         
            <div>
                <p><a href="@nodeurl.Url">@item.Fields["partnerTitle"]</a></p>
            </div>
        }
    }

     

    I can search via the 'searchstring' being passed to the page, but need to be able to search a MNTP associated to the nodes is property alias is 'attributes'

    How would i build the query to search for attributes, i can pass a comma delimited string to the page - filterList

    but unsure how to build up the query.

    Any help would be greatly apprciated.

     

     

     

     

     

     

     

     

     

     

     

  • Charles Afford 1163 posts 1709 karma points
    Jun 02, 2014 @ 20:40
    Charles Afford
    0

    Hi Neil what exaclty are you trying to search for?

    Thanks,

    Charlie :)

  • Neil Hodges 338 posts 987 karma points
    Jun 02, 2014 @ 22:36
    Neil Hodges
    0

    Hi

    Im trying to implement a kind of faceted search

    My search uses filters and a search box, passing values to a searchresults page:

    My Search Page:

    I need it to search not only the title, description but match on the alias attributes which is a MNTP:

     

    The code above searches nicely when i pass a search term from the text box, but i cant get it to filter via the checkboxes which passes a sting like 1123,1345,1234

    so i need it to search to see if the node contains the alias attribute and has that id selected within it

  • Neil Hodges 338 posts 987 karma points
    Jun 03, 2014 @ 11:33
    Neil Hodges
    0

    Ok think i have this working -

    @using Examine.SearchCriteria
    @using UmbracoExamine
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var searchQuery = Request["searchstring"];
        var filterList = Request["filters"]; //1122,1133,1347
    
        var searcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];
    
    
        var criteria = searcher.CreateSearchCriteria(IndexTypes.Content);
        IBooleanOperation query = criteria.NodeTypeAlias("PartMark-Partner");
        query = query.Not().Field("umbracoNaviHide", 1.ToString());
    
        if (!string.IsNullOrEmpty(searchQuery))
        {
            query = query.And().Field("partnerTitle", searchQuery);
        }
        
        if (!string.IsNullOrEmpty(filterList))
        {
            string[] attIds = filterList.Split(',');
            query.And().GroupedOr(new List<string> { "attributes" }, attIds);
    
        }
        
        var results = searcher.Search(query.Compile());
           
    }
    
    @{
        foreach (var item in results)
        {
            var nodeurl = Model.NodeById(item.Fields["id"]);                         
            <div>
                <p><a href="@nodeurl.Url">@item.Fields["partnerTitle"]</a></p>
            </div>
        }
    }

     

    Seems to pull back results that match in the attributes MNTP ids now :)

    My only problem now is getting the 'searchQuery' string to match on a fuzzy basis, at the minute the case and word have to exactly match to bring back a result, is there a way to ignore case sensetivity and also partial words? i.e. contains chars of a word?

    i.e. the search term Limited = 2 results

    but, typing in Lim, lim, limi or any derivitive of that word would not return a result due to it not exactly matching

    Any ideas?

     

     

     

     

     

     

     

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft