London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

EPiServer Search - Can't resolve symbol error

Vote:
 

I have copy pasted following code from the EPiServer 7 CMS SDK Documentation:

SearchResults results = Locate.SearchHandler().GetSearchResults(groupQuery, pagingNumber, pagingSize);

        ContentSearchHandler contentSearchHandler = Locate.ContentSearchHandler();
        foreach (var hit in results.IndexResponseItems)
        {
            // Use the content search handler to convert the page hit into a PageData
            yield return contentSearchHandler.GetContent<PageData>(hit);
        }

And I can't resolve the text marked in bold.
Which assembly to I need to add to my references or what namespace should I add?

Thank you in advance!
#65870
Feb 12, 2013 20:37
Vote:
 

Hi Daniel,

The Locate is a instance of the ServiceLocator and is a property inherited from the PageBase class I think.

#65874
Edited, Feb 13, 2013 9:10
Vote:
 

Hi Daniel

I don't see what part is in bold but I was able to get the code from the EPiServer 7 CMS Documentation to work by replacing

ContentSearchHandler contentSearchHandler = Locate.ContentSearchHandler();

with

var serviceLocationHelper = ServiceLocator.Current.GetInstance<ServiceLocationHelper>();
var contentSearchHandler = serviceLocationHelper.ContentSearchHandler();



#65882
Feb 13, 2013 12:43
Vote:
 

Hi,


In addition, instead of locating the ServiceLocationHelper, which is a class that contains common shortcuts to the ServiceLocator, and retrieving the search handler from there, you can fetch the search handler directly from the ServiceLocator:

var contentSearchHandler = ServiceLocator.Current.GetInstance<ContentSearchHandler>();

#65890
Feb 13, 2013 14:11
Vote:
 

Great Joel, thanks!

#122166
May 27, 2015 13:43
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.