1

I have a contribution folder with items on my sitecore website. I had to manually map the displayname to the items in my HttpRequestProcessor resolvers.

However, I would like to confirm there is no other (easier) way to process, such as telling sitecore to automatically get an item either by its name or its display name for an item which is outside of the "Home" folder.

To give you a better idea of what im currently doing : In my Resolver, I retrieve the item name from the URL, I check if UseDisplayName is enabled and if so, I do a Solr request with looking for either the Name or the Item name, otherwise I only search for the name.

If i get a result, I set my Context.Item

Is there any kind of magic to make this easier ? :) Thank's you

9
  • So with the current implementation if a user makes a request to baseUrl/some/path/dispName then they'll get the item dispName no matter where it exists if UseDisplayName is enabled?
    – Teeknow
    Aug 22, 2017 at 14:00
  • If the contribution folder is always at the same path and all the sites have access to it, you can easily hard code the path of the container or read it from a custom config file and then search within the container if the item is present. Then you may cache that request for performance. Aug 22, 2017 at 21:31
  • @Teeknow that's right, i don't like it at all but that's the first thing that came to my mind. Im not sure how I should "iterate" the tree based on the path. Ideally, I should look for all the subpath in the path and check if dispName is inside path, if path in inside some etc... while making sure we check for the displayName for each of them. It seems to be a bit complex and that is why I would like to let Sitecore do the work
    – TeKilla
    Aug 23, 2017 at 8:23
  • @HishaamNamooya I can't hardcode it because my Contribution folder hold other folder for each type of items and some of them can have differents structures.
    – TeKilla
    Aug 23, 2017 at 8:23
  • 1
    You need to fetch the container item via the path. Once you get the item, you can get the sub items using the axes.getdescendants and then perform a search on the list where the display name or name is equals to the value Aug 23, 2017 at 9:56

1 Answer 1

1

If the contribution folder is always at the same path and all the sites have access to it, you can easily hard code the path of the container or read it from a custom config file and then search within the container if the item is present. Then you may cache that request for performance.

By hard coding, I mean that you can hardcode the parent path only. Then you fetch the item to get the descendants. Example:

var contributionContainer = Factory.GetDatabase("web").GetItem("path to contribution container", Sitecore.Context.Language);

var contextItem = contributionContainer.Axes.GetDescendants().FirstOrDefault(w => w.Name.Equals("your item name from url") || w.DisplayName.Equals("your item name from url"));

Note that I have pass the language as parameter so that it fetches only items where the context language is available.

When using solr, you are already improving the performance but you need to make sure that the query you are performing is not resource intensive. You will need to add the Language filter in the query.

For performance gain, the flow will be as follows

  1. Query the index first.

  2. If result is not available/empty/not found, check the cache.

  3. If item is not found from cache, query database.

  4. Once the result is obtained, you need to cache the result so that next time when steps 3 is executed, it will get it from the cache. Make use of server cache instead of Sitecore cache as the Sitecore cache will get cleared after publishing

3
  • This won't work for anthing less that one level deep. You need to split on / and check each part separately, which makes is more intensive, much more so than the solr option.
    – jammykam
    Aug 23, 2017 at 15:14
  • @jammykam you're right. Fetching from the database itself will be resource intensive. But this will act as a fallback if the name is not retrieved from the index. Moreover, if the query is done on the database, to gain in performance, the response can be cached at server level Aug 23, 2017 at 21:58
  • 1
    *by less I meant more :D It's actually the same as what the Sitecoe ItemResolver is also doing anywa tbf. Personally, I would index the AbsolutePath and then it's a very simple index query and will actually be faster than Sitecore code.
    – jammykam
    Aug 23, 2017 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.