0

I set up a solr server running in Tomcat in machine 192.168.0.113(Centos 5.5). And I deploy a website in matchine 192.168.0.114(Windows server 2003). I use solrnet in matchine 192.168.0.114. The full code like bellow(which have been edited thanks to @Paige Cook):

using System;
using System.Collections.Generic;
using System.Text;
using SolrNet;
using NUnit.Framework;
using SolrNet.Attributes;
using SolrNet.Commands.Parameters;
using Microsoft.Practices.ServiceLocation;
namespace MySolrNet
{
    public class Video
    {
        private string videoid;
        [SolrField("videoid")]
        public string Videoid
        {
            get { return videoid; }
            set { videoid = value; }
        }

        private string videoname;
        [SolrField("videoname")]
        public string Videoname
        {
            get { return videoname; }
            set { videoname = value; }
        }
        private string videoorigin;
        [SolrField("videoorigin")]
        public string Videoorigin
        {
            get { return videoorigin; }
            set { videoorigin = value; }
        }
        public Video(string id, string name, string origin)
        {
            this.Videoid = id;
            this.Videoname = name;
            this.Videoorigin = origin;
        }
        public Video()
        {

        }
        public void FixtureSetup()
        {
            Startup.Init<Video>("http://192.168.0.113:8070/solr");
        }
        public void Add()
        {
            Video p = new Video("1", "test video", "Solr Test");
            ISolrOperations<Video> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Video>>();
            solr.Add(p);
            solr.Commit();
        }
    }

    [TestFixture]
    public class VideoTests
    {
        [TestFixtureSetUp]
        public void FixtureSetup()
        {
            Startup.Init<Video>("http://192.168.0.113:8070/solr");
        }
        [Test]
        public void Add()
        {
            Video p = new Video("1", "test video", "Solr Test");
            ISolrOperations<Video> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Video>>();
            solr.Add(p);
            solr.Commit();
        }
        [Test]
        public void Query()
        {
            ISolrOperations<Video> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Video>>();
            SolrQueryResults<Video> results = solr.Query(new SolrQueryByField("videoid", "33013"));
            Assert.AreEqual(1, results.Count);
            Console.WriteLine(results[0].Videoname);
        }
    }
}

However,both Add and Query test fail. It complains: TestFixture failed: SetUp : System.IO.FileLoadException : Could not load file or assembly“SolrNet, Version=0.4.0.2002, Culture=neutral, PublicKeyToken=bc21753e8aa334cb” Or one of its dependencies.

But I have add reference to Microsoft.Practices.ServiceLocation.dll and SolrNet.dll in my projoect,is there any other dll files I just miss?

By the way,,I can access my solr sever in browser with this url:http://192.168.0.113:8070/solr.

Can anyone tell me:

  1. Can I run solrnet and solr in different machines?
  2. How to do it.

Thanks a lot!

zhen lee
  • 333
  • 2
  • 6
  • 18
  • Yes, you can access a Solr server from another machine using SolrNet. Can you post all the code you are using to access the Solr server from the Windows server? – Paige Cook Jan 17 '13 at 13:46
  • @Paige Cook,Now I have add code,wish you give me some help. – zhen lee Jan 17 '13 at 14:33

3 Answers3

3

I don't understand why you're using two different URLs when you Init Solr. Try changing the URL in Paige's application to the one you posted in your original question:

http://192.168.0.113:8070/solr
Chris Warner
  • 436
  • 5
  • 7
1

Thanks for posting the code. The first thing I see is that you are using the test class as the class type to pass data to Solr. Split those out, that might be causing some issues. I would suggest the following:

public class Video
{
    private string videoid;
    [SolrField("videoid")]
    public string Videoid
    {
        get { return videoid; }
        set { videoid = value; }
    }

    private string videoname;
    [SolrField("videoname")]
    public string Videoname
    {
        get { return videoname; }
        set { videoname = value; }
    }
    private string videoorigin;
    [SolrField("videoorigin")]
    public string Videoorigin
    {
        get { return videoorigin; }
        set { videoorigin = value; }
    }
}

