Copied to clipboard

Flag this post as spam?

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


  • Roger 19 posts 57 karma points
    Oct 20, 2015 @ 16:26
    Roger
    0

    Umbraco 7 BackOffice Member Search By Custom Properties

    Hi All!

    Hope everyone is doing well! Just a quick question regarding BackOffice search in Umbraco 7 : we have a site with a lot of members with a few custom (text) properties we'd like to search by.

    We've updated the InternalMemberIndexer to add these fields, and can see them in the index set using Luke.

    However, in Umbraco's back office, we seem to only be able to find members by the 'native' umbraco fields (loginName, email etc)

    Does anyone know if it's easy to include these custom fields in the backoffice Umbraco member search? (we're keen to know if it can be done using the existing search that comes with Umbraco if possible)

    No worries if not, but thought I'd ask the question in case there was a quicker way than having a custom dashboard control.

    Thanks for your help!

    Kind regards,

    Roger Davies

  • claje 1 post 21 karma points
    Jan 11, 2016 @ 08:01
    claje
    0

    Hi

    Having the exact same problem - anyone knows if this is possible?

    Best Regards

    Claus

  • Angelo 87 posts 188 karma points
    May 02, 2016 @ 20:07
    Angelo
    0

    Hello Claje did you find any solution on this ?

    thank you

    Angelo

  • Marc Goodson 1203 posts 8073 karma points MVP 5x c-trib
    May 05, 2016 @ 12:17
    Marc Goodson
    0

    I just looked through the source code, and eventually the search makes a call in the EntityController to this ExamineSearch function, and if it's a member search the fields searched are hardcoded to be:

        fields = new[] { "id", "__NodeId", "email", "loginName"};
    

    eg:

    private IEnumerable<EntityBasic> ExamineSearch(string query, UmbracoEntityTypes entityType, string searchFrom = null)
            {
                var sb = new StringBuilder();
    
                string type;
                var searcher = Constants.Examine.InternalSearcher;            
                var fields = new[] { "id", "__NodeId" };
    
                //TODO: WE should really just allow passing in a lucene raw query
                switch (entityType)
                {
                    case UmbracoEntityTypes.Member:
                        searcher = Constants.Examine.InternalMemberSearcher;
                        type = "member";
                        fields = new[] { "id", "__NodeId", "email", "loginName"};
                        if (searchFrom != null && searchFrom != Constants.Conventions.MemberTypes.AllMembersListId && searchFrom.Trim() != "-1")
                        {
                            sb.Append("+__NodeTypeAlias:");
                            sb.Append(searchFrom);
                            sb.Append(" ");
                        }
                        break;
    

    so this is why the custom fields aren't searched, and there doesn't currently appear to be an option to configure this

    I have created a 'feature request' for this functionality which you can vote for / comment on if you would find this kind of change useful :

    http://issues.umbraco.org/issue/U4-8417

  • keilo 562 posts 1017 karma points
    Apr 26, 2017 @ 16:03
    keilo
    0

    Im running 7.5.9 and found out the hard way that its indeed hardcoded.

    Doesnt seem to be in 7.6 either...

  • David Armitage 347 posts 1373 karma points
    Aug 30, 2017 @ 09:54
    David Armitage
    0

    Hi,

    Is there any news on this?

    I have a lot of member profiles which are searchable by the front-end based on text fields and other types of fields.

    Is this thread saying that its just not possible to search members based on any other fields apart from the Umbraco defaults?

    Very frustrating if so.....

    I literally just re-coded a big project to use Umbraco's member stuff. Previously I was just using standard DocTypes as member profiles and linking then back to a Umbraco member object.

    I assumed this was bad practice and now finding out members are not searchable????

    Anyone got any help with this. A lot of re-work for me to do if not :(

    Kind Regards

    David

  • David Armitage 347 posts 1373 karma points
    Aug 31, 2017 @ 04:13
    David Armitage
    3

    Hi Guys,

    I got examine searching working on the members. I had to create a custom indexer & searcher.

    Here is what I did.

    First - I create a new IndexSet within the ExamineIndex.config.

    <IndexSet SetName="ExternalMemberIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/ExternalMember/" />
    

    Second - I created a new Indexer within the ExamineSettings.config. This needs adding within ExamineIndexProviders/providers.

     <add name="ExternalMemberIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine" supportUnpublished="true" supportProtected="true" />
    

    Third - I created a new Searcher within the ExamineSettings.config. This needs adding within ExamineSearchProviders/providers.

    <add name="ExternalMemberSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" analyzer="Lucene.Net.Analysis.KeywordAnalyzer, Lucene.Net" indexSets="ExternalMemberIndexSet"/>
    

    NOW YOU SHOULD BE ABLE TO SEARCH CUSTOM FIELDS!!!


    Here is an example of one of my simple member searches.

    var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["ExternalMemberSearcher"];
    var criteria = searcher.CreateSearchCriteria(BooleanOperation.And);
    criteria.NodeTypeAlias("companyProfile").And();
    
    if (search.Display != null)
    {
        criteria.Field("display", search.Display.Value ? "1" : "0").And();
    }
    
    if (search.Active != null)
    {
        criteria.Field("active", search.Active.Value ? "1" : "0").And();
    }
    
    if (search.Validated != null)
    {
        criteria.Field("validated", search.Active.Value ? "1" : "0").And();
    }
    
    if (search.IsEmployer != null)
    {
        criteria.Field("isEmployer", search.IsEmployer.Value ? "1" : "0").And();
    }
    
    if (search.IsAgency != null)
    {
        criteria.Field("isAgency", search.IsAgency.Value ? "1" : "0").And();
    }
    
    if (search.IsServiceProvider != null)
    {
        criteria.Field("isServiceProvider", search.IsServiceProvider.Value ? "1" : "0").And();
    }
    
    if (search.Keywords != null && search.Keywords.Count > 0)
    {
        var searchTerms = search.Keywords.Select(x => x.Fuzzy());
        criteria.GroupedOr(new[] { "companyName", "summary", "details1","details2","details3" }, searchTerms.ToArray()).And();
    }   
    
    var searchResults = searcher.Search(criteria);
    

    Hope this helps someone. It look we a while to figure out.

    Kind Regards

    David

  • Satpal Gahir 18 posts 88 karma points
    Mar 20, 2018 @ 23:41
    Satpal Gahir
    0

    I dont think David's solution is correct here. It will work for a front end, but not the umbraco back office.

    I've tried to add more attributes to the ExamineSettings.config and ExamineIndex.config, when i test the the indexer on the back office, it gets results, but when I try to use the umbraco member searcher, it doesnt bring back any results.

    It looks like the code for MemberSearch.ascx.cs needs to be amended. How do i go abouts doing that?

    Has anyone got this working?

  • Satpal Gahir 18 posts 88 karma points
    Mar 20, 2018 @ 23:59
    Satpal Gahir
    0

    I'm not sure I understand this:

    http://issues.umbraco.org/issue/U4-2676

    seems to be the recommended way to implement extending the backoffice search. so we'll have to intercept the search somewhere.

  • Simon steed 357 posts 665 karma points
    Mar 21, 2018 @ 09:07
    Simon steed
    0

    Satpal - Yes Davids code is for front end, thats the easy bit. To override the back office, as you've found you need to use ISearchableTree, however finding documentation or examples for it is very hard.

    I did try it a few weeks back but gave up so would welcome any examples you find so we can work out how to do it :)

    Si

  • Salomons 11 posts 102 karma points
    Sep 13, 2018 @ 09:03
    Salomons
    0

    The example here http://issues.umbraco.org/issue/U4-2676 is only for the three searcher enter image description here

    The members are also shown in this tree searcher, custom properties can be searched in a custom tree searcher class.

    You have to implement the ISearchableTree interface something like this:

    public class MemberTreeController : Umbraco.Web.Search.ISearchableTree
        {
    
            public string TreeAlias
            {
                get
            {
                return "member";
            }
        }
    
    
        public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
        {
            // MemberTreeController
            //public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
            //{
            //  return _treeSearcher.ExamineSearch(Umbraco, query, UmbracoEntityTypes.Member, pageSize, pageIndex, out totalFound, searchFrom);
            //}
    
            // Normaly this is done by UmbracoTreeSearcher.ExamineSearch
    
            var searcher = Constants.Examine.InternalSearcher;
            var internalSearcher = ExamineManager.Instance.SearchProviderCollection[searcher];
            var raw = internalSearcher.CreateSearchCriteria().RawQuery(query);
            var result = internalSearcher.Search(raw, Convert.ToInt32(pageSize * (pageIndex + 1)));
    
            totalFound = result.TotalItemCount;
    
            var pagedResult = result.Skip(Convert.ToInt32(pageIndex));
    
    
            return MemberFromSearchResults(pagedResult.ToArray());
    
        }
    

    Then in the ApplicationStarted event you can disable the default ISearchableTree controller

     public class RegisterEvents : ApplicationEventHandler
        {
    
            protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                base.ApplicationStarting(umbracoApplication, applicationContext);
            }
    
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                base.ApplicationStarted(umbracoApplication, applicationContext);
    
                //remove the default content one (which is the content tree)
                SearchableTreeResolver.Current.RemoveType<Umbraco.Web.Trees.MemberTreeController>();
    }
    }
    
  • Simon steed 357 posts 665 karma points
    Sep 13, 2018 @ 09:13
    Simon steed
    0

    Thank you Solomon for taking the time to post this. I've not had any time to look further but will give you code a go - the missing part for me I think was registering the events, sort of makes sense now doh!

  • John Churchley 272 posts 1256 karma points c-trib
    Oct 13, 2018 @ 08:00
    John Churchley
    0

    Hi,

    I'm trying to do something similar but with a custom section (so not using Examine). Would you be able to share the MemberFromSearchResults method?

  • Tajamal 64 posts 152 karma points
    Oct 01, 2019 @ 13:01
    Tajamal
    0

    Hi Salomons

    Could please share the MemberFromSearchResults code with us?

    Do I need to add my own interface as its referenced to Umbraco.Web.Search.ISearchableTree ?

    My umbraco versiom i am using. Umbraco version 7.3.7

Please Sign in or register to post replies

Write your reply to:

Draft