Java Code Examples for org.apache.solr.client.solrj.SolrServerException#printStackTrace()

The following examples show how to use org.apache.solr.client.solrj.SolrServerException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrConnector.java    From TagRec with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, Set<String>> getTweets() {
	Map<String, Set<String>> tweets = new LinkedHashMap<String, Set<String>>();
	
	SolrQuery solrParams = new SolrQuery();
	solrParams.set("q", "*:*");
	solrParams.set("fl", "text,hashtags");
	solrParams.set("rows", Integer.MAX_VALUE);
	QueryResponse r = null;
	try {
		r = this.server.query(solrParams);
		SolrDocumentList docs = r.getResults();
		for (SolrDocument d : docs) {
			tweets.put((String) d.get("text"), new LinkedHashSet<String>((List<String>) d.get("hashtags")));
		}
	} catch (SolrServerException e) {
		e.printStackTrace();
	}
	
	return tweets;
}
 
Example 2
Source File: SolrConnector.java    From TagRec with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Tweet> getTweetObjects(boolean ignoreRetweets) {
	List<Tweet> tweetObjects = new ArrayList<Tweet>();
	
	SolrQuery solrParams = new SolrQuery();
	if (!ignoreRetweets) {
		solrParams.set("q", "*:*");
	} else {
		solrParams.set("q", "-text:\"RT @*\"");
	}
	solrParams.set("rows", Integer.MAX_VALUE);
	QueryResponse r = null;
	try {
		r = this.server.query(solrParams);
		SolrDocumentList docs = r.getResults();
		for (SolrDocument d : docs) {
			tweetObjects.add(new Tweet((String) d.get("id"), (String) d.get("userid"), (String) d.get("text"), (String) d.get("timestamp"), new LinkedHashSet<String>((List<String>) d.get("hashtags"))));
		}
	} catch (SolrServerException e) {
		e.printStackTrace();
	}
	
	return tweetObjects;
}
 
Example 3
Source File: SolrConnector.java    From TagRec with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Tweet> getTrainTweetObjects(SolrConnector trainConnector, int hours) {
	List<Tweet> tweetObjects = new ArrayList<Tweet>();
	
	SolrQuery solrParams = new SolrQuery();
	solrParams.set("q", "*:*");
	solrParams.set("rows", Integer.MAX_VALUE);
	QueryResponse r = null;
	try {
		r = this.server.query(solrParams);
		SolrDocumentList docs = r.getResults();
		for (SolrDocument d : docs) {
			String userId = (String) d.get("userid");
			String text = trainConnector.getTweetTextOfLastHours(userId, hours);
			tweetObjects.add(new Tweet((String) d.get("id"), userId, text, (String) d.get("timestamp"), new LinkedHashSet<String>((List<String>) d.get("hashtags"))));
		}
	} catch (SolrServerException e) {
		e.printStackTrace();
	}
	
	return tweetObjects;
}
 
Example 4
Source File: SolrConnector.java    From TagRec with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, Set<String>> getUserIDs() {
	Map<String, Set<String>> tweetIDs = new LinkedHashMap<String, Set<String>>();
	
	SolrQuery solrParams = new SolrQuery();
	solrParams.set("q", "*:*");
	solrParams.set("fl", "userid,hashtags");
	solrParams.set("rows", Integer.MAX_VALUE);
	QueryResponse r = null;
	try {
		r = this.server.query(solrParams);
		SolrDocumentList docs = r.getResults();
		for (SolrDocument d : docs) {
			tweetIDs.put((String) d.get("userid"), new HashSet<String>((List<String>) d.get("hashtags")));
		}
	} catch (SolrServerException e) {
		e.printStackTrace();
	}
	
	return tweetIDs;
}
 
