How to select from solr use java? -
i save data in solr:
string solrurl = "http://localhost:8984/solr"; solrserver solrserver = new httpsolrserver( solrurl ); solrinputdocument doc = new solrinputdocument(); doc.addfield("id", "1"); doc.addfield("first_name", "ann"); doc.addfield("last_name", "smit"); doc.addfield("email", "test@test.com"); try { solrserver.add(doc); solrserver.commit(); } catch (solrserverexception e) {/* */}
and select data solr:
solrquery query = new solrquery(); query.setquery("*:*"); query.addfilterquery("first_name:ann*"); query.addfilterquery("last_name:ann*"); query.setfields("id","first_name","last_name","email"); queryresponse response = null; try { response = solrserver.query(query); } catch (solrserverexception e) {/* */ } solrdocumentlist list = response.getresults();
i have search criteria: first name or last name should contain value ann
. how set filterquery
select saved data?
should use:
solrquery parameters = new solrquery(); query.setquery("first_name:qwe2 or last_name:qwe2"); query.setfields("id","first_name","last_name","email"); queryresponse response = null; try { response = solrserver.query(parameters); } catch (solrserverexception e) {/* */ } solrdocumentlist list = response.getresults();
Comments
Post a Comment