How can I convert Examine search results into a IPublishedContent collection
I'm trying to create a simple search results page for my site. I have some test code to get some search only the node title:
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var searchCriteria = Searcher.CreateSearchCriteria(BooleanOperation.Or);
var query = searchCriteria.Field("nodeName", "blog").Compile();
var searchResults = Searcher.Search(query);
This works, but it's returning an Examine data type (ISearchResults)
I'd like to convert it to IPublishedContent so that I can work with it Umbraco objects, instead of just the list of fields returned in ISearchResults.
If you're dealing with media, something like this:
private IPiblishedContent ConvertToViewModel(SearchResult x)
{
switch (x.Fields["__IndexType"])
{
case "content":
return Umbraco.TypedContent(x.Id);
case "media":
return Umbraco.TypedMedia(x.Id);
default:
throw new ArgumentException($"Index Type of '{x.Fields["__IndexType"]}' not recognised");
}
}
How can I convert Examine search results into a IPublishedContent collection
I'm trying to create a simple search results page for my site. I have some test code to get some search only the node title:
This works, but it's returning an Examine data type (ISearchResults)
I'd like to convert it to IPublishedContent so that I can work with it Umbraco objects, instead of just the list of fields returned in ISearchResults.
Is that possible?
try this:
I recommend the Paul Seal tutorial, it's very good
http://www.codeshare.co.uk/blog/how-to-search-by-document-type-and-property-in-umbraco/
If you're dealing with media, something like this:
is working on a reply...