/** * Unindex a Document in the Lucene Index. * * @param context the dspace context * @param handle the handle of the object to be deleted * @throws SQLException if database error * @throws IOException if IO error */ @Override public void unIndexContent(Context context, String handle, boolean commit) throws SQLException, IOException { try { if (getSolr() != null) { getSolr().deleteByQuery(HANDLE_FIELD + ":\"" + handle + "\""); if (commit) { getSolr().commit(); } } } catch (SolrServerException e) { log.error(e.getMessage(), e); } }
/** * Maintenance to keep a SOLR index efficient. * Note: This might take a long time. */ @Override public void optimize() { try { if (getSolr() == null) { return; } long start = System.currentTimeMillis(); System.out.println("SOLR Search Optimize -- Process Started:" + start); getSolr().optimize(); long finish = System.currentTimeMillis(); System.out.println("SOLR Search Optimize -- Process Finished:" + finish); System.out.println("SOLR Search Optimize -- Total time taken:" + (finish - start) + " (ms)."); } catch (SolrServerException sse) { System.err.println(sse.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
/** * Maintenance to keep a SOLR index efficient. * Note: This might take a long time. */ public void optimize() { try { long start = System.currentTimeMillis(); System.out.println("SOLR Search Optimize -- Process Started:"+start); getSolr().optimize(); long finish = System.currentTimeMillis(); System.out.println("SOLR Search Optimize -- Process Finished:"+finish); System.out.println("SOLR Search Optimize -- Total time taken:"+(finish-start) + " (ms)."); } catch (SolrServerException sse) { System.err.println(sse.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
/** * Write the document to the index under the appropriate handle. * @param doc the solr document to be written to the server * @throws IOException IO exception */ private void writeDocument(SolrInputDocument doc) throws IOException { try { getSolr().add(doc); } catch (SolrServerException e) { log.error(e.getMessage(), e); } }
/** * Unindex a Document in the Lucene Index. * @param context the dspace context * @param handle the handle of the object to be deleted * @throws SQLException * @throws IOException */ public void unIndexContent(Context context, String handle, boolean commit) throws SQLException, IOException { try { getSolr().deleteById(handle); if(commit) { getSolr().commit(); } } catch (SolrServerException e) { log.error(e.getMessage(), e); } }
@Override public DiscoverResult search(Context context, DiscoverQuery discoveryQuery, boolean includeUnDiscoverable) throws SearchServiceException { try { if (getSolr() == null) { return new DiscoverResult(); } SolrQuery solrQuery = resolveToSolrQuery(context, discoveryQuery, includeUnDiscoverable); QueryResponse queryResponse = getSolr().query(solrQuery, SolrRequest.METHOD.POST); return retrieveResult(context, discoveryQuery, queryResponse); } catch (Exception e) { throw new org.dspace.discovery.SearchServiceException(e.getMessage(), e); } }
@Override public void buildSpellCheck() throws SearchServiceException { try { if (getSolr() == null) { return; } SolrQuery solrQuery = new SolrQuery(); solrQuery.set("spellcheck", true); solrQuery.set(SpellingParams.SPELLCHECK_BUILD, true); getSolr().query(solrQuery, SolrRequest.METHOD.POST); } catch (SolrServerException e) { //Make sure to also log the exception since this command is usually run from a crontab. log.error(e, e); throw new SearchServiceException(e); } }
@Override public InputStream searchJSON(Context context, DiscoverQuery discoveryQuery, String jsonIdentifier) throws SearchServiceException { if (getSolr() == null || !(getSolr() instanceof HttpSolrServer)) { return null; urlBuilder.append(((HttpSolrServer)getSolr()).getBaseURL()).append("/select");
/** Simple means to return the search result as an InputStream */ public java.io.InputStream searchAsInputStream(DiscoverQuery query) throws SearchServiceException, java.io.IOException { try { org.apache.commons.httpclient.methods.GetMethod method = new org.apache.commons.httpclient.methods.GetMethod(getSolr().getHttpClient().getHostConfiguration().getHostURL() + ""); method.setQueryString(query.toString()); getSolr().getHttpClient().executeMethod(method); return method.getResponseBodyAsStream(); } catch (org.apache.solr.client.solrj.SolrServerException e) { throw new SearchServiceException(e.getMessage(), e); } }
/** * unIndex removes an Item, Collection, or Community * * @param context The relevant DSpace Context. * @param dso DSpace Object, can be Community, Item, or Collection * @param commit if <code>true</code> force an immediate commit on SOLR * @throws SQLException if database error * @throws IOException if IO error */ @Override public void unIndexContent(Context context, DSpaceObject dso, boolean commit) throws SQLException, IOException { try { if (dso == null) { return; } String uniqueID = dso.getType() + "-" + dso.getID(); getSolr().deleteById(uniqueID); if (commit) { getSolr().commit(); } } catch (Exception exception) { log.error(exception.getMessage(), exception); emailException(exception); } }
solrQuery.addFilterQuery(filterquery); QueryResponse rsp = getSolr().query(solrQuery); SolrDocumentList docs = rsp.getResults();
if (getSolr() != null) { if (streams != null && !streams.isEmpty()) { ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract"); req.setParam(ExtractingParams.EXTRACT_FORMAT, "text"); req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); req.process(getSolr()); } else { getSolr().add(doc);
rsp = getSolr().query(query); } catch (SolrServerException e) { throw new SearchServiceException(e.getMessage(),e);
solrQuery.setParam(MoreLikeThisParams.MIN_WORD_LEN, String.valueOf(mltConfig.getMinWordLength())); if (getSolr() == null) { return Collections.emptyList(); QueryResponse rsp = getSolr().query(solrQuery, SolrRequest.METHOD.POST); NamedList mltResults = (NamedList) rsp.getResponse().get("moreLikeThis"); if (mltResults != null && mltResults.get(item.getType() + "-" + item.getID()) != null) {
getSolr().commit();