Copied to clipboard

Flag this post as spam?

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


  • Edgar Rasquin 326 posts 925 karma points
    Jan 26, 2017 @ 13:15
    Edgar Rasquin
    2

    Backoffice Search

    Hi there,

    I am wondering if there is a quick guide on how to extend the Backoffice Search in that manner that custom fields are included. I have browsed the Umbraco forum for quite a while now, but have not found an appropriate answer.

    Problem: I get search results searching for the name: enter image description here

    But do not get results searching for my custom field "code": enter image description here

    I already tried to make changes in the ExaminSettings.config so that the field gets indexed:

    <IndexSet SetName="InternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Internal/">
    <IndexUserFields>
      <add Name="code" />
    </IndexUserFields>
    

    and somehow umbraco knows about the existance of the value:

    enter image description here

    but how can I get it to show the node in the result list?

    I have come accross the Examining Examine page about a dozen times by now but, please correct me if I'm wrong, it seems a little over the top for my purpose.

    Can anybody help me out?

    Thanks

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 26, 2017 @ 13:40
    Dirk De Grave
    0

    Hi,

    Backoffice search will only search based on name (node name), so no, ootb, the search won't help you, even if you've added those fields to the index.

    But, there's always an extension point, albeit not that straightforward.

    Basically, you'll have to intercept the current api call and replace it with your own api call. As long as you return the same return value, you'd only need to intercept the call and use your own. I'll see if I can dig up that intercept example.

    --Dirk

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 26, 2017 @ 13:45
    Dirk De Grave
    101

    Hi,

    Here it goes:

    //Just in case you'd only want to change the search algorithm but keep the current search results presentation, in which case you'do need no custom view
    angular.module("umbraco.services").config(["$httpProvider", function ($httpProvider) {
        $httpProvider.interceptors.push(function ($q) {
            return {
                'request': function (request) {
                    //Redirect any requests for the search engine to our own Solr search engine
                    if (request.url.startsWith("/umbraco/backoffice/UmbracoApi/Entity/SearchAll")) {
                        var query = request.url.split("?")[1].split("=")[1];
                        //console.log("query=" + query);
                        request.url = "/umbraco/backoffice/X/Api/SearchAll?query=" + query;
                    }
                    return request || $q.when(request);
                }
            };
        });
    }]);
    

    Only thing left is to create a XApiController, with a SearchAll(string query) function and perform your advanced Examine query to fetch the results

    Here's what umbraco does when performing the search: https://github.com/umbraco/Umbraco-CMS/blob/b260f6c6dedc6c8c123de5f2348b4d7f0dcb51bd/src/Umbraco.Web/Editors/EntityController.cs#L97

    The idea is to return IEnumerable<EntityTypeSearchResult> from your own method and it should work.

    --Dirk

  • Edgar Rasquin 326 posts 925 karma points
    Jan 26, 2017 @ 15:46
    Edgar Rasquin
    0

    Thank you very much for your approach. I will give it a try.

Please Sign in or register to post replies

Write your reply to:

Draft