Copied to clipboard

Flag this post as spam?

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


  • Nigel Wilson 945 posts 2077 karma points
    Nov 29, 2011 @ 23:36
    Nigel Wilson
    0

    Examine Search Results With Multiple Checkboxlists

    Hi there

    My first time implementing Examine / Lucene search and I choose to do so with 5 checkboxlists - arghh !

    My desired result is that the user can make multiple choices across any or all of 5 checkbox lists and my search results will display accordingly.

    To kick things off here is my code for filtering on the selections of the first checkbox list

     

    // Set criteria
    var criteria = ExamineManager.Instance.SearchProviderCollection["RFCRecordsSearcher"].CreateSearchCriteria(); //Make initial selection of all items in the index
    var query = criteria.NodeTypeAlias("changeRequest"); //If any project managers have been selected add filter
    if (countProjectMgrs > 0)
    {
    var selectedProjectManagerValues = (from item in cblITProjectManagers.Items.Cast<ListItem>() where item.Selected select item.Text).ToArray();
            var selectedProjectManagerValuesJoined = (countProjectMgrs > 1 ? "(+" + string.Join(" +", selectedProjectManagerValues) + ") " : cblITProjectManagers.SelectedValue);
            query = query.And().GroupedAnd(new[] { "iTProjectManager" }, selectedProjectManagerValuesJoined);
    }

    If I only tick one Project Manager I am getting the correct results. However if more than one is ticked I get no results.

    Can anyone please advise where my code is wonky ?

    Thanks

    Nigel

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 30, 2011 @ 00:13
    Bo Damgaard Mortensen
    0

    Hi Nigel,

    Being new to Examine and the Fluent query language, this is just a guess :-)

    Could it be that you need to use the BooleanOperation.Or to get the correct Lucene searchterm? Right now it seems that you're performing a search in Lucene with the query being: "+ property:SearchTerm" where you would need it to be something like "property:SearchTerm" instead.

    There's a more in-depth article on this here: http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx 

    .. at about half-way down the page.

    Don't know if this is of any help at all (?)

    - Bo

  • Nigel Wilson 945 posts 2077 karma points
    Nov 30, 2011 @ 00:27
    Nigel Wilson
    0

    Hi Bo

    Thanks for your reply but no joy yet..

    I tried:

    var criteria = ExamineManager.Instance.SearchProviderCollection["RFCRecordsSearcher"].CreateSearchCriteria(BooleanOperation.Or);

    and I tried:

    query = query.And().GroupedOr(new[] { "iTProjectManager" }, selectedProjectManagerValuesJoined);

    but I still get the same output - no data on multiple selection, correct data on single selection.

    I need to keep Googling - the article you reference was written by Peter Gregory who recently provided training for Level 1 and 2 so I might send him a note... 

    Thanks again.

    Nigel

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 30, 2011 @ 00:31
    Bo Damgaard Mortensen
    0

    Hi Nigel,

    Alright, was worth a shot. 

    Have you checked which values there's in your string array? Just to be sure the values actually exists :-)

    - Bo

  • Nigel Wilson 945 posts 2077 karma points
    Nov 30, 2011 @ 00:37
    Nigel Wilson
    0

    Ahh good point - will do some checking now...


    N

  • Nigel Wilson 945 posts 2077 karma points
    Nov 30, 2011 @ 00:45
    Nigel Wilson
    0

    OK...

    For a single selection the data benig input is just the node ID which is valid data and returning correct matches.

    For multiple selections the data is being formatted as:

    (+1952 +1740)

    I have also tried changing it to simply output

    1952 1740

    this also didn't work.

    Thanks for your help Bo - will be a happy chap when I can crack this one...

    Nigel

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 30, 2011 @ 00:53
    Bo Damgaard Mortensen
    0

    Hi Nigel,

    O.k, so 1952 and 1740 seems to be Node id's ? :-) And your Examine index is set to index those aswell?

    Also, just to break it down, have you tried to hardcode some values into the search criteria to see if it shows up? If not, try to hit your web.config and upload it again to recycle the application. This should force your index to be created again.

    - Bo

  • Nigel Wilson 945 posts 2077 karma points
    Nov 30, 2011 @ 00:58
    Nigel Wilson
    0

    Hey Bo

    You are correct the ID's are Node ID's and that is what is being indexed.

    A single selection of Project Manager is returning correct values so the index appears to be correctly setup.

    I truly appreciate your proactive thinking and participation - thank you.

    Nigel

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 30, 2011 @ 01:04
    Bo Damgaard Mortensen
    0

    Hi Nigel,

    No worries, i'm just curious on this really :-)

    Can you please try to set your query variable to this:

    var query = criteria.GroupedOr(new string[] { "Id" }, new string[] { "1952", "1740" }); 

    (forgive me if the syntax is incorrect, writing straight in the editor)

    Just to see if there's any output at all..

    Thanks!

    - Bo

  • Nigel Wilson 945 posts 2077 karma points
    Nov 30, 2011 @ 01:15
    Nigel Wilson
    0

    Hi Bo

    No go on that either I'm afraid...

    My code was:

    var query = criteria.GroupedOr(new string[] {"iTProjectManager"}, new string[] { "1952", "1740" }); 

    as iTProjectManager is the field being indexed.

    A single selection returns correct results, a multiple selection returns no results. So again it is very close, but yet so far....

    Thanks again for your time / assistance - time to take a break from it I think and come back to it later...

    Cheers

    Nigel

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 30, 2011 @ 02:03
    Bo Damgaard Mortensen
    0

    Hi Nigel,

    Alright, well I've been searching a bit on this and all I could find is a semi-ugly approach when searching in one field for n values. Something like this (put on your "ugly-but-should-work-glasses" now):

    var searchTerms = new string[] { "1952", "1740" };
    foreach(string term in searchTerms)
    {
    query = query.And().Field("iTProjectManager", term);

    Again, not sure on the syntax.

    Anyway, it's getting late here, so I better hit the sack instead of keep pushing some random non-working cowboy-code your way ;-)

    - Bo

  • Nigel Wilson 945 posts 2077 karma points
    Nov 30, 2011 @ 03:56
    Nigel Wilson
    0

    Hi Bo

    Perseverance paid off...

    The (rather verbose) code is:

     

    // Set criteria
    var criteria = ExamineManager.Instance.SearchProviderCollection["RFCRecordsSearcher"].CreateSearchCriteria(BooleanOperation.And);

    //Default variables
    var luceneString = "";
    bool prevSelection = false;

    //If any project managers have been selected add filter
    if (countProjectMgrs > 0)
    {
    var selectedProjectManagerValues = (from item in cblITProjectManagers.Items.Cast() where item.Selected select item.Value).ToArray();
            luceneString += "(iTProjectManager:";
    luceneString += countProjectMgrs > 1 ? string.Join(" ", selectedProjectManagerValues) : cblITProjectManagers.SelectedValue;
           luceneString += ")";

    prevSelection = true;
    }

    //If any assignees have been selected add filter
    if (countAssignees > 0)
    {
    luceneString += prevSelection ? " AND " : "";
    var selectedAssigneesValues = (from item in cblAssignees.Items.Cast() where item.Selected select item.Value).ToArray();
            luceneString += "(assignee:";
    luceneString += countAssignees > 1 ? string.Join(" ", selectedAssigneesValues) : cblAssignees.SelectedValue;
          luceneString += ")";
    prevSelection = true;
    }

    //If any functional areas have been selected add filter
    if (countFunctionalAreas > 0)
    {
    luceneString += prevSelection ? " AND " : "";
    var selectedFunctionalAreaValues = (from item in cblFunctionalAreas.Items.Cast() where item.Selected select item.Value).ToArray();
    luceneString += "(functionalArea:";
    luceneString += countFunctionalAreas > 1 ? string.Join(" ", selectedFunctionalAreaValues) : cblFunctionalAreas.SelectedValue;
            luceneString += ")";
    prevSelection = true;
    }

    //If any BPO Priorities have been selected add filter
    if (countBPOPriorities > 0)
    {
    luceneString += prevSelection ? " AND " : "";
    var selectedBPOPrioritiesValues = (from item in cblBPOPriorities.Items.Cast() where item.Selected select item.Value).ToArray();
            luceneString += "(bPOPriority:";
    luceneString += countFunctionalAreas > 1 ? string.Join(" ", selectedBPOPrioritiesValues) : cblBPOPriorities.SelectedValue;
            luceneString += ")";
    prevSelection = true;
    }

    //If any Status's have been selected add filter
    if (countStatus > 0)
    {
    luceneString += prevSelection ? " AND " : "";
    var selectedStatusValues = (from item in cblStatus.Items.Cast() where item.Selected select item.Value).ToArray();
            luceneString += "(status:";
    luceneString += countFunctionalAreas > 1 ? string.Join(" ", selectedStatusValues) : cblStatus.SelectedValue;
           luceneString += ")";
    }

    var query = criteria.RawQuery(luceneString);

    SearchResults = ExamineManager.Instance.SearchProviderCollection["RFCRecordsSearcher"].Search(query).OrderByDescending(x => x.Score);

    searchResultListing.DataSource = SearchResults;
    searchResultListing.DataBind();

    Hope this helps someone else at some stage.

    Nigel

     

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Dec 02, 2011 @ 00:02
    Bo Damgaard Mortensen
    0

    Hi Nigel,

    Glad you solved it! I'm sure this will be helpful for others aswell.

    - Bo

Please Sign in or register to post replies

Write your reply to:

Draft