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 Joey <va...@gmail.com> on 2011/12/13 20:38:04 UTC

Re: How to get SolrServer within my own servlet

Anybody could help?

--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3583368.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to get SolrServer within my own servlet

Posted by Patrick Plaatje <pp...@gmail.com>.
Hey Joey,

You should first configure your deployed Solr instance by adding/changing the schema.xml and solrconfig.xml. After that you can use SolrJ to connect to that Solr instance and add documents to it. On the link i posted earlier, you'll find à couple of examples on how to do that.

- Patrick 

Verstuurd vanaf mijn iPhone

Op 13 dec. 2011 om 20:53 heeft Joey <va...@gmail.com> het volgende geschreven:

> Thanks Patrick  for the reply. 
> 
> What I did was un-jar solr.war and created my own web application. Now I
> want to write my own servlet to index all files inside a folder. 
> 
> I suppose there is already solrserver instance initialized when my web app
> started. 
> 
> How can I access that solr server instance in my servlet?
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3583416.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to get SolrServer within my own servlet

Posted by Joey <va...@gmail.com>.
Thanks Patrick  for the reply. 

What I did was un-jar solr.war and created my own web application. Now I
want to write my own servlet to index all files inside a folder. 

I suppose there is already solrserver instance initialized when my web app
started. 

How can I access that solr server instance in my servlet?

--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3583416.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to get SolrServer within my own servlet

Posted by Joey <va...@gmail.com>.
Hi Chris,

There won't be deadlock I think because there is only one place(from my own
servlet) can trigger a index. 

Yes, I am trying to embed Solr application - I could separate my servlet to
another app and talk to Sorl via HTTP, but there will be two pieces(Solr and
my own app) of software I have to maintain - which is something I don't
like.



--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3587157.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to get SolrServer within my own servlet

Posted by Chris Hostetter <ho...@fucit.org>.
: So what I want to do is to modify Solr a bit - add one servlet so I can
: trigger a full index of a folder in the file system.
	...

: I guess there are two SolrServer instances(one is EmbeddedSolrServer,
: created by myself and the other is come with Solr itself and they are
: holding different index?

i suspect you are correct, but frankly i'm amazed hwat you are doing is 
working at all (you should be getting a write lock from having two 
distinct Solr instances trying to write to the same directory)

I think you need to back up and explain better what your overall goal is 
-- embedding Solr in other apps is:

a) a fairly advanced usage that i would not suggest you persue until 
you have a better grasp of solr fundementals
b) not something people usually do if they also want to be able to use 
solr via HTTP.

in general, if your only goal of mucking with the solr.war is to be able 
to index files on the "local" filesystem (relative where Solr is running) 
there are a lot of other ways to approach that goal (use DIH, or write a 
custom RequestHanlder you load as a plugin, etc...)

https://people.apache.org/~hossman/#xyproblem
XY Problem

Your question appears to be an "XY Problem" ... that is: you are dealing
with "X", you are assuming "Y" will help you, and you are asking about "Y"
without giving more details about the "X" so that we can understand the
full issue.  Perhaps the best solution doesn't involve "Y" at all?
See Also: http://www.perlmonks.org/index.pl?node_id=542341



-Hoss

Re: How to get SolrServer within my own servlet

Posted by yunfei wu <yu...@gmail.com>.
Just curious, sounds like you try to deploy your servlet with Solr support,
why don't you just deploy you app as separate Sevlet with the Solr war in
the server, then let your servlet send requests to Solr? This will bring
much benefit in maintaining your app with Solr support.

Yunfei