[TestFixture]
public class VideoTests
{
    [TestFixtureSetUp]
    public void FixtureSetup()
    {
        Startup.Init<Video>("http://192.168.0.113/solr");
    }
  [Test]
    public void Add() {
        Video p = new Video("1","test video","Solr Test");
        ISolrOperations<Video> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Video>>();
        solr.Add(p);
        solr.Commit();
    }
    [Test]
    public void Query()
    {
        ISolrOperations<Video> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Video>>();
        SolrQueryResults<Video> results = solr.Query(new SolrQueryByField("videoid", "33013"));
        Assert.AreEqual(1, results.Count);
        Console.WriteLine(results[0].Videoname);
    }        
}

Update: Try this in a console application and see if it works...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SolrNet;
using Microsoft.Practices.ServiceLocation;
namespace Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            Startup.Init<Video>("http://192.168.0.113:8070/solr");
            var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Video>>();

            var video = new Video("1", "test", "test");
            solr.Add(video);
            solr.Commit();

            var results = solr.Query(SolrQuery.All);
            Console.WriteLine("{0} - {1} - {2}",
                results[0].Videoid, results[0].Videoname, results[0].Videoorigin);
        }
    }
    public class Video
    {
        public Video(string id, string name, string origin)
        {
            Videoid = id;
            Videoname = name;
            Videoorigin = origin;
        }

        public string Videoid { get; set; 
        public string Videoname { get; set; }
       public string Videoorigin { get; set; }
    }
}
zhen lee
  • 333
  • 2
  • 6
  • 18
Paige Cook
  • 22,415
  • 3
  • 57
  • 68
  • Thanks a lot,I'll try this code the day after tomorrow.I'll let you know if it works.Really appreciate it. – zhen lee Jan 17 '13 at 15:05
  • I'm sorry,but after I change my code like what you say,It doesn't work too.When I run Add test,It complains: TestFixture failed: SetUp : System.IO.FileLoadException : Could not load file or assembly“SolrNet, Version=0.4.0.2002, Culture=neutral, PublicKeyToken=bc21753e8aa334cb” Or one of its dependencies. – zhen lee Jan 18 '13 at 12:26
  • By the way,I have add reference to Microsoft.Practices.ServiceLocation.dll and SolrNet.dll in my projoect,Is there other dll I just miss? – zhen lee Jan 18 '13 at 12:28
  • No, you should not need any other dlls. I created a sample project that is structured just like this one and it ran successfully. – Paige Cook Jan 18 '13 at 12:54
  • Do you run solrnet in a different machine from solr server as what i do? – zhen lee Jan 18 '13 at 13:01
  • Yes. I ran the test project from my laptop and the Solr server is on a Windows 2008 server (running Tomcat) on the network. We have deployed multiple .Net applications that connect to Solr running on another machine and have never had any issues. – Paige Cook Jan 18 '13 at 13:07
  • That's really strange,but what's worse is that I can't find any tutorial in the Internet which teaches how to run solrnet in a different machine,while all of them do teach how to run solrnet in the some machine with solr server.Really feel hopeless now. – zhen lee Jan 18 '13 at 13:17
  • 1
    The issues you are experiencing are not b/c you are attempting to run SolrNet against a different machine. Your issues are related to running the .NET project successfully, it does not matter where the server is located (it is just a simple REST call). I would suggest that you start over with a new project and not try to run this in a Test harness. I will modify my answer to include an option for running within the Main class of a ConsoleApplication. – Paige Cook Jan 18 '13 at 13:33
  • I invoke "video.FixtureSetup() and video.Add()" in the Main class,but the problem remain.I'm wondering if it need some configure in solr server to support being accessed by solr client . – zhen lee Jan 19 '13 at 03:12
0

Can you check your project setup as suggested by Paige? Do you have SolrNet source code added as project reference in your solution? If you are using the dll, can you paste your .csproj file contents? If it is urgent, download the source code and add as project reference in your solution until you figure out the issue.

guruprasath
  • 277
  • 3
  • 17