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:
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!
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...
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:
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 ;)
Hi Jake,
Did you find solution for it? I can think of below query in order to achieve it.
Cheers, Shaishav
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:
so in this example, my 'keys' are the tag property e.g.
topics
andtypes
and then the filters are the values e.g.topics
hasRefugees
andFood
andtypes
hasEducation
.then i'm looping through and appending them to the query e.g.
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...
is working on a reply...