本文整理匯總了Java中org.apache.solr.client.solrj.SolrServerException類的典型用法代碼示例。如果您正苦於以下問題:Java SolrServerException類的具體用法?Java SolrServerException怎麽用?Java SolrServerException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SolrServerException類屬於org.apache.solr.client.solrj包,在下文中一共展示了SolrServerException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getHttpSolrClients
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
*
* @param cloudSolrClient
* @return
* @throws SolrServerException
* @throws IOException
*/
private List<HttpSolrClient> getHttpSolrClients(CloudSolrClient cloudSolrClient) throws SolrServerException, IOException {
List<HttpSolrClient> solrClients = new ArrayList<>();
for (String baseUrl : getBaseUrls(cloudSolrClient)) {
NoOpResponseParser responseParser = new NoOpResponseParser();
responseParser.setWriterType("json");
HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
builder.withBaseSolrUrl(baseUrl);
HttpSolrClient httpSolrClient = builder.build();
httpSolrClient.setParser(responseParser);
solrClients.add(httpSolrClient);
}
return solrClients;
}
示例2: main
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
String zkHost = "localhost:2181";
String defaultCollection = "collection1";
CloudSolrServer solr = new CloudSolrServer(zkHost);
solr.setDefaultCollection(defaultCollection);
/* ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "cat:electronics");
params.set("defType", "edismax");
params.set("start", "0");*/
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例3: getResultCount
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
* Returns how many solr documents match the given query.
* @param query a solr `q` query.
* @return solr document count.
* @deprecated use {@link #search(SolrQuery)}{@code .getNumFound()}.
*/
@Deprecated
@PreAuthorize("hasRole('ROLE_SEARCH')")
public int getResultCount(String query)
{
try
{
query = solrDao.updateQuery(query);
return (int) solrDao.search(new SolrQuery(query)).getResults().getNumFound();
}
catch (SolrServerException | IOException ex)
{
LOGGER.error(ex);
throw new DHusSearchException("An exception occured while searching", ex);
}
}
示例4: listRuntimeDependencies
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException {
ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/file");
request.setResponseParser(new InputStreamResponseParser("json"));
NamedList o = client.request(request, collectionName);
LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8");
List<String> returnValues = Streams.stream(it).collect(Collectors.toList());
//if file not exists (a little hacky..)
if(returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) {
logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually.");
return Collections.emptyList();
};
return returnValues;
}
示例5: getCores
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
* Get target cores via CoreAdminAPI.
*
* @param httpSolrClient
* @return
*/
public static List<String> getCores(HttpSolrClient httpSolrClient) throws SolrServerException, IOException {
List<String> cores = new ArrayList<>();
NoOpResponseParser responseParser = new NoOpResponseParser();
responseParser.setWriterType("json");
httpSolrClient.setParser(responseParser);
CoreAdminRequest coreAdminRequest = new CoreAdminRequest();
coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS);
coreAdminRequest.setIndexInfoNeeded(false);
NamedList<Object> coreAdminResponse = httpSolrClient.request(coreAdminRequest);
JsonNode statusJsonNode = om.readTree((String) coreAdminResponse.get("response")).get("status");
for (Iterator<JsonNode> i = statusJsonNode.iterator(); i.hasNext(); ) {
String core = i.next().get("name").textValue();
if (!cores.contains(core)) {
cores.add(core);
}
}
return cores;
}
示例6: request
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
@Override
public NamedList<Object> request(@SuppressWarnings("rawtypes") SolrRequest req, String collection)
throws SolrServerException, IOException {
if (closed) {
throw new SolrServerException("The SolrClient is closed.");
}
if (collection == null) {
throw new SolrServerException("a collection must be specified");
}
String expr = req.getParams().get("expr");
if (expr == null) {
throw new SolrServerException(
"there should be an 'expr' parameter on the request, to specify a streaming expression.");
}
String json = JSONUtil.toJSON(root);
InputStream is = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
NamedList<Object> nl = new NamedList<>(Collections.singletonMap("stream", is));
return nl;
}
示例7: prepareUpdate
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
* Prepares the given record for an update. Creation timestamp is preserved. A new update timestamp is added, child docs are removed.
*
* @param indexObj {@link IndexObject}
* @throws IOException -
* @throws SolrServerException
* @throws FatalIndexerException
*/
private void prepareUpdate(IndexObject indexObj) throws IOException, SolrServerException, FatalIndexerException {
String pi = indexObj.getPi().trim();
SolrDocumentList hits = hotfolder.getSolrHelper().search(SolrConstants.PI + ":" + pi, null);
if (hits != null && hits.getNumFound() > 0) {
logger.debug("This file has already been indexed, initiating an UPDATE instead...");
indexObj.setUpdate(true);
SolrDocument doc = hits.get(0);
// Set creation timestamp, if exists (should never be updated)
Object dateCreated = doc.getFieldValue(SolrConstants.DATECREATED);
if (dateCreated != null) {
// Set creation timestamp, if exists (should never be updated)
indexObj.setDateCreated((Long) dateCreated);
}
// Set update timestamp
Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
if (dateUpdatedValues != null) {
for (Object date : dateUpdatedValues) {
indexObj.getDateUpdated().add((Long) date);
}
}
// Recursively delete all children
deleteWithPI(pi, false, hotfolder.getSolrHelper());
}
}
示例8: main
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
// ModifiableSolrParams params = new ModifiableSolrParams();
// params.setQuery("name:Samsung ");
// params.setStart(0);
// params.setRows(100);
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例9: search
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
* searches and returns a list of {@link SolrDocument}
*
* @param from startdate
* @param until enddate
* @param set which collection
* @param metadataPrefix
* @param firstRow
* @param numRows
* @param urnOnly
* @param querySuffix
* @return list of hits as {@link SolrDocument}
* @throws IOException
* @throws SolrServerException
*/
public SolrDocumentList search(String from, String until, String set, String metadataPrefix, int firstRow, int numRows, boolean urnOnly,
String querySuffix) throws IOException, SolrServerException {
StringBuilder sbQuery = new StringBuilder(buildQueryString(from, until, set, metadataPrefix, urnOnly, querySuffix));
if (urnOnly) {
sbQuery.append(" AND (").append(SolrConstants.URN).append(":* OR ").append(SolrConstants.IMAGEURN_OAI).append(":*)");
}
sbQuery.append(getAllSuffixes());
logger.debug("OAI query: {}", sbQuery.toString());
SolrQuery solrQuery = new SolrQuery(sbQuery.toString());
solrQuery.setStart(firstRow);
solrQuery.setRows(numRows);
solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
QueryResponse resp = server.query(solrQuery);
logger.debug("Total hits: {}, fetched records {} - {}", resp.getResults().getNumFound(), firstRow, firstRow + resp.getResults().size() - 1);
return resp.getResults();
}
示例10: query
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
*
* @param identifier
* @param metadataPrefix
* @param rows
* @return
* @throws SolrServerException
*/
private SolrDocumentList query(final String identifier, String metadataPrefix, int rows) throws SolrServerException {
String useIdentifier = ClientUtils.escapeQueryChars(identifier);
StringBuilder sb = new StringBuilder();
sb.append('(').append(SolrConstants.PI).append(':').append(useIdentifier).append(" OR ").append(SolrConstants.URN).append(':').append(
useIdentifier).append(" OR ").append(SolrConstants.IMAGEURN).append(':').append(useIdentifier).append(')');
sb.append(getAllSuffixes());
logger.debug(sb.toString());
SolrQuery solrQuery = new SolrQuery(sb.toString());
solrQuery.setRows(rows);
QueryResponse resp = server.query(solrQuery);
// if (resp.getResults().isEmpty() && Metadata.epicur.name().equals(metadataPrefix)) {
// solrQuery = new SolrQuery(new StringBuilder(SolrConstants.IMAGEURN_OAI).append(":").append(identifier).toString());
// solrQuery.setRows(rows);
// resp = server.query(solrQuery);
// }
return resp.getResults();
}
示例11: getSets
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
* Creates a list with all available values for the given field (minus any blacklisted values).
*
* @return
* @throws SolrServerException
* @should return all values
*/
public List<String> getSets(String field) throws SolrServerException {
List<String> ret = new ArrayList<>();
SolrQuery query = new SolrQuery();
query.setQuery(field + ":* " + DataManager.getInstance().getConfiguration().getCollectionBlacklistFilterSuffix());
query.setStart(0);
query.setRows(0);
query.addFacetField(field);
logger.trace("Set query: {}", query.getQuery());
QueryResponse resp = server.query(query);
FacetField facetField = resp.getFacetField(field);
if (facetField != null) {
for (Count count : facetField.getValues()) {
if (count.getCount() == 0) {
continue;
}
ret.add(count.getName());
}
}
Collections.sort(ret);
logger.trace("{} terms found for {}", ret.size(), field);
return ret;
}
示例12: getTotalHitNumber
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
*
* @param params
* @param urnOnly
* @param querySuffix
* @return size of search
* @throws IOException
* @throws SolrServerException
*/
public long getTotalHitNumber(Map<String, String> params, boolean urnOnly, String querySuffix) throws IOException, SolrServerException {
StringBuilder sbQuery = new StringBuilder(buildQueryString(params.get("from"), params.get("until"), params.get("set"), params.get(
"metadataPrefix"), urnOnly, querySuffix));
if (urnOnly) {
sbQuery.append(" AND (").append(SolrConstants.URN).append(":* OR ").append(SolrConstants.IMAGEURN_OAI).append(":*)");
}
sbQuery.append(getAllSuffixes());
logger.debug("OAI query: {}", sbQuery.toString());
SolrQuery solrQuery = new SolrQuery(sbQuery.toString());
solrQuery.setStart(0);
solrQuery.setRows(0);
solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
QueryResponse resp = server.query(solrQuery);
long num = resp.getResults().getNumFound();
logger.debug("Total hits: {}", num);
return num;
}
示例13: getLatestVolumeTimestamp
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
* If the given SolrDocument is an anchor, retrieve the latest DATEUPDATED timestamp value from its volumes.
*
* @param anchorDoc
* @param untilTimestamp
* @return
* @throws SolrServerException
*/
public long getLatestVolumeTimestamp(SolrDocument anchorDoc, long untilTimestamp) throws SolrServerException {
if (anchorDoc.getFieldValue(SolrConstants.ISANCHOR) != null && (Boolean) anchorDoc.getFieldValue(SolrConstants.ISANCHOR)) {
SolrDocumentList volumes = search(SolrConstants.ISWORK + ":true AND " + SolrConstants.IDDOC_PARENT + ":" + (String) anchorDoc
.getFieldValue(SolrConstants.IDDOC));
if (volumes != null) {
long latest = 0;
for (SolrDocument volume : volumes) {
long volumeTimestamp = getLatestValidDateUpdated(volume, untilTimestamp);
if (latest < volumeTimestamp) {
latest = volumeTimestamp;
}
}
if (latest > 0) {
return latest;
}
}
}
return -1;
}
示例14: query
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
public QueryResponse query(ModifiableSolrParams params) throws SolrServerException
{
try
{
QueryResponse response = server.query(params);
if(response.getStatus() != 0)
{
solrTracker.setSolrActive(false);
}
return response;
}
catch(SolrServerException e)
{
solrTracker.setSolrActive(false);
throw e;
}
}
示例15: setProperties
import org.apache.solr.client.solrj.SolrServerException; //導入依賴的package包/類
/**
* Set the given properties and values using the config API.
* @param props properties to set.
* @throws IOException network error.
* @throws SolrServerException solr error.
*/
public void setProperties(Map<String, String> props) throws SolrServerException, IOException
{
// Solrj does not support the config API yet.
StringBuilder command = new StringBuilder("{\"set-property\": {");
for (Map.Entry<String, String> entry: props.entrySet())
{
command.append('"').append(entry.getKey()).append('"').append(':');
command.append(entry.getValue()).append(',');
}
command.setLength(command.length()-1); // remove last comma
command.append("}}");
GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null);
ContentStream content = new ContentStreamBase.StringStream(command.toString());
rq.setContentStreams(Collections.singleton(content));
rq.process(solrClient);
}