Created
October 2, 2013 10:57
-
-
Save PaulSorensen/6792009 to your computer and use it in GitHub Desktop.
SolrNet autosuggest query
This file contains 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
public string AutoSuggest(string query) | |
{ | |
const int maxResults = 10; | |
const int startpage = 1; | |
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Item>>(); | |
var options = new QueryOptions | |
{ | |
Rows = maxResults, | |
Start = (startpage - 1)*maxResults | |
}; | |
var results = solr.Query(query, options); | |
//Sort products after ProductName ASC and strip ",* | |
var itemList = results.ToList().OrderBy(x => x.ItemName.Replace("\"", "").Replace("*", "")); | |
var result = (from r in itemList | |
where r.ItemName.ToLower().Contains(query.ToLower()) | |
select new {r.ItemName}).Distinct().OrderBy(x => x.ItemName); | |
return result.ToJson(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment