本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.setFacetSort方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.setFacetSort方法的具體用法?Java SolrQuery.setFacetSort怎麽用?Java SolrQuery.setFacetSort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.setFacetSort方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: enableFaceting
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private boolean enableFaceting(SolrQuery solrQuery, FacetQuery query) {
FacetOptions facetOptions = query.getFacetOptions();
if (facetOptions == null || !facetOptions.hasFacets()) {
return false;
}
solrQuery.setFacet(true);
solrQuery.setFacetMinCount(facetOptions.getFacetMinCount());
solrQuery.setFacetLimit(facetOptions.getPageable().getPageSize());
if (facetOptions.getPageable().getPageNumber() > 0) {
int offset = Math.max(0, facetOptions.getPageable().getOffset());
solrQuery.set(FacetParams.FACET_OFFSET, offset);
}
if (FacetOptions.FacetSort.INDEX.equals(facetOptions.getFacetSort())) {
solrQuery.setFacetSort(FacetParams.FACET_SORT_INDEX);
}
return true;
}
示例2: getRemoteFacets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Get a list of remote facets keyed by field name.
*
* @param fields
* Fields.
* @return List of facets keyed by field name.
* @throws SophieException
* If facets could not be fetched.
*/
private Map<String, FacetField> getRemoteFacets(List<FieldInfo> fields) throws SophieException {
// Prepare query.
SolrQuery query = getBaseQuery(0, 0);
query.setFacet(true);
query.setFacetSort("index");
query.setFacetLimit(FACET_LIMIT);
query.setFacetMissing(true);
// For each field, determine whether Solr can generate a facet (fq works
// only on indexed fields). If yes, then list that field in the query.
for (FieldInfo field : fields) {
if (SolrUtils.getFlags(field).contains(FieldFlag.INDEXED)) {
query.addFacetField(field.getName());
}
}
// Send query.
Map<String, FacetField> facets = new HashMap<String, FacetField>();
try {
for (FacetField facet : Sophie.client.query(query).getFacetFields()) {
facets.put(facet.getName(), facet);
}
} catch (SolrServerException | IOException | SolrException e) {
throw new SophieException("Unable to fetch remote facets", e);
}
// Return facets keyed by field name.
return facets;
}