1

I'm generating a custom sitewide search by indexing the rendered HTML of the pages on my site.

Some pages will have a title and description field defined to display in the results, however, some wont and would benefit from using the indexed content to display a snippet of the search result.

is there a way to append the page content via glass mapper, that is, on item creation glass mapper binds the corresponding document in the index to the generated object?

One solution would be to create a custom mapper that inserts the indexed field. Unfortunately, Im unsure how to access the corresponding lucene document from the item.

2
  • So you are bringing in data from an external index that is nothing to do with the Sitecore item and trying to add that to your Glass model?
    – Richard Seal
    Jan 22, 2019 at 18:54
  • yep that's the idea.
    – Adam Hess
    Jan 23, 2019 at 21:50

1 Answer 1

2

I'd be reluctant to use a custom mapper to insert this indexed content for each item because it would affect the performance of every item's creation (and therefore your entire site).

Instead, although it's not automatic, I'd recommend the following approach:

Add your "fallback" logic at the business/service layer instead

var currentPage = mySitecoreContext.GetCurrentItem<IMyModel>();
string pageTitle = currentPage.Title;
if (string.IsNullOrEmpty(pageTitle))
{
    // execute a search for (x => x.Id = currentPage.Id) and get the indexed field's value
}
1
  • I eventually opted for this and am ultimately going to use a provider framework seen in habitat.
    – Adam Hess
    Jan 23, 2019 at 21:52

Your Answer

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

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