You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by danielkrudolf <da...@gmail.com> on 2014/04/01 11:30:28 UTC

Asp.net MVC 4 and Solr Query Begining

Hello to all, I am new in Solr, but I see it si very usable. So I whant to
build web application with asp.net MVC 4 that shows query from Solr. 

Ok, let's go so far i have done this:

1) Open new project in Visual Studio 2012 and create new MVC 4 project
(Empty solution).

2) In Package Manager Console I have Install next packages:
/SolrNet (core library)
SolrNet.Windsor
SolrNet.StructureMap
SolrNet.Ninject
SolrNet.Unity
SolrNet.Autofac
SolrNet.NHibernate/

3) I create new Model class with name "Poskus" and write this code:
using SolrNet.Attributes;

/namespace TestSolr2.Models
{
    public class Poskus
    {

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

    }
}/

4) Next I have create new Controller with name "PoskusSolr" and write this
code:

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

namespace TestSolr.Controllers
{
    public class PoskusSolrController : Controller
    {
        //
        // GET: /PoskusSolr/
        
        public ActionResult Index()
        {

            try
            {
                var connection = new
SolrConnection("http://servicemix/.../msglog_pilot");
                Startup.Init<Poskus>(connection);

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

                return View(pos1);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
            return View();
        }   
    }
}/

5) And finaly I have create View (Index) 

So far I put this:

/@model TestSolr.Models.Poskus
@{
    ViewBag.Title = "Index";
}

Index
/

---------------------------------------------
Now, this code does not work, it not returns customers from my Solr databse.
Any sugestions, ideas, links to make this work. Realy, realy thanks for
help.

Daniel




--
View this message in context: http://lucene.472066.n3.nabble.com/Asp-net-MVC-4-and-Solr-Query-Begining-tp4128372.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Asp.net MVC 4 and Solr Query Begining

Posted by danielkrudolf <da...@gmail.com>.
Nazik thanks for the help, is there similar forums, this one seems that is
not working, I can't post new subject or question. 

Thanks for help.



--
View this message in context: http://lucene.472066.n3.nabble.com/Asp-net-MVC-4-and-Solr-Query-Begining-tp4128372p4128390.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Asp.net MVC 4 and Solr Query Begining

Posted by Nazik <na...@yahoo.com>.
Hi Daniel,

I think you should post this to SOLR.NET google group:

https://groups.google.com/forum/m/#!forum/solrnet

That forum is more appropriate to address  this type of problem.

@Nazik_Huq 


On Apr 1, 2014, at 5:30 AM, danielkrudolf <da...@gmail.com> wrote:

> Hello to all, I am new in Solr, but I see it si very usable. So I whant to
> build web application with asp.net MVC 4 that shows query from Solr. 
> 
> Ok, let's go so far i have done this:
> 
> 1) Open new project in Visual Studio 2012 and create new MVC 4 project
> (Empty solution).
> 
> 2) In Package Manager Console I have Install next packages:
> /SolrNet (core library)
> SolrNet.Windsor
> SolrNet.StructureMap
> SolrNet.Ninject
> SolrNet.Unity
> SolrNet.Autofac
> SolrNet.NHibernate/
> 
> 3) I create new Model class with name "Poskus" and write this code:
> using SolrNet.Attributes;
> 
> /namespace TestSolr2.Models
> {
>    public class Poskus
>    {
> 
>        [SolrField("customer")]
>        public string Customer { get; set; }
> 
>    }
> }/
> 
> 4) Next I have create new Controller with name "PoskusSolr" and write this
> code:
> 
> /using System;
> using System.Web.Mvc;
> using SolrNet;
> using SolrNet.DSL;
> using TestSolr.Models;
> using SolrNet.Impl;
> 
> namespace TestSolr.Controllers
> {
>    public class PoskusSolrController : Controller
>    {
>        //
>        // GET: /PoskusSolr/
> 
>        public ActionResult Index()
>        {
> 
>            try
>            {
>                var connection = new
> SolrConnection("http://servicemix/.../msglog_pilot");
>                Startup.Init<Poskus>(connection);
> 
>                var pos1 = Solr.Query<Poskus>(new SolrQueryByField("name",
> "customer"));
> 
>                return View(pos1);
>            }
>            catch (Exception ex)
>            {
>                string error = ex.Message;
>            }
>            return View();
>        }   
>    }
> }/
> 
> 5) And finaly I have create View (Index) 
> 
> So far I put this:
> 
> /@model TestSolr.Models.Poskus
> @{
>    ViewBag.Title = "Index";
> }
> 
> Index
> /
> 
> ---------------------------------------------
> Now, this code does not work, it not returns customers from my Solr databse.
> Any sugestions, ideas, links to make this work. Realy, realy thanks for
> help.
> 
> Daniel
> 
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Asp-net-MVC-4-and-Solr-Query-Begining-tp4128372.html
> Sent from the Solr - User mailing list archive at Nabble.com.