Example 5
Source File: AppATEGENIATest.java    From jate with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void validate_indexing() {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", "*:*");

    try {
        QueryResponse qResp = server.query(params);
        SolrDocumentList docList = qResp.getResults();

        assert (docList.getNumFound() == 2000);
    } catch (SolrServerException e) {
        e.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
 
Example 6
Source File: ACLRDTECTest.java    From jate with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static long validate_indexing() {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", "*:*");

    try {
        QueryResponse qResp = server.query(params);
        SolrDocumentList docList = qResp.getResults();

        long numDocs = docList.getNumFound();
        LOG.info(String.format("[%s] documents processed!", numDocs));
        return numDocs;
    } catch (SolrServerException e) {
        e.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    return 0;
}
 
Example 7
Source File: SolrQueryHandler.java    From aem-solr-search with Apache License 2.0 6 votes vote down vote up
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/json");
    response.setCharacterEncoding("utf-8");

    JSONArray solrDocs = new JSONArray();

    SolrClient solr = getQueryingSolrClient();

    try {
        LOG.debug("Query using Solr Client {} and the solr core {}", solr, core);
        QueryResponse result = solr.query(core, new SolrQuery("*:*"));
        SolrDocumentList list=result.getResults();
        response.getWriter().write(list.toString());

    } catch (SolrServerException e) {
        e.printStackTrace();
    }


}
 
Example 8
Source File: MarcToSolr.java    From metadata-qa-marc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void processRecord(MarcRecord marcRecord, int recordNumber) throws IOException {
  try {
    Map<String, List<String>> map = marcRecord.getKeyValuePairs(
      parameters.getSolrFieldType(), true
    );
    map.put("record_sni", Arrays.asList(marcRecord.asJson()));
    client.indexMap(marcRecord.getId(), map);
  } catch (SolrServerException e) {
    if (e.getMessage().contains("Server refused connection at")) {
      // end process;
      readyToProcess = false;
    }
    e.printStackTrace();
  }
  if (recordNumber % 5000 == 0) {
    if (parameters.doCommit())
      client.commit();
    logger.info(
      String.format(
        "%s/%s (%s)",
        currentFile.getFileName().toString(),
        decimalFormat.format(recordNumber),
        marcRecord.getId()
      )
    );
  }
}
 
Example 9
Source File: ChaosMonkeySafeLeaderTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void tryDelete() throws Exception {
  long start = System.nanoTime();
  long timeout = start + TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
  while (System.nanoTime() < timeout) {
    try {
      del("*:*");
      break;
    } catch (SolrServerException e) {
      // cluster may not be up yet
      e.printStackTrace();
    }
    Thread.sleep(100);
  }
}
 
Example 10
Source File: MainClass.java    From DistributedCrawler with Apache License 2.0 5 votes vote down vote up
public void map(LongWritable key, Text value, Context context)
		throws IOException, InterruptedException {
	CrawlDB db = new CrawlDB(crawlDBHost, crawlDBPort, crawlDBPassword,
			crawlDBTimeout, crawlDBToCrawlDB, crawlDBCrawledDB);
	Crawler c = new Crawler(key.toString(), value.toString(), topN,
			depth, db, context);// 以Input文件的行偏移量作为crawler的id
	try {
		SolrIndex.index(c.start(), solrURL);
	} catch (SolrServerException e) {
		LOG.error(e.getMessage());
		e.printStackTrace();
	}
	LOG.info("Map finish");
}
 
Example 11
Source File: SolrCommandRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Experimental method for trying out the loading of complex_annotation doc type
 * 
 * @param opts
 * @throws Exception
 */
@CLIMethod("--solr-load-complex-annotations")
public void experimentalLoadComplexAnnotationSolr(Opts opts) throws Exception {

	// Check to see if the global url has been set.
	String url = sortOutSolrURL(globalSolrURL);				

	// Only proceed if our environment was well-defined.
	if( legoCatalogs == null || legoFiles == null || legoCatalogs.isEmpty() || legoFiles.isEmpty() ){
		LOG.warn("Lego environment not well defined--skipping.");
	}else{

		// Ready the environment for every pass.
		ParserWrapper pw = new ParserWrapper();
		// Add all of the catalogs.
		for( File legoCatalog : legoCatalogs ){
			pw.addIRIMapper(new CatalogXmlIRIMapper(legoCatalog));				
		}
		OWLOntologyManager manager = pw.getManager();
		OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();

		// Actual loading--iterate over our list and load individually.
		for( File legoFile : legoFiles ){
			String fname = legoFile.getName();
			OWLReasoner currentReasoner = null;
			OWLOntology ontology = null;

			// TODO: Temp cover for missing group labels and IDs.
			//String agID = legoFile.getCanonicalPath();
			String agLabel = StringUtils.removeEnd(fname, ".owl");
			String agID = new String(agLabel);

			try {
				ontology = pw.parseOWL(IRI.create(legoFile));
				currentReasoner = reasonerFactory.createReasoner(ontology);

				// Some sanity checks--some of the genereated ones are problematic.
				boolean consistent = currentReasoner.isConsistent();
				if( consistent == false ){
					LOG.info("Skip since inconsistent: " + fname);
					continue;
				}
				Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom();

				// TODO - make configurable to allow fail fast
				if (unsatisfiable.isEmpty() == false) {
					LOG.info("Skip since unsatisfiable: " + fname);
					continue;
				}

				Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
				Set<OWLAnnotation> modelAnnotations = ontology.getAnnotations();

				OWLGraphWrapper currentGraph = new OWLGraphWrapper(ontology);						
				try {
					LOG.info("Trying complex annotation load of: " + fname);
					ComplexAnnotationSolrDocumentLoader loader =
							new ComplexAnnotationSolrDocumentLoader(url, currentGraph, currentReasoner, individuals, modelAnnotations, agID, agLabel, fname);
					loader.load();
				} catch (SolrServerException e) {
					LOG.info("Complex annotation load of " + fname + " at " + url + " failed!");
					e.printStackTrace();
					System.exit(1);
				}
			} finally {
				// Cleanup reasoner and ontology.
				if (currentReasoner != null) {
					currentReasoner.dispose();
				}
				if (ontology != null) {
					manager.removeOntology(ontology);
				}
			}
		}
	}
}
 
Example 12
Source File: SolrCommandRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Experimental method for trying out the loading of complex_annotation doc type.
 * Works with --read-ca-list <file>.
 * 
 * @param opts
 * @throws Exception
 */
@CLIMethod("--solr-load-complex-exp")
public void loadComplexAnnotationSolr(Opts opts) throws Exception {

	// Check to see if the global url has been set.
	String url = sortOutSolrURL(globalSolrURL);				

	// Only proceed if our environment was well-defined.
	if( caFiles == null || caFiles.isEmpty() ){
		LOG.warn("LEGO environment not well defined--will skip loading LEGO/CA.");
	}else{

		// NOTE: These two lines are remainders from old code, and I'm not sure of their place in this world of ours.
		// I wish there was an arcitecture diagram somehwere...
		OWLOntologyManager manager = pw.getManager();
		OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();

		// Actual loading--iterate over our list and load individually.
		for( String fname : caFiles ){
			OWLReasoner currentReasoner = null;
			OWLOntology ontology = null;

			// TODO: Temp cover for missing group labels and IDs.
			//String agID = legoFile.getCanonicalPath();
			String pretmp = StringUtils.removeEnd(fname, ".owl");
			String[] bits = StringUtils.split(pretmp, "/");
			String agID = bits[bits.length -1];
			String agLabel = new String(StringUtils.replaceOnce(agID, ":", "_"));

			try {
				ontology = pw.parseOWL(IRI.create(fname));
				currentReasoner = reasonerFactory.createReasoner(ontology);

				// Some sanity checks--some of the genereated ones are problematic.
				boolean consistent = currentReasoner.isConsistent();
				if( consistent == false ){
					LOG.info("Skip since inconsistent: " + fname);
					continue;
				}
				Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom();
				if (unsatisfiable.isEmpty() == false) {
					LOG.info("Skip since unsatisfiable: " + fname);
					continue;
				}

				Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
				Set<OWLAnnotation> modelAnnotations = ontology.getAnnotations();
				OWLGraphWrapper currentGraph = new OWLGraphWrapper(ontology);						
				try {
					LOG.info("Trying complex annotation load of: " + fname);
					ComplexAnnotationSolrDocumentLoader loader =
							new ComplexAnnotationSolrDocumentLoader(url, currentGraph, currentReasoner, individuals, modelAnnotations, agID, agLabel, fname);
					loader.load();
				} catch (SolrServerException e) {
					LOG.info("Complex annotation load of " + fname + " at " + url + " failed!");
					e.printStackTrace();
					System.exit(1);
				}
			} finally {
				// Cleanup reasoner and ontology.
				if (currentReasoner != null) {
					currentReasoner.dispose();
				}
				if (ontology != null) {
					manager.removeOntology(ontology);
				}
			}
		}
	}
}