Created
February 9, 2013 01:31
-
-
Save kevindoran/4743410 to your computer and use it in GitHub Desktop.
SolrJ example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SimpleSolrSearch { | |
| private String solrUrl = "http://192.168.1.103:8983/solr/auctions"; | |
| private SolrServer server; | |
| public SimpleSolrSearch() { | |
| server = new HttpSolrServer(solrUrl); | |
| } | |
| public Collection<Integer> search(String searchTerms, String category, BigDecimal maxBidAmount) throws SolrServerException { | |
| SolrQuery query = new SolrQuery(); | |
| String categoryFilter = "category:\"" + category + "\""; | |
| query.addFilterQuery(categoryFilter); | |
| query.addFilterQuery("current_bid:[1 TO " + maxBidAmount.doubleValue() + "]"); | |
| query.setQuery(searchTerms); | |
| QueryResponse response = server.query(query); | |
| SolrDocumentList documentList = response.getResults(); | |
| List<Integer> auctionIds = new ArrayList<>(); | |
| for(SolrDocument doc : documentList) { | |
| int listingId = Integer.parseInt((String)doc.getFirstValue("auction_id")); | |
| auctionIds.add(listingId); | |
| } | |
| return auctionIds; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment