Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 61 lines (35 sloc) 3.269 kb
4f3de01 @anandbn Initial draft.
anandbn authored
1 # Using WebSolr with Java on Heroku
2
079262d @anandbn Update README.md
anandbn authored
3 This is a sample project that demonstrates how to use [WebSolr add on](http://addons.heroku.com/websolr) with Java on Heroku. [WebSolr](http://websolr.com/) is essentially a hosted version of [Apache Solr](http://lucene.apache.org/solr/) which is a really fast and flexible search and indexing platform that can search/index any data. This project also uses the [JQuery Autocomplete](http://docs.jquery.com/Plugins/Autocomplete) plugin and [SolrJ](http://wiki.apache.org/solr/Solrj), a Java API to communicate with any Solr instance.
4f3de01 @anandbn Initial draft.
anandbn authored
4
2f7a4b8 @anandbn Update README.md
anandbn authored
5 __*Note*__: This project is by no means a demonstration of all of Solr's capabilties. Please refer to the Solr wiki for more information on additional features and functionality that you can leverage with Solr.
4f3de01 @anandbn Initial draft.
anandbn authored
6
7 ## Pre-requisites
8
9 - Basic knowledge of Java and Java servlets
10 - Knowledge of JQuery and using plugins
11 - Understanding of Solr and Solr Queries.
12
13 ## How does it work?
14
15 Most of the magic happens in two main components:
16
079262d @anandbn Update README.md
anandbn authored
17 1. `index.jsp` : This contains the JQuery autocomplete code and includes the Autocomplete Javascripts and CSS.
18 2. `SolrProxy.java` : This is a servlet that acts as a proxy the WebSolr index URL that is exposed on provision the add-on to your heroku account.
4f3de01 @anandbn Initial draft.
anandbn authored
19
20 ## Provisioning WebSolr
21
978daf7 @anandbn Update README.md
anandbn authored
22 You can provision the WebSolr add-on to your Heroku app by using the command:
2f7a4b8 @anandbn Update README.md
anandbn authored
23
4f3de01 @anandbn Initial draft.
anandbn authored
24 $ heroku addons:add websolr:cobalt
25
2f7a4b8 @anandbn Update README.md
anandbn authored
26 __*Note*__: WebSolr is not a free add-on. If you provision their "cobalt" add-on you will be charged $20 per month.
079262d @anandbn Update README.md
anandbn authored
27
4f3de01 @anandbn Initial draft.
anandbn authored
28 Once you provision this add-on, WebSolr will create a "default" index and add the WebSolr index URL to your Heroku config. To view the WebSolr index URL use the command:
29
30 $ heroku config
31 ...
32 WEBSOLR_URL => http://index.websolr.com/solr/...
33
079262d @anandbn Update README.md
anandbn authored
34 Once you have the WebSolr index URL, you and send your Solr queries to this URL. To modify the Solr `schema.xml` and make updates to your Solr cofiguration, navigate to the WebSolr add-on under your app and that will open up a page to all the Solr indexes that you have defined. On click a specific index, you can look at the schema, synonym configurations, stop words etc.
4f3de01 @anandbn Initial draft.
anandbn authored
35
36
37 ## Using SolrJ
38
39 SolrJ is a pure java client to communicate with your Solr instance. Refer to [http://wiki.apache.org/solr/Solrj#Adding_Data_to_Solr](http://wiki.apache.org/solr/Solrj#Adding_Data_to_Solr) on how to add data to your index using Solr. Refer to [http://wiki.apache.org/solr/Solrj#Reading_Data_from_Solr](http://wiki.apache.org/solr/Solrj#Reading_Data_from_Solr) on how to use Solr queries using SolrJ.
40
41
42 ## Using SolrJ and WebSolr
43
079262d @anandbn Update README.md
anandbn authored
44 `SolrProxy.java` is the main Java servlet that does the communication with the WebSolr index URL. The code snippet that performs the query is below:
4f3de01 @anandbn Initial draft.
anandbn authored
45
46
47 SolrQuery query = new SolrQuery();
48 query.setQuery( "text:"+queryParam );
49 query.set("wt", "json");
50 query.setFields("id","StreetAddress");
51 query.setFacet(true);
52 query.addFacetField("State");
53
54 Long start,end;
55 start = System.currentTimeMillis();
56 QueryResponse queryResponse = server.query(query);
57 end = System.currentTimeMillis();
58
59 To see a working example of this, go to [http://websolr-java.herokuapp.com](http://websolr-java.herokuapp.com)
60
Something went wrong with that request. Please try again.