Skip to content

Instantly share code, notes, and snippets.

@PaulSorensen
Created October 2, 2013 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulSorensen/6792009 to your computer and use it in GitHub Desktop.
Save PaulSorensen/6792009 to your computer and use it in GitHub Desktop.
SolrNet autosuggest query
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