Implement an associated query for multiple fields within a core:
Application scenarios are: words, sentences, articles
We hope to implement words, sentences, and Common keywords in the article through query.
private static Cloudsolrserver Cloudsolrserver;
private static String Zkhost = "192.168.0.157:2181";
private static Cloudsolrserver Solrserver = new Cloudsolrserver (zkhost);
private static synchronized Cloudsolrserver Getcloudsolrserver (
Final String Zkhost) {
if (Cloudsolrserver = = null) {
try {
Cloudsolrserver = new Cloudsolrserver (zkhost);
} catch (Exception e) {
E.printstacktrace ();
}
}
return cloudsolrserver;
}
public static map<string, object> SOLRCLOUDR (String skey, int start, int rows) throws Solrserverexception{map<st Ring, object> mapresults = new hashmap<string, object> (); Solrserver.setdefaultcollection ("Collection1"); Solrquery solrquery = new Solrquery (); Solrquery.set ("Q", "Word:" +skey+ "or nickname:" +skey+ "or content:" +skey "); Solrquery.sethighlight (TRUE); Turn on Highlight component Solrquery.addhighlightfield (skey);//Highlight Field Solrquery.sethighlightsimplepre ("<font color= ' Red ' >");// tag, highlight keyword prefix solrquery.sethighlightsimplepost ("</font>");//suffix Solrquery.set ("Start", start); Solrquery.set (" Rows ", rows); Queryresponse response = Solrserver.query (solrquery); Solrdocumentlist results = Response.getresults (); Long numfound = Response.getresults (). Getnumfound (); Mapresults.put ( "Results:", results); System.out.println ("numfound=" +numfound); for (int i = 0; i < results.size (); ++i) {System.out.println (Results.get (i)); } return mapresults;}
public static void Main (string[] args) throws Exception {
String skey = "Xiamen";
SOLRCLOUDR (skey);
SOLRCLOUDR (skey);
Solrsearch (Skey, 1, 20);
SOLRCLOUDR (skey, 0, 1000);
}
Query Result:
Numfound=5Solrdocument{createtime=mon 14:58:59 PDT, id=502, articlenum=0, sex=true, Username=ad, Updatetime=mon 16:19:31 PDT, Nickname= Xiamen, Wordnum=0, Sentencenum=0, money=0.0, _version_=151038 4955694252032}solrdocument{createtime=fri 11:38:48 PDT, id=132, articlenum=0, username=15622238554, Updatetime=mon-18:47:56 PDT, Nickna Me= Xiamen Xiamen Xiamen, Wordnum=0, Sentencenum=0, money=0.0, password=96e79218965eb72c92a549dd5a330112, _version_= 1510384955754020864}solrdocument{uid=56, feel=1, Updatetime=mon 11:15:58 PDT, state=1, Createtime=mon-11:16:00 PDT, id=5, content=[heard Taiwan The wind does not come to Xiamen's], articlenum=112, Forwardnum=1, Supportnum=1, word= Xiamen, _version_=1510384955107049472}solrdocument{uid=12, feel=1, Updatetime=mon 15:04:20 PDT, state=1, Createtime=mon-15:04:24 PDT, id=501, content=[listen Said Xiamen and rain], articlenum=12, Forwardnum=1, Supportnum=1, word= Xiamen and Rain, _version_=1510384955013726208}solrdocument{uid=12, feel=1, Updatetime=mon 15:04:20 PDT, state=1, Createtime=mon-15:04:24 PDT, id=500, content=[most Near the weather very unstable], articlenum=12, Forwardnum=1, Supportnum=1, word= Xiamen high temperature, _version_=1510384954935083008}
SOLR queries the associated field of the same core