U4-2676 - implement ISearchableTree to abstract search for each tree into it's own logic

Created by Shannon Deminick 21 Aug 2013, 02:54:00 Updated by Shannon Deminick 31 Jul 2017, 05:07:27

Tags: PR Community Contrib

Is duplicated by: U4-8449

Relates to: U4-2857

Relates to: U4-3988

Relates to: U4-8449

Subtask of: UAASSCRUM-964

The interface Umbraco.Web.Trees.ISearchableTree is

    public interface ISearchableTree
        /// <summary>
        /// The alias of the tree that the <see cref="ISearchableTree"/> belongs to
        /// </summary>
        string TreeAlias { get; }

        /// <summary>
        /// Searches for results based on the entity type
        /// </summary>
        /// <param name="query"></param>
        /// <param name="totalFound"></param>
        /// <param name="searchFrom">
        /// A starting point for the search, generally a node id, but for members this is a member type alias
        /// </param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null);

This returns a list of SearchResultItem

    public class SearchResultItem : EntityBasic
        /// <summary>
        /// The score of the search result
        /// </summary>
        [DataMember(Name = "score")]
        public float Score { get; set; }

which is used to populate the search results when searching in the back office.

The any tree is allowed to be searched in the back office will implement this interface.

Overriding implementations

On ApplicationStarting you can replace the core implementations with your own using SearchableTreeResolver.Current , for example:

//remove the default content one (which is the content tree)
//add your custom one - this would need to return the same tree alias as the content one


Shannon Deminick 16 Sep 2013, 13:18:30

I've created a search task for v7.0: http://issues.umbraco.org/issue/U4-2857

Shannon Deminick 25 May 2016, 13:33:14

NOTE: This is tagged for v8 but should be developed on a branch from dev-v7 since we can include in 7.x

Darren Ferguson 28 May 2016, 09:10:57

@Shandem Please take a look at: https://github.com/darrenferguson/Umbraco-CMS/commit/d9af403cf0ce04064963495f05b04593b6e0d1ac

I have the first two "simple changes" running, but I'm not 100% sure on what/how the next two changes work.

I also had to tweak your interface and SearchResultItem class a bit, so I'd appreciate feedback.

Can you spare a few minutes on skype next week - to speak about the Search controller and angular changes?

Shannon Deminick 16 Nov 2016, 09:44:59

PR: https://github.com/umbraco/Umbraco-CMS/pull/1537

Adam Peter Nielsen 17 Nov 2016, 13:57:54

An increasing number of clients are asking: "why can't we tag our images and search for the tags in the backoffice?". I guess overriding ISearchableTree this + an Umbraco.Tags property editor on the image media type should do the trick then?

Shannon Deminick 21 Nov 2016, 11:13:50

@adampnielsen I suppose that is one solution but if you feel that the default back office search should be enhanced then please create a separate issue for this with some details about what you'd like to see and how it would work. Thanks!

Shannon Deminick 20 Jul 2017, 13:05:23

PR: https://github.com/umbraco/Umbraco-CMS/pull/2063

To Test:

  • Ensure everything builds
  • Review the code to make sure there's nothing obviously wrong
  • Create a bunch of stuff of different types that implement ISearchableTree that start with the word "Test" like Content, Media, Document/Media types, Data Types, Templates and you'll see that the search result will return all of these things :)

Stephan 28 Jul 2017, 10:48:10

builds, could upgrade from 7.6, could search for searchable items, code looks good, merging

Stephan 28 Jul 2017, 12:11:06

Re-opening: I merged dev-v7.7 into the user groups branch and it turns out we have various issues with start nodes, with the Lucene queries, etc - working on it

Stephan 28 Jul 2017, 12:31:20

Uh... ISearchableTree is implemented by ''controllers'' and the SearchableTreeResolver will instanciate one of each when it resolves the searchable trees... capturing all the stuff that a controller manages, once and for ever - so when the controller does

return _treeSearcher.ExamineSearch(Umbraco, ...);

the 'Umbraco' object there is going to be the same for all users, thus creating confusion with start nodes etc - this is bad - if the ISearchableTree is implemented by things that are going to be cached, then the interface cannot depend on anything non-static.

Stephan 28 Jul 2017, 12:51:24

please review commit [19d55c8d|https://github.com/umbraco/Umbraco-CMS/commit/19d55c8df0e6827a5c856f1f0d5d0b4ed76d13e5] that should fix the issue with capturing the Umbraco helper (and the current user) + fix the issue with multiple start nodes.

Stephan 28 Jul 2017, 12:53:57

if ok with you, then I'm ok to merge

Shannon Deminick 31 Jul 2017, 05:07:21

Good catch. I've updated things differently:

  • Changed SearchableTreeResolver to be ObjectLifetimeScope.HttpRequest so a new instance will be created each request which means it will not hang on to stale data or the current user
  • Reverted the ISearchableTree interface method to not have to have an UmbracoHelper passed in - since this should be part of the implementation (ctor)
  • Removes the use of ApplicationContext.Current singleton

see: cc8adae593b9048e091c22266ae2ac8647cbff8f

Priority: Normal

Type: Feature (request)

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 7.7.0

Sprint: Sprint 64

Story Points: 3