Skip to content

Instantly share code, notes, and snippets.

@kevindoran
Created February 9, 2013 01:31
Show Gist options
  • Select an option

  • Save kevindoran/4743410 to your computer and use it in GitHub Desktop.

Select an option

Save kevindoran/4743410 to your computer and use it in GitHub Desktop.
SolrJ example
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