Copied to clipboard

Flag this post as spam?

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


  • Frederik T 234 posts 345 karma points
    Oct 06, 2022 @ 08:37
    Frederik T
    0

    Handling tag datatypes with Examine

    I have made a search page using Examine which for the moment works fine and as intended (still needs to get paging sorted...), but I have run into an issue. I also want the page to function as a related tags page, as in an article can have several tags, and if you click a tag you can see related articles with the same tag. Pretty basic stuff. Only I have found out that Examine cant really handle tag data types because as I understand they are stored in a comma delimited list, something Examine cant handle in this case. I have searched around and found only a few hints of others having the same problem, one with an actual solution but that sadly no longer works in Umbraco 10: https://our.umbraco.com/forum/developers/api-questions/57958-Using-Examine-to-search-UmbracoTags

    Also found this more recent one, but kind of a dead end: https://our.umbraco.com/forum/umbraco-8/98761-how-to-match-tags-in-examine-in-v8-theyre-now-stored-as-a-json-string-array

    So yeah, what the heck do I do?

    For good measure here is my examine code:

    @{
        Layout = "master.cshtml";
        var searchQuery = !string.IsNullOrWhiteSpace(Context.Request.Query["q"].ToString()) ? Context.Request.Query["q"].ToString() : "";
        var tags = !string.IsNullOrWhiteSpace(Context.Request.Query["tags"].ToString()) ? Context.Request.Query["tags"].ToString() : "";
        var parent = !string.IsNullOrWhiteSpace(Context.Request.Query["parent"].ToString()) ? Convert.ToInt32(Context.Request.Query["parent"].ToString()) : 1088;
    
        if (!examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out IIndex index))
        {
            throw new InvalidOperationException($"No index found by name{Constants.UmbracoIndexes.ExternalIndexName}");
        }
        var searcher = index.Searcher;
        var criteria = searcher.CreateQuery(IndexTypes.Content);
        var filter = criteria.ParentId(parent).AndNot(x => x.Field("umbracoNaviHide", 1.ToString()));
    
        if (!string.IsNullOrWhiteSpace(tags))
        {
            filter.And().Field("tags", tags);
        }
        if (!string.IsNullOrWhiteSpace(searchQuery))
        {
            filter.And().ManagedQuery(searchQuery);
        }
        var res = filter.Execute();
    }
    
  • Harikrishna Parmar 43 posts 262 karma points c-trib
    Oct 14, 2022 @ 11:10
    Harikrishna Parmar
    0

    Hi, To search tags, create custom fields. in umbraco 10 the syntax is changes to collect data. we need to define Dictionary and that will use to update emanine index values. but this will definitely work. Let me know if you want the code block.

  • Frederik T 234 posts 345 karma points
    Oct 17, 2022 @ 08:29
    Frederik T
    0

    Yeah an example would be great as I don't really follow what you mean :)

  • Frederik T 234 posts 345 karma points
    Oct 25, 2022 @ 11:47
    Frederik T
    0

    Sorry for bumping my own thread, but it's just strange to me that Examine has no built-in method of handling basic umbraco tag data types. There is no way I am the only one struggling with this on an Umbraco 9+ website.

Please Sign in or register to post replies

Write your reply to:

Draft