On Tuesday, December 13, 2011, Joey <va...@gmail.com> wrote:
> Thank you guys for the reply.
>
> So what I want to do is to modify Solr a bit - add one servlet so I can
> trigger a full index of a folder in the file system.
>
> What I did:
>       un-jar solr.war;
>       Create a web app and copy the un-jar the solr files to this app;
>       Create my servlet;
>       Repackage the web app to a war and deploy;
>
> by following the suggestions of you guys;
> I create a "EmbeddedSolrServer" in my Servlet:
>        public void init() throws ServletException {
>                CoreContainer.Initializer initializer = new
CoreContainer.Initializer();
>                CoreContainer coreContainer = null;
>                try {
>                        coreContainer = initializer.initialize();
>                } catch (IOException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                } catch (ParserConfigurationException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                } catch (SAXException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }
>                _solrServer = new EmbeddedSolrServer(coreContainer, "");
>        }
>
> And I can now trigger the index by call:
> http://localhost:8080/testservlet01. The servlet does this:
>                SolrInputDocument doc1 = new SolrInputDocument();
>                doc1.addField( "id", "id1", 1.0f );
>                doc1.addField( "name", "doc1", 1.0f );
>
>            Collection<SolrInputDocument> docs = new
> ArrayList<SolrInputDocument>();
>            docs.add( doc1 );
>            try {
>                        _solrServer.add( docs );
>                        _solrServer.commit();
>                } catch (SolrServerException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }
>
> However, seems the search didn't return unless I restart my application:
> localhost:8080/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on
>
>
> I guess there are two SolrServer instances(one is EmbeddedSolrServer,
> created by myself and the other is come with Solr itself and they are
> holding different index?
>
> How can I make them synchronized?
>
> --
> View this message in context:
http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3583741.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: How to get SolrServer within my own servlet

Posted by Joey <va...@gmail.com>.
Thank you guys for the reply.

So what I want to do is to modify Solr a bit - add one servlet so I can
trigger a full index of a folder in the file system.

What I did:
       un-jar solr.war;
       Create a web app and copy the un-jar the solr files to this app;
       Create my servlet;
       Repackage the web app to a war and deploy;

by following the suggestions of you guys;
I create a "EmbeddedSolrServer" in my Servlet:
	public void init() throws ServletException {
		CoreContainer.Initializer initializer = new CoreContainer.Initializer();
		CoreContainer coreContainer = null;
		try {
			coreContainer = initializer.initialize();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		_solrServer = new EmbeddedSolrServer(coreContainer, "");
	}

And I can now trigger the index by call:
http://localhost:8080/testservlet01. The servlet does this:
		SolrInputDocument doc1 = new SolrInputDocument();
		doc1.addField( "id", "id1", 1.0f );
		doc1.addField( "name", "doc1", 1.0f );
		
	    Collection<SolrInputDocument> docs = new
ArrayList<SolrInputDocument>();
	    docs.add( doc1 );	    
	    try {
			_solrServer.add( docs );
			_solrServer.commit();
		} catch (SolrServerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

However, seems the search didn't return unless I restart my application:
localhost:8080/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on


I guess there are two SolrServer instances(one is EmbeddedSolrServer,
created by myself and the other is come with Solr itself and they are
holding different index?

How can I make them synchronized?

--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3583741.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to get SolrServer within my own servlet

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
The first drawback of SolrJ is using xml serialization for in-process
communication.
I guess you can start from SolrDispatchFilter source, and get something for
your servlet from there.

Regards

On Tue, Dec 13, 2011 at 11:45 PM, Patrick Plaatje <pp...@gmail.com>wrote:

> Have à look here first and you're will probably be using
> SolrEmbeddedServer.
>
> http://wiki.apache.org/solr/Solrj
>
> Patrick
>
>
> Op 13 dec. 2011 om 20:38 heeft Joey <va...@gmail.com> het volgende
> geschreven:
>
> > Anybody could help?
> >
> > --
> > View this message in context:
> http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3583368.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
>



-- 
Sincerely yours
Mikhail Khludnev
Developer
Grid Dynamics
tel. 1-415-738-8644
Skype: mkhludnev
<http://www.griddynamics.com>
 <mk...@griddynamics.com>

Re: How to get SolrServer within my own servlet

Posted by Patrick Plaatje <pp...@gmail.com>.
Have à look here first and you're will probably be using SolrEmbeddedServer.

http://wiki.apache.org/solr/Solrj

Patrick


Op 13 dec. 2011 om 20:38 heeft Joey <va...@gmail.com> het volgende geschreven:

> Anybody could help?
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/How-to-get-SolrServer-within-my-own-servlet-tp3583304p3583368.html
> Sent from the Solr - User mailing list archive at Nabble.com.