本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.setSort方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.setSort方法的具體用法?Java SolrQuery.setSort怎麽用?Java SolrQuery.setSort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.setSort方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getVersionAndInstallIfNecessary
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public Long getVersionAndInstallIfNecessary(String dependency) {
try {
SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency));
query.setSort("version", SolrQuery.ORDER.desc);
QueryResponse response = client.query(".system",query);
if(response.getResults().getNumFound() > 0) { //should could look for updates here as well?
return Long.valueOf(response.getResults().get(0).get("version").toString());
} else {
Path configDirectory = Files.createTempDirectory(dependency);
Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency);
return uploadRuntimeLib(dependency, jarFile);
}
} catch (SolrServerException | IOException e) {
logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues.");
return -1L;
}
}
示例4: getAllBooks
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public List<BookEntry> getAllBooks(List<WatchList> watchList) throws SolrServerException {
if (watchList.isEmpty()) {
return Collections.EMPTY_LIST;
}
String searchString = "id:(";
for (WatchList watchListItem : watchList) {
searchString = searchString + "\"" +watchListItem.getBookId() +"\",";
}
searchString = searchString.substring(0, searchString.length()-1) + ")";
SolrQuery query = new SolrQuery();
query.setRows(20);
query.setStart(0);
query.setQuery(searchString);
query.setSort(SolrQuery.SortClause.asc("author"));
query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
return bookService.searchBooks(query).getBeans(BookEntry.class);
}
示例5: getSolrQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public SolrQuery getSolrQuery(List<WatchList> watchList) {
if (watchList.isEmpty()) {
return null;
}
String searchString = "id:(";
for (WatchList watchListItem : watchList) {
searchString = searchString + "\"" +watchListItem.getBookId() +"\",";
}
searchString = searchString.substring(0, searchString.length()-1) + ")";
SolrQuery query = new SolrQuery();
query.setRows(20);
query.setStart(0);
query.setQuery(searchString);
query.setSort(SolrQuery.SortClause.asc("author"));
query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
return query;
}
示例6: searchSolrIndexSorted
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public QueryResponse searchSolrIndexSorted(String queryString, String fields, int rows, int startOffset, String sortField) throws SolrServerException {
SolrServer solr = null;
try {
solr = bookeryService.getSolrConnection();
} catch (IOException ex) {
throw new SolrServerException(ex.getMessage());
}
SolrQuery query = new SolrQuery();
query.setQuery(queryString);
query.setRows(rows);
query.setStart(startOffset);
query.setSort(sortField, SolrQuery.ORDER.desc);
query.setFields(fields);
QueryResponse rsp = solr.query(query);
return rsp;
}
示例7: 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;
}
}
示例8: getRemoteDocument
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Get document to display at a specific row index. The document is
* retrieved from the cache. If it is not in the cache, then we fetch a new
* page of results and we populate the cache.
*
* @param rowIndex
* Row index.
* @return Solr document.
* @throws SophieException
* If the document could not be fetched from Solr.
*/
private SolrDocument getRemoteDocument(int rowIndex) throws SophieException {
// Compute page ID.
int page = rowIndex / PAGE_SIZE;
// If page is not in the cache, then fetch it from Solr and populate the
// cache.
if (!pages.containsKey(page)) {
SolrQuery query = getBaseQuery(page * PAGE_SIZE, PAGE_SIZE);
query.setSort(sortField, sortOrder);
try {
pages.put(page, Sophie.client.query(query).getResults());
} catch (SolrServerException | IOException | SolrException e) {
throw new SophieException("Unable to fetch remote document " + rowIndex, e);
}
}
// Return Solr document from the cache.
return pages.get(page).get(rowIndex % PAGE_SIZE);
}
示例9: execute
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public SearchResult<? extends Result> execute(ComponentConfiguration conf, Template intent, Conversation conversation, MultiValueMap<String, String> queryParams) throws IOException {
// read default page-size from builder-configuration
int pageSize = conf.getConfiguration(CONFIG_KEY_PAGE_SIZE, 3);
// if present, a queryParam 'rows' takes precedence.
pageSize = toInt(queryParams.getFirst("rows"), pageSize);
long offset = toInt(queryParams.getFirst("start"), 0);
final QueryRequest solrRequest = buildSolrRequest(conf, intent, conversation, offset, pageSize, queryParams);
if (solrRequest == null) {
return new SearchResult<ConversationResult>(pageSize);
}
try (SolrClient solrClient = solrServer.getSolrClient(conversationCore)) {
final NamedList<Object> response = solrClient.request(solrRequest);
final QueryResponse solrResponse = new QueryResponse(response, solrClient);
final SolrDocumentList solrResults = solrResponse.getResults();
final List<ConversationResult> results = new ArrayList<>();
for (SolrDocument solrDocument : solrResults) {
//get the answers /TODO hacky, should me refactored (at least ordered by rating)
SolrQuery query = new SolrQuery("*:*");
query.add("fq",String.format("conversation_id:\"%s\"",solrDocument.get("conversation_id")));
query.add("fq", "message_idx:[1 TO *]");
query.setFields("*","score");
query.setSort("time", SolrQuery.ORDER.asc);
//query.setRows(3);
QueryResponse answers = solrClient.query(query);
results.add(toHassoResult(conf, solrDocument, answers.getResults(), intent.getType()));
}
return new SearchResult<>(solrResults.getNumFound(), solrResults.getStart(), pageSize, results);
} catch (SolrServerException e) {
throw new IOException(e);
}
}
示例10: enter
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
SolrQuery.SortClause sortClause = SolrQuery.SortClause.asc("author");
String searchString = SolrSearchUtil.generateSearchString(appHeader.getSearchText());
String[] params = event.getParameters().split("/");
if (params.length > 0) {
String sortParameter = params[0];
switch(sortParameter) {
case "author":
sortClause = SolrQuery.SortClause.asc("author");
break;
case "likes":
sortClause = SolrQuery.SortClause.desc("likes");
break;
case "downloads":
sortClause = SolrQuery.SortClause.desc("downloadcount");
break;
}
if (params.length > 1) {
String viewer = SecurityUtils.getSubject().getPrincipal().toString();
searchString = SolrSearchUtil.addNewBooksSearchString(viewer, searchString);
}
}
SolrQuery query = new SolrQuery();
query.setRows(20);
query.setStart(0);
query.setQuery(searchString);
query.setSort(sortClause);
query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
searchLayout.searchBooks(query,true);
}
示例11: createQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery createQuery(String query) {
SolrQuery q = new SolrQuery("*:*");
// TODO: Should we add a request handler to the solr cluster to get metrics
// on the volume and/or performance of these searches in their own bucket?
q.setFilterQueries(query);
q.setFields(SOLR_FIELDS);
q.setSort(SortClause.asc(SolrEnum.ID.toString()));
q.setRows(solrReadSize);
return q;
}
示例12: enter
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
try {
bookCount.setValue("Aktuell sind "+presenter.getBookCount()+" Bücher in der Bookery");
String searchString = SolrSearchUtil.generateSearchString("");
SolrQuery query = new SolrQuery();
query.setRows(6);
query.setStart(0);
query.setQuery(searchString);
query.setSort(SolrQuery.SortClause.desc("likes"));
query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
QueryResponse response = presenter.searchBooks(query);
mostLikedLane.loadLane("Beliebteste Bücher", response.getBeans(BookEntry.class),SearchView.id + "/likes");
query.setSort(SolrQuery.SortClause.desc("downloadcount"));
response = presenter.searchBooks(query);
mostLoadedLane.loadLane("Meist geladene Bücher", response.getBeans(BookEntry.class),SearchView.id + "/downloads");
searchString = SolrSearchUtil.addNewBooksSearchString(SecurityUtils.getSubject().getPrincipal().toString(), searchString);
query.setQuery(searchString);
query.setSort(SolrQuery.SortClause.asc("author"));
response = presenter.searchBooks(query);
newBooksLane.loadLane("Neue Bücher", response.getBeans(BookEntry.class),SearchView.id + "/auhtor/true");
query = presenter.getWatchListQuery(SecurityUtils.getSubject().getPrincipal().toString());
if (query != null) {
query.setRows(6);
response = presenter.searchBooks(query);
watchListLane.loadLane("Deine Merkliste", response.getBeans(BookEntry.class), WatchListView.id);
}
else {
watchListLane.loadLane("Deine Merkliste", Collections.EMPTY_LIST, WatchListView.id);
}
} catch (SolrServerException ex) {
logger.error(ex,ex);
}
}
示例13: getRecordReader
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public RecordReader<IntWritable, LWDocumentWritable> getRecordReader(
InputSplit split, JobConf job, Reporter reporter) throws IOException {
LWInputSplit lwSplit = (LWInputSplit) split;
SolrClient solr;
String collection = job.get(SOLR_COLLECTION);
String query = job.get(SOLR_QUERY, "*:*");
if (lwSplit.isZk) {
SolrSecurity.setSecurityConfig(job);
if (lwSplit.isShard) {
solr = new HttpSolrClient.Builder()
.withBaseSolrUrl(lwSplit.getConnectionUri())
.build();
} else {
// somehow the list of shard is unavailable
solr = new CloudSolrClient.Builder()
.withZkHost(lwSplit.getConnectionUri())
.build();
((CloudSolrClient) solr).setDefaultCollection(collection);
}
} else {
String connectionUri = lwSplit.getConnectionUri();
int queueSize = job.getInt("solr.client.queue.size", 100);
int threadCount = job.getInt("solr.client.threads", 1);
if (!connectionUri.endsWith("/")) {
connectionUri += "/";
}
connectionUri += collection;
solr = new ConcurrentUpdateSolrClient.Builder(connectionUri)
.withQueueSize(queueSize)
.withThreadCount(threadCount)
.build();
}
SolrQuery solrQuery = new SolrQuery(query);
solrQuery.set("distrib", false);
solrQuery.set("collection", collection);
if (solrQuery.getRows() == null) {
solrQuery.setRows(DEFAULT_PAGE_SIZE); // default page size
}
solrQuery.setSort(SolrQuery.SortClause.asc("id"));
return new LWRecordReader(solr, solrQuery, "*");
}