Copied to clipboard

Flag this post as spam?

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


  • Kris Janssen 210 posts 568 karma points c-trib
    Feb 27, 2017 @ 19:51
    Kris Janssen
    0

    Listing site members in views - don't use MemberService?

    Hi,

    I am running some sites where team members are 'members' and where we would like to list these members and e.g. their bio on a web facing page.

    I am currently doing this by referencing the MemberService.

    However, there is mention of such a thing in the 'pitfalls' sections in the docs.

    The Services layer of Umbraco is for manipulating the business logic of Umbraco directly to/from the database. None of these methods should be used within your views and can have a very large impact on performance and stability of your application.

    However, MembershipHelper or UmbracoHelper only allow one to query singular users bij some kind of property such as ID or Email...

    So what to do here if I want fast, reliable access to all users, just like I could with cached content?

  • Dennis Adolfi 1055 posts 6229 karma points MVP c-trib
    Feb 28, 2017 @ 07:26
    Dennis Adolfi
    1

    Hi Kris.

    You can use Examine for listing you members.

    Here is an example of how to list all members. (You probobly want to set up your own ExamineIndex instead of using the InternalMember index, but you get the idea. More on setting up your own indexes and searchers here: https://our.umbraco.org/documentation/reference/searching/examine/.)

    @using UmbracoExamine
    
    @{
        var searcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];
        var criteria = searcher.CreateSearchCriteria(IndexTypes.Member);
        var searchResults = searcher.Search(criteria.SearchIndexType, true);
    }
    
    @foreach (var item in searchResults)
    {
        <span>@(item.Fields["email"])</span>
    }
    

    Best of luck!

  • Kris Janssen 210 posts 568 karma points c-trib
    Feb 28, 2017 @ 09:21
    Kris Janssen
    1

    Excellent, that indeed seems to be the solution.

    You'd be surprised how many online resources abuse the services layer for this :)

  • Kris Janssen 210 posts 568 karma points c-trib
    Feb 28, 2017 @ 10:22
    Kris Janssen
    0

    Actually one thing that I was wondering about when implementing this:

    If I create my own indexes (e.g. external member searcher), I assume I can index only 'members'.

    Why then, when creating search criteria, I still need to specify :

    var criteria = searcher.CreateSearchCriteria(IndexTypes.Member);
    

    When I am already using my member specific 'Searcher'?

    The effect of specifying IndexTypes.Member seems to be that way down in the inner workings of the search mechanism a 'MUST' condition is added for the string 'member' and indeed, the string member is all over the relevant index files in the filesystem.

    Still, if the searcher only indexes members in the first place, why is this necessary as opposed to just searching the equivalent of '*'.

    Don't know if this question makes sense :)

  • Dennis Adolfi 1055 posts 6229 karma points MVP c-trib
    Feb 28, 2017 @ 10:01
    Dennis Adolfi
    0

    Perfect! Glad I could help you Kris! :)

    Have a great day!

  • Jeroen Breuer 4860 posts 12127 karma points MVP 3x admin c-trib
    Feb 28, 2017 @ 10:18
    Jeroen Breuer
    2

    Examine is perfect for this, but there should still be a better API for this:

    This is the original feature request: http://issues.umbraco.org/issue/U4-4379

    This is the improvement: http://issues.umbraco.org/issue/U4-6368

    Jeroen

  • Kris Janssen 210 posts 568 karma points c-trib
    Feb 28, 2017 @ 10:28
    Kris Janssen
    0

    It would certainly make things somewhat more consistent given the relatively ease of access to content nodes.

    Lucene is very nice and powerful it seems but for proper use, requires quite some setup and a good helping of 'you really must know what you're doing' :)

Please Sign in or register to post replies

Write your reply to:

Draft