Copied to clipboard

Flag this post as spam?

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


  • George Phillipson 108 posts 287 karma points
    Mar 19, 2018 @ 11:34
    George Phillipson
    0

    Filter Lucene search results under document type

    Hi

    I have a structure like the following

    category (Boots)

    ----itemsForSale (addidas)

    category (Socks)

    ----itemsForSale (long)

    Where Boots is the name of the category doctype and Adidas is the name for the itemsForSale doctype etc.

    Now if a visitor to the site selects the Boots category from the checkbox options, I pass the id to the search page

    The visitor can also search via keyword and min, max price.

    That keyword min,max price option works, I just cannot get the search to work so that it only displays items under the parent, i.e Addidas.

    I have the following code:

    ExamineIndex

    <add Name="categoryPath"/>
    

    OnGatheringNodeData

    private void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
            {
                if (e.Fields.ContainsKey("bidPrice"))
                {
                    e.Fields["searchBidPrice"] = e.Fields["bidPrice"].PadLeft(10, '0');
                }
    
    
                var path = e.Fields["path"];
                path = path.Replace(",", " ");
                e.Fields.Add("categoryPath", path);
            } 
    

    And my search is as follows:

     //TODO needs to be fixed so that checkbox search can be done
                        query = searchCriteria.Range("bidPrice", paddedLower, paddedHigher, true, true).And().Field("categoryPath",searchCategory).Or().Field("nodeName",searchCategory.Fuzzy()).Or().Field("nodeName", q.Fuzzy()).Or().Field("description", q.Fuzzy());
    

    But no results are getting returnned, can anyone see what I'm doing wrong, I have rebuild the index, but no luck.

    Thanks in advance

    George

  • Paul Tilsed 26 posts 179 karma points c-trib
    Mar 21, 2018 @ 09:45
    Paul Tilsed
    0

    Hi George,

    By default Umbraco will add a field called ParentID to the index. Based on your structure you should be able to search against that field without having to do any manipulation of the path. This is probably an easier route for you in this situation.

    If you allow more than one category to be selected at once then you could use the GroupedOr() method which allows you to pass in multiple IDs to search against. It would look something like this:

            query = searchCriteria.Range("bidPrice", paddedLower, paddedHigher, true, true)
                .And().GroupedOr(new string[] { "ParentID" }, new string[] { "CategoryIDOne", "CategoryIDTwo" }) //This is the key line 
                .Or().Field("nodeName", searchCategory.Fuzzy())
                .Or().Field("nodeName", q.Fuzzy())
                .Or().Field("description", q.Fuzzy());
    

    Hopefully this is along the lines of the functionality you are looking for.

    Paul

  • George Phillipson 108 posts 287 karma points
    Mar 21, 2018 @ 10:14
    George Phillipson
    0

    Hi Paul

    Thanks for the reply, I managed to solve the problem in my case I had to use the following

    .Field("__Path",searchCategory)
    

    No idea why but that worked, and as really pushed for time did not have time to find out why. All I know is that in Lucene /Examine the field in the raw data is named __Path.

    Regards George

Please Sign in or register to post replies

Write your reply to:

Draft