PublicList geturlresults (list<string> strlist,string serverurl,pageresult result)throwsmalformedurlexception, solrserverexception{httpsolrserver server=NewHttpsolrserver (ServerURL); //serverurl indicates the URL to connect to List<String> urls=NewArraylist<string>(); if(Strlist.size () >0){ for(intI=0;i<strlist.size (); i++) {modifiablesolrparams params=NewModifiablesolrparams (); Params.set ("Q", Strlist.get (i));//*. * Indicates query criteria//params.set ("Deftype", "Edismax");Params.set ("Start", "0");//index at which to start the query//params.set ("DF", "content");//set the scope of a queryParams.set ("fl", "url");//set the results returned by the queryresult.setpagesize (Getfoundnums (Strlist.get (i). toString (), ServerURL)); Params.set ("Rows", Result.getpagesize ()); //params.set ("df", "url");Queryresponse Solrresponse; Try{solrresponse=server.query (params); Solrdocumentlist Results=solrresponse.getresults (); for(solrdocument solrdocument:results) {String URL= (String) solrdocument.getfieldvalue ("url"); Urls.add (URL); } } Catch(solrserverexception e) {e.printstacktrace (); } } } returnURLs; } PublicList<newsinfo> getresultsbyrule (list<string> rulelist,string ServerURL)throwsmalformedurlexception, solrserverexception{httpsolrserver server=NewHttpsolrserver (ServerURL); List<NewsInfo> urls=NewArraylist<newsinfo>(); if(Rulelist.size () >0){ for(intI=0;i<rulelist.size (); i++) {modifiablesolrparams params=NewModifiablesolrparams (); Params.set ("Q", Rulelist.get (i));//*.* //params.set ("Deftype", "Edismax");Params.set ("Start", "0"); Params.set ("DF", "all"); Params.set ("FL", "title description ntime URL SourceID id");//return Fields//params.set ("Rows", 2); //params.set ("df", "url");Queryresponse Solrresponse; Try{solrresponse=server.query (params); Solrdocumentlist Results=solrresponse.getresults ();
Integer counts = Results.getnumfound (); //Gets the total number of bars found for(solrdocument solrdocument:results) {Newsinfo News=NewNewsinfo (); News.setdescription (String) Solrdocument.getfieldvalue ("description")); News.settitle (Solrdocument.getfieldvalue ("Title"). toString ()); News.seturl (String) Solrdocument.getfieldvalue ("url")); News.setntime (Solrdocument.getfieldvalue ("Ntime"). toString ()); Integer J=integer.valueof (((ArrayList) solrdocument.getfieldvalue ("SourceID"). Get (0). toString ()); News.setsourceid (j); News.setid (integer.valueof (Solrdocument.getfieldvalue ("id"). toString ())); Urls.add (news); } } Catch(solrserverexception e) {e.printstacktrace (); } } } returnURLs; }
The Java program connects SOLR and sets parameters, etc.