Copied to clipboard

Flag this post as spam?

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


  • Manish 373 posts 929 karma points
    Mar 08, 2017 @ 11:11
    Manish
    0

    Examine search with surface controller

    Hi

    I am using umbraco version 7.5. I added a simple search page which returns me result well if I pass a single parameter in query string. Some thing like that

    http://localhost:83/search/?search=Publication

    It is works fine but my case is little different. I have a list of check boxes and i want to refine results on basis of check box selection. enter image description here

    Here are few points on which can someone help me out

    1. How can i do this using surface controller with Ajax call.
    2. Is there any sample code with Ajax+Surface+Examine.

    Manish

  • David Peck 615 posts 1646 karma points c-trib
    Mar 08, 2017 @ 11:35
    David Peck
    0

    Hi Manish,

    Ajax shouldn't really pose any additional constraint. Just return a JsonResult e.g.

    var myResults = new List<MyTypedResultObject>();
    //.... populate results
    return Json(myResults);
    

    However, instead of using Json you could just return the HTML which is required to replace your results. This works just the same as a Partial. Return a PartialResult and have your view render the results.

    If your surface controller has arguments for all your filters then that should be straight forward.

  • Manish 373 posts 929 karma points
    Mar 08, 2017 @ 12:34
    Manish
    0

    thanks for giving me a start.

  • Manish 373 posts 929 karma points
    Mar 08, 2017 @ 13:21
    Manish
    0

    I am doing code something like that but no luck with date range

    var q = "Policy Publication";
                var q_split = q.Split(' ');
    
                var Searcher = Examine.ExamineManager.Instance.SearchProviderCollection["MySearcher"];
                var searchCriteria = Searcher.CreateSearchCriteria(BooleanOperation.Or);
    
                var fieldsToSearch = new[]
                {
                 "type", "format", "nodeName", "createdDate"
                };
    
                IBooleanOperation filter = searchCriteria.GroupedOr(fieldsToSearch, q_split.First());
                foreach (var term in q_split.Skip(1))
                {
                    filter = filter.Or().GroupedOr(fieldsToSearch, term);
                }
    
                //Put if condition for date range
                filter = filter.And().Range("createdDate", new DateTime(2017, 03, 01), new DateTime(2017, 03, 05));
    
                var searchResults = Searcher.Search(filter.Compile());
    
  • David Peck 615 posts 1646 karma points c-trib
    Mar 08, 2017 @ 19:12
    David Peck
    0

    You probably need to use the GatheringNodeData examine event to populate a field with the format yyyyMMddHHmmss. Plus I'm not sure range works. You might need to do a greater than and a less than.

  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Mar 08, 2017 @ 19:51
    Dan Diplo
    0

    You can do date range searches uses Lucene (Examine) but you might need to create a raw query. This is how I format it:

    var query = String.Format("{0}:[{1}* TO {2}*]", dateField, fromDate.ToString("yyyyMMdd"), toDate.AddDays(1).ToString("yyyyMMdd"));
    

    dateField is the name of the field in your index that holds the date fromDate and toDate are DateTime values for your date range.

  • Manish 373 posts 929 karma points
    Mar 09, 2017 @ 05:38
    Manish
    0

    Hi Dan Diplo

    I just added like this but not able to filter

       var query = String.Format("{0}:[{1}* TO {2}*]", "createdDate", new DateTime(2017, 02, 01).ToString("yyyyMMdd"), new DateTime(2017, 03, 05).ToString("yyyyMMdd"));
    
                filter = filter.And().GroupedOr(fieldsToSearch, query);
    

    Manish

  • Manish 373 posts 929 karma points
    Mar 09, 2017 @ 06:20
    Manish
    100

    Just done with this

     filter = filter.And().Range("createDate", queryDate.AddDays(-2).ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), queryDate.AddDays(1).ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture));
    

    Thanks all for your valueble support

    Manish

  • Manish 373 posts 929 karma points
    Mar 09, 2017 @ 13:28
    Manish
    0

    How can i apply pagination when i am getting results through Ajax. Any code snippet please.

    Manish

  • 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