Search code examples
asp.netlucenesolrsolrnet

Solrnet /ASP.NET sample without MVC


I am trying to get a handle on Solrnet and interacting an ASP.NET site with a Solr server. However, the sample app (on the code repository) is MVC based ,does anyone know of a version in plain vanilla ASP.NET?

Thanks


Solution

  • There aren't any major differences really:

    • Initialize the library in your Application_Start() just like in the MVC sample app.
    • The simplest way to use it in a code-behind is to use the service locator to get the main SolrNet interface (e.g. var solr = ServiceLocator.Current.GetInstance<ISolrOperations<MyDocumentClass>>()), (in MVC it's easy to instead inject the interface using an IoC container)
    • Then you can use that instance to run any query you want, update documents, etc. In the MVC sample app a ModelBinder is used to get the search parameters from the querystring, but that's a MVC feature, so getting the search parameters is up to you.
    • Then bind the query results to the page (I mostly use a simple foreach, you could also try ObjectDataSource)