本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.addSort方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.addSort方法的具體用法?Java SolrQuery.addSort怎麽用?Java SolrQuery.addSort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.addSort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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;
}
示例3: addQueryOption
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void addQueryOption(String key, String value, SolrQuery query) {
switch(value){
case "name_asc":
query.setSort("taxon.rank_s_lower", ORDER.asc);
query.addSort("sortable", ORDER.asc);
break;
case "name_desc":
query.setSort("taxon.rank_s_lower", ORDER.asc);
query.addSort("sortable", ORDER.desc);
break;
case "relevance":
query.setSort("score", ORDER.desc);
query.addSort("taxon.rank_s_lower", ORDER.asc);
query.addSort("sortable", ORDER.asc);
break;
}
}
示例4: attachSortClause
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void attachSortClause(SolrQuery query, SearchCriteria searchCriteria, String defaultSort, List<Field> fields) {
Map<String, String> solrFieldKeyMap = getSolrFieldKeyMap(searchCriteria, fields);
String sortQuery = searchCriteria.getSortQuery();
if (StringUtils.isBlank(sortQuery)) {
sortQuery = defaultSort;
}
if (StringUtils.isNotBlank(sortQuery)) {
String[] sortFields = sortQuery.split(",");
for (String sortField : sortFields) {
String field = sortField.split(" ")[0];
if (solrFieldKeyMap.containsKey(field)) {
field = solrFieldKeyMap.get(field);
}
ORDER order = "desc".equals(sortField.split(" ")[1]) ? ORDER.desc : ORDER.asc;
if (field != null) {
query.addSort(new SortClause(field, order));
}
}
}
}
示例5: list
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
protected void list(final PatientSearch search, FrameTask task) throws FrameException {
if (!search.searchType("task")) return;
SolrQuery query = search.initQuery();
query.setQuery("domain:\"" + search.getQueryStr() + "\"");
query.addFilterQuery("domain:task");
query.addSort(SearchService.DATETIME, ORDER.desc);
QueryResponse results = execSolrQuery(query, task);
task.addAction(new SolrSearchAction(query, results) {
@Override
public List<SummaryItem> createSummaryItems(QueryResponse response) {
if (!search.searchType("task")) return null; // don't create results if we documents are filtered out
return super.createSummaryItems(response);
}
});
}
示例6: configureQueryForDocuments
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void configureQueryForDocuments(SolrQuery query) {
query.addFilterQuery("domain:document");
query.addSort("reference_date_time", ORDER.desc);
query.addField(Document.SOLR_LOCAL_TITLE_FIELD);
query.addField(Document.SOLR_DOC_DEF_UID_FIELD);
query.addField(Document.SOLR_DOCUMENT_STATUS_FIELD);
query.addField(Document.SOLR_AUTHOR_UID_FIELD);
query.addField(Document.SOLR_SIGNER_UID_FIELD);
query.addField(Document.SOLR_COSIGNER_UID_FIELD);
query.addField((Document.SOLR_ATTENDING_UID_FIELD));
query.addField(Document.SOLR_IS_INTERDISCIPLINARY_FIELD);
query.addField(Document.SOLR_INTERDISCIPLINARY_TYPE_FIELD);
query.addField(SearchService.PHRASE);
query.set(GroupParams.GROUP, true);
query.set(GroupParams.GROUP_FIELD, Document.SOLR_LOCAL_TITLE_FIELD);
query.setHighlight(true);
query.addHighlightField("body").addHighlightField("subject");
query.setHighlightFragsize(45);
query.setHighlightSnippets(5);
}
示例7: exec
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void exec(PatientSearch search, FrameTask task) throws FrameException {
// create + exec SOLR query
SolrQuery query = search.initQuery();
query.setParam("q.op", "OR");
query.setQuery("+all:\"" + ClientUtils.escapeQueryChars(search.getQueryStr()) + '"');
// search for the specific domains we don't have frames for
String domains = "obs procedure "; // encounter stuff
domains += "mh "; // other patient stuff
domains += "roadtrip auxiliary "; // CPE specific stuff
domains += "pov skin diagnosis ptf exam treatment"; // encounter flags
query.addFilterQuery("+domain: (" + domains + ")");
query.addFilterQuery("-removed:true");
query.addSort(SearchService.DATETIME, ORDER.desc);
query.setFields(SearchService.UID, SearchService.DATETIME,
SearchService.SUMMARY, SearchService.URL_FIELD,
SearchService.DOMAIN, SearchService.KIND,
SearchService.FACILITY);
task.addAction(new SolrSearchAction(query, execSolrQuery(query, task)));
}
示例8: prepareQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery prepareQuery(PatientSearch search, boolean highlight) {
SolrQuery query = search.initQuery();
query.addFilterQuery("domain:med");
query.addSort("overall_stop", ORDER.desc);
query.addField("qualified_name");
query.addField("va_type");
query.addField("last_filled");
query.addField("last_give");
query.addField(CLASS_FIELD);
query.set(GroupParams.GROUP, true);
query.set(GroupParams.GROUP_FIELD, "kind");
query.add(GroupParams.GROUP_FIELD, "qualified_name");
if (highlight) {
query.setHighlight(true);
query.addHighlightField("administration_comment");
query.addHighlightField("prn_reason");
query.setHighlightFragsize(72);
query.setHighlightSnippets(5);
}
return query;
}
示例9: testSimpleAgent
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Test
public void testSimpleAgent() {
assertEquals(0, this.commitAndGetSolrDocumentCount("*:*"));
HqAgentController.install("1", HQ_URL, QUEUE_DIRECTORY, SPACE_TOKEN, MARKER);
TestAgent testAgent = new TestAgent();
this.waitFor(5, SECONDS);
AgentControllerProvider.shutdown();
assertTrue(testAgent.getEventCount() > 0);
assertEquals(testAgent.getEventCount(), this.commitAndGetSolrDocumentCount("*:*"));
SolrQuery solrQuery = new SolrQuery("*:*");
solrQuery.addSort("global_id", ORDER.asc);
QueryResponse queryResponse = this.querySolr(solrQuery);
int documentCount = 0;
for (SolrDocument eachDocument : queryResponse.getResults()) {
assertEquals(String.valueOf(++documentCount), eachDocument.getFirstValue("global_id"));
assertEquals(MARKER, eachDocument.getFirstValue("marker"));
}
}
示例10: getEarliestRecordDatestamp
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public String getEarliestRecordDatestamp() throws SolrServerException {
try {
String searchStr = SolrConstants.ISWORK + ":true" + getAllSuffixes();
SolrQuery solrQuery = new SolrQuery(searchStr);
solrQuery.setRows(1);
solrQuery.addField(SolrConstants.DATECREATED);
solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
QueryResponse resp = server.query(solrQuery);
if (resp.getResults().size() > 0) {
SolrDocument doc = resp.getResults().get(0);
if (doc.getFieldValue(SolrConstants.DATECREATED) != null) {
Date d = new Date((Long) doc.getFieldValue(SolrConstants.DATECREATED));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// ;YYYY-MM-DDThh:mm:ssZ
SimpleDateFormat hours = new SimpleDateFormat("HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
hours.setTimeZone(TimeZone.getTimeZone("GMT"));
String yearMonthDay = format.format(d);
String hourMinuteSeconde = hours.format(d);
return yearMonthDay + "T" + hourMinuteSeconde + "Z";
}
}
} catch (NullPointerException e) {
logger.error(e.getMessage(), e);
}
return "";
}
示例11: applySortOptions
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public static SolrQuery applySortOptions(SolrQuery q, List<MCRSortBy> sortBy) {
for (MCRSortBy option : sortBy) {
SortClause sortClause = new SortClause(option.getFieldName(), option.getSortOrder() ? ORDER.asc
: ORDER.desc);
q.addSort(sortClause);
}
return q;
}
示例12: transform
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public SolrQuery transform(final Query query) {
final SolrQuery solrQuery = new SolrQuery(query.getQuery());
solrQuery.setParam("q.op", query.getDefaultOperator().name());
if (query.getCursorMark() != null) {
solrQuery.setParam(CursorMarkParams.CURSOR_MARK_PARAM, query.getCursorMark());
} else {
solrQuery.setStart(query.getOffset());
}
solrQuery.setRows(query.getRows());
if (query.getReturnFields() != null) {
query.getReturnFields().stream().forEach(f -> solrQuery.addField(f.getName()));
}
if (query.getHighlightFields() != null && !query.getHighlightFields().isEmpty()) {
solrQuery.setHighlight(true);
query.getHighlightFields().stream().forEach(hf -> solrQuery.addHighlightField(hf.getName()));
}
if (query.getFacetFields() != null) {
query.getFacetFields().stream().forEach(ff -> solrQuery.addFacetField(ff.getName()));
}
if (query.getSorts() != null) {
for (Sort sort : query.getSorts()) {
SolrQuery.ORDER solrOrder = sort.getSortOrder() == SortOrder.ASC ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc;
SolrQuery.SortClause sortClause = new SolrQuery.SortClause(sort.getField().getName(), solrOrder);
solrQuery.addSort(sortClause);
}
}
if (query.getFilterQueries() != null) {
query.getFilterQueries().stream().forEach(fq -> solrQuery.addFilterQuery(fq.getField().getName() + ":" + fq.getValue()));
}
if (query.getParams() != null) {
query.getParams().entrySet().stream().forEach(e -> solrQuery.add(e.getKey(), e.getValue()));
}
return solrQuery;
}
示例13: getQueryParams
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getQueryParams(BoundedSolrSource source) {
String query = source.spec.getQuery();
if (query == null) {
query = "*:*";
}
SolrQuery solrQuery = new SolrQuery(query);
solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
solrQuery.setRows(source.spec.getBatchSize());
solrQuery.addSort(uniqueKey, SolrQuery.ORDER.asc);
if (source.replica != null) {
solrQuery.setDistrib(false);
}
return solrQuery;
}
示例14: appendSort
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Append sorting parameters to {@link org.apache.solr.client.solrj.SolrQuery}
*
* @param solrQuery
* @param sort
*/
protected void appendSort(SolrQuery solrQuery, Sort sort) {
if (sort == null) {
return;
}
for (Order order : sort) {
solrQuery.addSort(order.getProperty(), order.isAscending() ? ORDER.asc : ORDER.desc);
}
}
示例15: exec
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void exec(RenderTask task) throws Exception {
if (this.solr == null) {
this.solr = task.getResource(SolrServer.class);
}
// create/edit query
String newQry = evalQueryString(task, getQueryString());
SolrQuery solrParams = new SolrQuery(newQry);
if (this.fq != null) {
solrParams.setFilterQueries(evalQueryString(task, this.fq));
}
// add sort+limit criteria (if found)
String sortCol = task.getParamStr("sort.col");
String sortDir = task.getParamStr("sort.dir");
int limit = task.getParamInt("row.count");
if (sortCol != null && sortDir != null) {
solrParams.addSort(sortCol, ORDER.valueOf(sortDir.toLowerCase()));
}
if (limit > 0) {
solrParams.setRows(limit);
}
// include debug info
// execute SOLR query and include debug info
modifySolrQuery(solrParams, task);
task.addAction(new DebugInfo("solr.query", solrParams.toString()));
QueryResponse resp = solr.query(solrParams);
mapResults(task, resp);
}