當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryResponse.getFacetFields方法代碼示例

本文整理匯總了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;
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:17,代碼來源:SearchResultsDaoImpl.java

示例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;
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:22,代碼來源:FacetValueCountsCollector.java

示例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;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:63,代碼來源:SolrProductSearch.java

示例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;
    }
 
開發者ID:hackty,項目名稱:hadooptools,代碼行數:79,代碼來源:QueryFileServiceSolrMRImpl.java

示例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() );
}
 
開發者ID:europeana,項目名稱:search,代碼行數:69,代碼來源:SolrExampleTests.java


注:本文中的org.apache.solr.client.solrj.response.QueryResponse.getFacetFields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。