Multiple Searchterm in umbraco Examine Search

1.6k views Asked by At

I am trying to setup a search in umbraco examine.I have two search fields ,material and manufacturer.when I trying to search with one material and one manufactuere it will give the correct result.but when try to search more than one material or manufacturer it doesn't give the result.here is my code

 const string materialSearchFields = "material";
    const string manufacturerSearchFields = "manufacturer";

if (!string.IsNullOrEmpty(Request.QueryString["material"])) { material = Helper.StripTags(Request.QueryString["material"]); } if (!string.IsNullOrEmpty(Request.QueryString["manufacturer"])) { manufacturer = Helper.StripTags(Request.QueryString["manufacturer"]); } if (!string.IsNullOrEmpty(Request.QueryString["material"]) || !string.IsNullOrEmpty(Request.QueryString["manufacturer"])) { var query = userFieldSearchCriteria.Field(materialSearchFields, material).And().Field(manufacturerSearchFields, manufacturer).Compile(); contentResults = contentSearcher.Search(query).ToList(); }

here my search keywors in querystring is material=iron,steel

how can we split this keyword and search done? Thanks in advance for the help....

1

There are 1 answers

0
antao On

You are using the AND operator, in your case I think you are looking for the GROUPEDOR instead?

I was just working in an old project and grabbed this snipet from there (which I've adapted for your needs). I think it's going to help you:

public IEnumerable<DynamicNode> SearchUmbraco(string[] keywords, string currentCulture)
        {
            // In this case I had some  diferent cultures, so this sets the BaseSearchProvider to the given culture parameter. You might not need this, use your default one.
            BaseSearchProvider searcher = SetBaseSearchProvider(currentCulture);

            var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
            var groupedQuery = searchCriteria.GroupedOr(new[] {"manufacturer", "material"}, keywords).Compile();

            var searchResults = searcher.Search(groupedQuery);

            // ... return IEnumerable of dynamic nodes (in this snipet case)

        }

I just split(etc) the keywords in an helper and pass them to a string array when I call this method.

Just check this infomation on the umbraco blog: http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx