本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.setRows方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.setRows方法的具體用法?Java SolrQuery.setRows怎麽用?Java SolrQuery.setRows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.setRows方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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));
}
}
示例2: main
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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));
}
}
示例3: search
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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();
}
示例4: query
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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();
}
示例5: getSets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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;
}
示例6: getTotalHitNumber
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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;
}
示例7: findCurrentDataRepository
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
*
* @param pi
* @return The name of the data repository currently used for the record with the given PI; "?" if the record is indexed, but not in a repository;
* null if the record is not in the index
* @throws SolrServerException
* @should find correct data repository for record
*/
public String findCurrentDataRepository(String pi) throws SolrServerException {
SolrQuery solrQuery = new SolrQuery(SolrConstants.PI + ":" + pi);
solrQuery.setRows(1);
solrQuery.setFields(SolrConstants.DATAREPOSITORY);
QueryResponse resp = server.query(solrQuery);
if (!resp.getResults().isEmpty()) {
if (resp.getResults().get(0).getFieldValue(SolrConstants.DATAREPOSITORY) != null) {
return (String) resp.getResults().get(0).getFieldValue(SolrConstants.DATAREPOSITORY);
}
return "?";
}
return null;
}
示例8: buildSolrRequest
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
protected QueryRequest buildSolrRequest(ComponentConfiguration conf, Template intent, Conversation conversation, long offset, int pageSize, MultiValueMap<String, String> queryParams) {
final ConversationMltQuery mltQuery = buildQuery(conf, intent, conversation);
if (mltQuery == null) {
return null;
}
final SolrQuery solrQuery = new SolrQuery();
solrQuery.addField("*").addField("score");
solrQuery.addFilterQuery(String.format("%s:%s", FIELD_TYPE, TYPE_MESSAGE));
solrQuery.addFilterQuery(String.format("%s:0",FIELD_MESSAGE_IDX));
solrQuery.addSort("score", SolrQuery.ORDER.desc).addSort(FIELD_VOTE, SolrQuery.ORDER.desc);
// #39 - paging
solrQuery.setStart((int) offset);
solrQuery.setRows(pageSize);
//since #46 the client field is used to filter for the current user
addClientFilter(solrQuery, conversation);
addPropertyFilters(solrQuery, conversation, conf);
return new ConversationMltRequest(solrQuery, mltQuery.getContent());
}
示例9: buildSolrRequest
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
protected QueryRequest buildSolrRequest(ComponentConfiguration conf, Template intent, Conversation conversation, long offset, int pageSize, MultiValueMap<String, String> queryParams) {
final ConversationSearchQuery searchQuery = buildQuery(conf, intent, conversation);
if (searchQuery == null) {
return null;
}
// TODO: build the real request.
final SolrQuery solrQuery = new SolrQuery(searchQuery.getKeyword().stream().reduce((s, s2) -> s + " OR " + s2).orElse("*:*"));
solrQuery.addField("*").addField("score");
solrQuery.set(CommonParams.DF, "text");
solrQuery.addFilterQuery(String.format("%s:%s",FIELD_TYPE, TYPE_MESSAGE));
solrQuery.addSort("score", SolrQuery.ORDER.desc).addSort("vote", SolrQuery.ORDER.desc);
// #39 - paging
solrQuery.setStart((int) offset);
solrQuery.setRows(pageSize);
//since #46 the client field is used to filter for the current user
addClientFilter(solrQuery, conversation);
addPropertyFilters(solrQuery, conversation, conf);
return new QueryRequest(solrQuery);
}
示例10: getDatasetCount
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public long getDatasetCount() throws SearchException{
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
solrQuery.setFilterQueries(SearchFields.TYPE+":datasets",
SearchFields.PUBLICATION_STATUS+":Published");
solrQuery.setStart(0);
solrQuery.setRows(0);
QueryResponse queryResponse = null;
try {
queryResponse = solrServer.query(solrQuery);
return queryResponse.getResults().getNumFound();
} catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {
logger.log(Level.INFO, null, ex);
throw new SearchException("Internal Dataverse Search Engine Error", ex);
}
}
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:17,代碼來源:SolrSearchServiceBean.java
示例11: getDataverseCount
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public long getDataverseCount() throws SearchException{
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
solrQuery.setFilterQueries(SearchFields.TYPE+":dataverses",
SearchFields.PUBLICATION_STATUS+":Published");
solrQuery.setStart(0);
solrQuery.setRows(0);
QueryResponse queryResponse = null;
try {
queryResponse = solrServer.query(solrQuery);
return queryResponse.getResults().getNumFound();
} catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {
logger.log(Level.INFO, null, ex);
throw new SearchException("Internal Dataverse Search Engine Error", ex);
}
}
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:17,代碼來源:SolrSearchServiceBean.java
示例12: getHeader
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public Optional<Header> getHeader(String mcrId) {
SolrQuery query = getBaseQuery(CommonParams.FQ);
query.set(CommonParams.Q, "id:" + MCRSolrUtils.escapeSearchValue(mcrId));
query.setRows(1);
// do the query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
try {
QueryResponse response = solrClient.query(query);
SolrDocumentList results = response.getResults();
if (!results.isEmpty()) {
return Optional.of(toHeader(results.get(0), getSetResolver(results)));
}
} catch (Exception exc) {
LOGGER.error("Unable to handle solr request", exc);
}
return Optional.empty();
}
示例13: getQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getQuery() {
SolrQuery solrQuery = new SolrQuery();
MCRConfiguration config = MCRConfiguration.instance();
// query
String idQuery = getResult().stream()
.map(getIdentifier())
.map(MCRSolrUtils::escapeSearchValue)
.collect(Collectors.joining(" OR ", "id:(", ")"));
solrQuery.setQuery(idQuery);
solrQuery.setFilterQueries(query);
solrQuery.setFields("id");
solrQuery.setRows(getResult().size());
// request handler
solrQuery.setRequestHandler(config.getString(getConfigPrefix() + "Search.RequestHandler", "/select"));
return solrQuery;
}
示例14: checkSitemapFile
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* The method computes the number of sitemap files. If we have less than
* <em>numberOfURLs</em> URLs and only one MyCoRe type the sitemap_google.xml
* contained all URLs. Otherwise it split the sitemap in an sitemap_google.xml
* index file and a lot of sitemap_google_xxxx.xml URL files.
*
* @return the number of files, one for a single sitemap_google.xml file, more than
* one for the index and all parts.
*
*/
protected final int checkSitemapFile() throws IOException {
int number = 0;
QueryResponse response;
SolrQuery query = new SolrQuery();
query.setQuery(SOLR_QUERY);
query.setRows(Integer.MAX_VALUE);
query.setParam("fl", "id,modified");
try {
response = MCRSolrClientFactory.getSolrClient().query(query);
objidlist = response.getResults().stream().map((document) -> {
String id = (String) document.getFieldValue("id");
Date modified = (Date) document.getFieldValue("modified");
return new MCRObjectIDDateImpl(modified, id);
}).collect(Collectors.toList());
} catch (SolrServerException e) {
LOGGER.error(e);
}
number = objidlist.size() / numberOfURLs;
if (objidlist.size() % numberOfURLs != 0)
number++;
return number;
}
示例15: getCount
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public long getCount() throws SwordServerException {
try {
// make a copy to prevent multi threading issues
final SolrQuery queryCopy = this.solrQuery.getCopy();
// only need the numFound
queryCopy.setStart(0);
queryCopy.setRows(0);
final QueryResponse queryResponse = MCRSolrClientFactory.getSolrClient().query(queryCopy);
return queryResponse.getResults().getNumFound();
} catch (SolrServerException | IOException e) {
throw new SwordServerException(
"Error while getting count with MCRSword2SolrObjectIDSupplier and Query: " + this.solrQuery,
e);
}
}