本文整理汇总了Java中org.apache.solr.client.solrj.response.QueryResponse.getFacetFields方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResponse.getFacetFields方法的具体用法?Java QueryResponse.getFacetFields怎么用?Java QueryResponse.getFacetFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.response.QueryResponse
的用法示例。
在下文中一共展示了QueryResponse.getFacetFields方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFacets
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
@Override
public List<FacetField> getFacets(SolrQuery query) {
//final QueryResponse response = fireQuery(sanitise(query));
//curation instance doesnt sanitase queries
final QueryResponse response = fireQuery(query);
final List<FacetField> facetFields = response.getFacetFields();
if (logger.isDebugEnabled()) {
if (facetFields.size() == 1) {
final FacetField field = facetFields.get(0);
logger.debug("Found facet field '{}' with {} values", field.getName(), field.getValueCount());
} else {
logger.debug("Found {} facet fields", facetFields.size());
}
}
return facetFields;
}
示例2: obtainFacetStats
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
private List<VloReport.Facet> obtainFacetStats(VloConfig config, SolrServer solrServer) throws SolrServerException {
final SolrQuery query = new SolrQuery();
query.setRows(0);
query.setFacet(true);
FacetConstants.AVAILABLE_FACETS.forEach((field) -> {
query.addFacetField(field);
});
query.setFacetLimit(-1);
final QueryResponse result = solrServer.query(query);
final List<FacetField> facetFields = result.getFacetFields();
final List<VloReport.Facet> facets
= facetFields.stream().map((field) -> {
final VloReport.Facet facet = new VloReport.Facet();
facet.setName(field.getName());
facet.setValueCount(field.getValueCount());
return facet;
}).collect(Collectors.toList());
return facets;
}
示例3: getAvailableCategories
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
/**
* Returns a map of the categories currently available under the root
* element.
*/
public static Map<String, Object> getAvailableCategories(DispatchContext dctx, Map<String, Object> context) {
Map<String, Object> result;
try {
boolean displayProducts = false;
if (UtilValidate.isNotEmpty(context.get("displayProducts")))
displayProducts = (Boolean) context.get("displayProducts");
int viewIndex = 0;
int viewSize = 9;
if (displayProducts) {
viewIndex = (Integer) context.get("viewIndex");
viewSize = (Integer) context.get("viewSize");
}
String catalogId = null;
if (UtilValidate.isNotEmpty(context.get("catalogId")))
catalogId = (String) context.get("catalogId");
Boolean excludeVariants = (Boolean) context.get("excludeVariants");
List<String> currentTrail = UtilGenerics.checkList(context.get("currentTrail"));
// String productCategoryId = (String)
// context.get("productCategoryId") != null ?
// CategoryUtil.getCategoryNameWithTrail((String)
// context.get("productCategoryId"), catalogId, dctx, currentTrail): null;
String productCategoryId = (String) context.get("productCategoryId") != null
? SolrCategoryUtil.getCategoryNameWithTrail((String) context.get("productCategoryId"), catalogId, dctx, currentTrail) : null;
if (Debug.verboseOn()) Debug.logVerbose("Solr: getAvailableCategories: productCategoryId: " + productCategoryId, module);
Map<String, Object> query = SolrCategoryUtil.categoriesAvailable(catalogId, productCategoryId, (String) context.get("productId"), displayProducts,
viewIndex, viewSize, null, excludeVariants);
QueryResponse cat = (QueryResponse) query.get("rows");
result = ServiceUtil.returnSuccess();
result.put("numFound", (long) 0);
Map<String, Object> categories = new HashMap<>();
List<FacetField> catList = (List<FacetField>) cat.getFacetFields();
for (Iterator<FacetField> catIterator = catList.iterator(); catIterator.hasNext();) {
FacetField field = (FacetField) catIterator.next();
List<Count> catL = (List<Count>) field.getValues();
if (catL != null) {
// log.info("FacetFields = "+catL);
for (Iterator<Count> catIter = catL.iterator(); catIter.hasNext();) {
FacetField.Count f = (FacetField.Count) catIter.next();
if (f.getCount() > 0) {
categories.put(f.getName(), Long.toString(f.getCount()));
}
}
result.put("categories", categories);
result.put("numFound", cat.getResults().getNumFound());
// log.info("The returned map is this:"+result);
}
}
} catch (Exception e) {
result = ServiceUtil.returnError(e.toString());
result.put("numFound", (long) 0);
}
return result;
}
示例4: queryFileTypes
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
/**
* 根据给出的关键字查询并获取FileType
*
* @param keyword
* @return List<FileTypeModel>
*/
@Override
public List<FileTypeModel> queryFileTypes(String keyword, Map filterQuery) {
String role = (String) filterQuery.get("role");
if(role == null || "".equals(role)) {
role = "anonymous";
}
List<FileTypeModel> models = new ArrayList<FileTypeModel>();
// CloudSolrServer cloudSolrServer = CloudSolrUtils.getCloudSolrServer(); //创建cloudSolrServer
ApplicationContext ctx =
new ClassPathXmlApplicationContext("spring/hadooptools-spring-config.xml");
cloudSolrServer = (CloudSolrServer)ctx.getBean("cloudSolrServer");
cloudSolrServer.setDefaultCollection(defaultCollection);
cloudSolrServer.setZkClientTimeout(zkClientTimeout);
cloudSolrServer.setZkConnectTimeout(zkConnectTimeout);
cloudSolrServer.connect(); //连接zookeeper
SolrQuery query = new SolrQuery();//建立一个新的查询
query.setQuery("content_text:" + keyword);
query.setFilterQueries(
"(" + getRoleFilter(role) + ")"
);
query.setFacet(true);//设置facet=on
query.addFacetField("content_type");//设置需要facet的字段
// query.setFacetLimit(10);//限制facet返回的数量
QueryResponse response = null;
try {
response = cloudSolrServer.query(query);
} catch (SolrServerException e) {
e.printStackTrace();
}
List<FacetField> facets = response.getFacetFields();//返回的facet列表(由设置的facet字段决定这里只有content_type)
for (FacetField facet : facets) {
// System.out.println(facet.getName());
// System.out.println("----------------");
int[] sum = new int[6];
String[] str = {"doc","xls","ppt","pdf","txt","others"};
List<FacetField.Count> counts = facet.getValues();
for (FacetField.Count count : counts) {
// System.out.println(count.getName() + ":" + count.getCount());
String name = getFileTypeName(count.getName());
int num = (int)count.getCount();
if(name.equals("doc") || name.equals("docx")) {
sum[0] += num;
} else if(name.equals("xls") || name.equals("xlsx")) {
sum[1] += num;
} else if(name.equals("ppt") || name.equals("pptx")) {
sum[2] += num;
} else if(name.equals("pdf")) {
sum[3] += num;
} else if(name.equals("txt")) {
sum[4] += num;
} else {
sum[5] += num;
}
}
for(int i=0; i<6; i++) {
FileTypeModel model = new FileTypeModel();
model.setTypeName(str[i]);
model.setTypeCount(sum[i]);
models.add(model);//添加model
}
}
// cloudSolrServer.shutdown();//关闭cloudSolrServer
return models;
}
示例5: testFaceting
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
@Test
public void testFaceting() throws Exception
{
SolrServer server = getSolrServer();
// Empty the database...
server.deleteByQuery( "*:*" );// delete everything!
server.commit();
assertNumFound( "*:*", 0 ); // make sure it got in
ArrayList<SolrInputDocument> docs = new ArrayList<>(10);
for( int i=1; i<=10; i++ ) {
SolrInputDocument doc = new SolrInputDocument();
doc.setField( "id", i+"", 1.0f );
if( (i%2)==0 ) {
doc.addField( "features", "two" );
}
if( (i%3)==0 ) {
doc.addField( "features", "three" );
}
if( (i%4)==0 ) {
doc.addField( "features", "four" );
}
if( (i%5)==0 ) {
doc.addField( "features", "five" );
}
docs.add( doc );
}
server.add( docs );
server.commit();
SolrQuery query = new SolrQuery( "*:*" );
query.remove( FacetParams.FACET_FIELD );
query.addFacetField( "features" );
query.setFacetMinCount( 0 );
query.setFacet( true );
query.setRows( 0 );
QueryResponse rsp = server.query( query );
assertEquals( docs.size(), rsp.getResults().getNumFound() );
List<FacetField> facets = rsp.getFacetFields();
assertEquals( 1, facets.size() );
FacetField ff = facets.get( 0 );
assertEquals( "features", ff.getName() );
// System.out.println( "111: "+ff.getValues() );
// check all counts
assertEquals( "[two (5), three (3), five (2), four (2)]", ff.getValues().toString() );
// should be the same facets with minCount=0
query.setFilterQueries( "features:two" );
rsp = server.query( query );
ff = rsp.getFacetField( "features" );
assertEquals( "[two (5), four (2), five (1), three (1)]", ff.getValues().toString() );
// with minCount > 3
query.setFacetMinCount( 4 );
rsp = server.query( query );
ff = rsp.getFacetField( "features" );
assertEquals( "[two (5)]", ff.getValues().toString() );
// with minCount > 3
query.setFacetMinCount( -1 );
rsp = server.query( query );
ff = rsp.getFacetField( "features" );
// System.out.println( rsp.getResults().getNumFound() + " :::: 444: "+ff.getValues() );
}