Copied to clipboard

Flag this post as spam?

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


  • jake williamson 207 posts 872 karma points
    Aug 27, 2019 @ 01:47
    jake williamson
    0

    how to match tags in examine in v8? they're now stored as a json string array!

    hey out there,

    i'm in the process of setting up a search for a new v8 site.

    so far i've managed to cobble some code together with examples i've found in the forum however i've hit a bit of a wall when it comes to matching against tags...

    it appears that tag data type is now stored as a json string array in the index:

    tags in an index

    i guess this nicer as we no longer have to hook into the index events to store the tags in a new non analyzed field?

    however...

    how the hell do i match against them now?!?!

    for example, i have a string array to match against 'topics' that contains 'Refugees' and 'Food' so i want to grab all items that have those two topic tags.

    this is very early days in the code that i'm writing but i wondered if someone out there has already hit upon this problem and has any insight?

    it feels like the kind of thing that a lot of people would want to do after all, the tags datatype really lends itself to this kinda filtering!

    any suggestions, as ever, are greatly received ;)

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Aug 30, 2019 @ 00:56
    Shaishav Karnani from digitallymedia.com
    0

    Hi Jake,

    Did you find solution for it? I can think of below query in order to achieve it.

                    results = examineSearcher.CreateQuery("content").Field("topics", "refugees").And().Field("topics", "food").Execute();
    

    Cheers, Shaishav

  • jake williamson 207 posts 872 karma points
    Sep 02, 2019 @ 02:15
    jake williamson
    100

    hey shaishav,

    i've been bashing my head for a while on this problem and at the moment, i've come up with the following.

    the filters are captured in a dictionary:

    public Dictionary<string, IEnumerable<string>> Filters { get; set; }
    

    so in this example, my 'keys' are the tag property e.g. topics and types and then the filters are the values e.g. topics has Refugees and Food and types has Education.

    then i'm looping through and appending them to the query e.g.

    foreach (var filter in search.Filters)
    {
        if (filter.Value.Any(x => !string.IsNullOrWhiteSpace(x)))
        {
            query.GroupedOr(new[] { filter.Key }, filter.Value.ToArray()).And();
        }
    }
    

    so far so good - ish! i'm still testing but it 'seems' to be working.

    sure wish you could write unit tests for this stuff, kinda does my head in that the only way to test it is in browser...

Please Sign in or register to post replies

Write your reply to:

Draft