Copied to clipboard

Flag this post as spam?

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


  • MrFlo 159 posts 403 karma points
    Mar 21, 2015 @ 14:54
    MrFlo
    0

    Examine product filter with checkboxes and comma separated values

    Hello,

    I am working on a filter to filter all the product pages. Each product has a series of multiple checkboxes in the backoffice. Each field is stored in CSV.

    On the front-end side I have a multiple checkboxs filter that should sort the products.

    After setting up my custom searcher/indexer, I can't have it woring because of the comma.

    Here is a search using only a signle value (but it will be a CSV string as well).
    As the field may contain a comma, it's not working properly:

     var query = searchCriteria.Field("nodeTypeAlias", "Product")
            .And().Field("cableInterface", "SDI")
            .And().Field("pcieInterface", "Gen1 x1")
            .And().Field("formFactor", "standard height").Compile(); 

     

    I have tried to remove the comma from each indexed field using something like this but it's not indexing anything now:

    private const string ProductAlias = "Product";
    
    public ExamineEvents()
    {
     ExamineManager.Instance.IndexProviderCollection["ProductIndexer"].GatheringNodeData += ExamineEvents_GatheringNodeData;
    }
    
    void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
                if (e.IndexType == IndexTypes.Content)
                {
                    if (e.Node.Name == ProductAlias)
                    {
                        foreach (var keyValuePair in e.Fields)
                        {
                 e.Fields[keyValuePair.Key] = e.Fields[keyValuePair.Key].Replace(",", " ");
                        }
                    }
                }
    }

     

    Is there an error in my examine event ?
    Do I have to use another search query ?

    Thanks a lot for your help

  • Alain 73 posts 520 karma points c-trib
    Mar 21, 2015 @ 15:52
    Alain
    100

    Hi,

    Have a look to this thread since it is very similar to what you want to achieve https://our.umbraco.org/forum/developers/api-questions/57958-Using-Examine-to-search-UmbracoTags

    Hope that helps.

    Alain

  • MrFlo 159 posts 403 karma points
    Mar 21, 2015 @ 15:57
    MrFlo
    0

    Hi Alain,

    Thank you for the link, this can help!

    I didn't know that the event ExamineEvents_GatheringNodeData  was trigered on publish. So If I want to trigger this on all pages I have to re-publish all site?
    It's not fired up on reindexing ?

    Florent 

  • Alain 73 posts 520 karma points c-trib
    Mar 21, 2015 @ 16:03
    Alain
    0

    Florent,

    This event should be fired up on reindexing. Try to rebuild your index from the [Developper section -> Examine management] in umbraco 7, to be 100% sure.

    Alain

  • MrFlo 159 posts 403 karma points
    Mar 21, 2015 @ 17:13
    MrFlo
    0

    Hi Alain,

    It's working now. In my first version, I was trying to replace an existing indexed field which is not possible.

    This is working:

    private void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
        if (e.IndexType != IndexTypes.Content) return;
    
        var fields = e.Fields;
        var searchableFields = new Dictionary<string, string>();
        foreach (var field in fields)
        {                 
            var searchableFieldKey = field.Key+"Indexed";
            var searchableFieldValue = field.Value.Replace(',', ' ');
            if (!string.IsNullOrEmpty(searchableFieldValue))
            {
                searchableFields.Add(searchableFieldKey, searchableFieldValue);
            }                         
        }
    
        foreach (var fld in searchableFields)
        {
            e.Fields.Add(fld.Key, fld.Value);
        }
    }
Please Sign in or register to post replies

Write your reply to:

Draft