Skip to content

Instantly share code, notes, and snippets.

@RyanABailey
Last active March 1, 2016 03:45
Show Gist options
  • Select an option

  • Save RyanABailey/8f0aa4850c7fd427e896 to your computer and use it in GitHub Desktop.

Select an option

Save RyanABailey/8f0aa4850c7fd427e896 to your computer and use it in GitHub Desktop.
Lucene search
var searchIndex = ContentSearchManager.GetIndex("MySearchIndex"); // Get the search index
var searchPredicate = GetSearchPredicate(searchTerm); // Build the search predicate
using (var searchContext = searchIndex.CreateSearchContext()) // Get a context of the search index
{
var searchResults = searchContext.GetQueryable<SearchModel>().Filter(searchPredicate); // Search the index for items which match the predicate
// This will get all of the results, which is not reccomended
var fullResults = searchResults.GetResults();
// This is better and will get paged results - page 1 with 10 results per page
//var pagedResults = searchResults.Page(1, 10).GetResults();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment