Last active
March 1, 2016 03:45
-
-
Save RyanABailey/8f0aa4850c7fd427e896 to your computer and use it in GitHub Desktop.
Lucene search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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