SolrPage edited by Ben O'Day
Comment:
added delete example
Changes (5)
Full ContentSolr ComponentAvailable as of Camel 2.9 The Solr component allows you to interface with an Apache Lucene Solr server (based on SolrJ 3.5.0). Maven users will need to add the following dependency to their pom.xml for this component: <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-solr</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
ExampleBelow is a simple INSERT, DELETE and COMMIT example from("direct:insert") .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_INSERT)) .setHeader(SolrConstants.FIELD + "id", body()) .to("solr://localhost:8983/solr"); from("direct:delete") .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_DELETE_BY_ID)) .to("solr://localhost:8983/solr"); from("direct:commit") .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_COMMIT)) .to("solr://localhost:8983/solr"); <route> <from uri="direct:insert"/> <setHeader headerName="SolrOperation"> <constant>INSERT</constant> </setHeader> <setHeader headerName="SolrField.id"> <simple>${body}</simple> </setHeader> <to uri="solr://localhost:8983/solr"/> </route> <route> <from uri="direct:delete"/> <setHeader headerName="SolrOperation"> <constant>DELETE_BY_ID</constant> </setHeader> <to uri="solr://localhost:8983/solr"/> </route> <route> <from uri="direct:commit"/> <setHeader headerName="SolrOperation"> <constant>COMMIT</constant> </setHeader> <to uri="solr://localhost:8983/solr"/> </route> A client would simply need to pass a body message to the insert or delete routes and then call the commit route. template.sendBody("direct:insert", "1234"); template.sendBody("direct:commit", null); template.sendBody("direct:delete", "1234"); template.sendBody("direct:commit", null); Querying SolrCurrently, this component doesn't support querying data natively (may be added later). For now, you can query Solr using HTTP as follows: //define the route to perform a basic query from("direct:query") .recipientList(simple("http://localhost:8983/solr/select/?q=${body}")) .convertBodyTo(String.class); ... //query for an id of '1234' (url encoded) String responseXml = (String) template.requestBody("direct:query", "id%3A1234"); For more information, see these resources... See Also
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|