I have configured my solrconfig.xml and schema.xml to query for the suggestions.
I am able to get the suggestions from the url
http://localhost:8080/
I had the exact same requirement but could not find any way to easily handle Suggester results with SolrNet. Unfortunately, SolrNet seems to be built around the default /select
request handler and does not currently support any other handler including /suggest
for object type mappings (T
). It expects all mappings to occur with indexed Solr document results and not suggester results.
Hence, @Paige Cook's answer did not work for me. T
type with mappings is not compatible with a suggester results response. All the standard plumbing code from initializing the request (Startup.Init
) to querying (ISolrQueryResults
) needs a mapped Solr document type and not a simple array of strings which the suggester provides.
Therefore, (similar to @dfay) I went with making a web request and parsing out the suggested results from the XML web response. The SolrConnection
class was used for this:
string searchTerm = "ha";
string solrUrl = "http://localhost:8080/solr/collection1";
string relativeUrl = "/suggest";
var parameters = new Dictionary
{
{"q", searchTerm},
{"wt", "xml"},
};
var solrConnection = new SolrConnection(solrUrl);
string response = solrConnection.Get(relativeUrl, parameters);
// then use your favorite XML parser to extract
// suggestions from the reponse string
Alternatively, instead of XML, the request can return a JSON response using the wt=json
parameter:
var parameters = new Dictionary
{
{"q", searchTerm},
{"wt", "json"}, // change this!
};
// then use your favorite JSON parser