Re: [SolrNet] Asp.net MVC 4 and SolrNet begining with simple query

907 views
Skip to first unread message

Mauricio Scheffer

unread,
Apr 2, 2014, 12:10:32 PM4/2/14
to sol...@googlegroups.com
Hi Daniel,

You don't need all those NuGet packages, they just integrate SolrNet with other libraries. SolrNet.StructureMap integrates SolrNet with StructureMap, and so on.

As explained in https://github.com/mausch/SolrNet/blob/master/Documentation/README.md#downloads , it's currently recommended to get the latest binaries directly from the build server instead.
As explained in https://github.com/mausch/SolrNet/blob/master/Documentation/Initialization.md , Startup.Init should be called at application startup. You'll get an error if you run this in each request.
As explained in https://github.com/mausch/SolrNet/blob/master/Documentation/Fluent-API.md#querying , the static "Solr.Query<T>(...)" is deprecated, I don't recommend using it.
I recommend using the sample web application ( https://github.com/mausch/SolrNet/blob/master/Documentation/Sample-application.md ) for guidance for your own application.

Also check out the FAQ ( https://github.com/mausch/SolrNet/blob/master/Documentation/FAQ.md ) for some common mistakes when starting out with Solr and SolrNet.

Cheers,
Mauricio


On Tue, Apr 1, 2014 at 5:47 AM, Daniel K. Rudolf <daniel....@gmail.com> wrote:
Hello to all, I am new in SolrNet and I whant to built web application that shows some results from Solr, and I have some trouble to do it.

Ok, let's go. I whant to create web application with asp.net MVC 4 that shows (query) all "customer" from my Solr.

First I have open new Visual Studio 2012 project for MVC 4 - Empty solution and name it TestSolr.

Second I have tru Package Manager Console instal next packages:
  • SolrNet (core library)
  • SolrNet.Windsor
  • SolrNet.StructureMap
  • SolrNet.Ninject
  • SolrNet.Unity
  • SolrNet.Autofac
  • SolrNet.NHibernate
Third I have create new Models and name it "Poskus" and write code below:

using SolrNet.Attributes;

namespace TestSolr.Models
{
    public class Poskus
    {

        [SolrField("customer")]
        public string Customer { get; set; }

    }
}

Forth I have create new Controller with name "PoskusSolrController" and write code below:

using System.Web.Mvc;
using SolrNet;
using SolrNet.DSL;
using TestSolr.Models;

namespace TestSolr.Controllers
{
    public class PoskusSolrController : Controller
    {
        //
        // GET: /PoskusSolr/
        
        public ActionResult Index()
        {
            Startup.Init<Poskus>("http://servicemix01...msglog_pilot");

            var pos1 = Solr.Query<Poskus>(new SolrQueryByField("name", "customer"));

            return View(pos1);
        }

    }
}

Fifth I have create View with name "Index" and write code below:

@model IQueryable<TestSolr.Models.Poskus>
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

@foreach (var item in Model)
{
    <div>
        <div>@item.Customer</div>
    </div>
}

-----------------------
Now, this code is not working correctly. The error pops up in this line of code: var pos1 = Solr.Query<Poskus>(new SolrQueryByField("name", "customer")); the error is: NullReferenceException was unhandled by code. 

Realy need help here, some sugestions, links, similar experience... realy thanks for help,

Daniel 







--
You received this message because you are subscribed to the Google Groups "SolrNet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to solrnet+u...@googlegroups.com.
To post to this group, send email to sol...@googlegroups.com.
Visit this group at http://groups.google.com/group/solrnet.
For more options, visit https://groups.google.com/d/optout.

Daniel K. Rudolf

unread,
Apr 3, 2014, 1:45:22 AM4/3/14
to sol...@googlegroups.com
Hi, Mauricio,

I very much appreciate your help. 

Cheers, Daniel

Daniel K. Rudolf

unread,
Apr 3, 2014, 3:07:37 AM4/3/14
to sol...@googlegroups.com
Hi, again,

So if I understand correctly in this line of code:

private static readonly string solrURL = ConfigurationManager.AppSettings["solrUrl ... <= here I put url of "http://servicemix..."]; <= tis line

        protected void Application_Start() {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(Server.MapPath("/"), "log4net.config")));

            RegisterRoutes(RouteTable.Routes);

            var connection = new SolrConnection(solrURL);
            var loggingConnection = new LoggingConnection(connection);
            Startup.Init<Product>(loggingConnection);
        }

Mauricio Scheffer

unread,
Apr 3, 2014, 10:53:21 AM4/3/14
to sol...@googlegroups.com
See http://stackoverflow.com/questions/7069911/how-to-use-the-configurationmanager-appsettings .

Please ask any generic questions about .NET in Stackoverflow or other similar forums. This mailing list is for questions about SolrNet.

Cheers



--
Mauricio
Reply all
Reply to author
Forward
0 new messages