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 <vanjo...@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. >