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


Java SolrQuery.setFacet方法代碼示例

本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.setFacet方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.setFacet方法的具體用法?Java SolrQuery.setFacet怎麽用?Java SolrQuery.setFacet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.solr.client.solrj.SolrQuery的用法示例。


在下文中一共展示了SolrQuery.setFacet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: obtainCollectionCounts

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private List<VloReport.CollectionCount> obtainCollectionCounts(SolrServer solrServer) throws SolrServerException {
    final SolrQuery query = new SolrQuery();
    query.setRows(0);
    query.setFacet(true);
    query.addFacetField(FacetConstants.FIELD_COLLECTION);
    query.setFacetLimit(Integer.MAX_VALUE);

    final QueryResponse result = solrServer.query(query);
    final FacetField collectionField = result.getFacetField(FacetConstants.FIELD_COLLECTION);
    logger.debug("Collection field: {}", collectionField.getValues());

    final List<VloReport.CollectionCount> counts
            = collectionField.getValues().stream().map((count) -> {
                VloReport.CollectionCount collectionCount = new VloReport.CollectionCount();
                collectionCount.setCollection(count.getName());
                collectionCount.setCount(count.getCount());
                return collectionCount;
            }).collect(Collectors.toList());
    return counts;
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:21,代碼來源:CollectionsCollector.java

示例2: obtainFacetStats

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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: attachFacets

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Notifies solr about which facets you want it to determine results and counts for
 * 
 * @param query
 * @param namedFacetMap
 */
protected void attachFacets(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap) {
    query.setFacet(true);
    for (Entry<String, SearchFacetDTO> entry : namedFacetMap.entrySet()) {
        SearchFacetDTO dto = entry.getValue();
        String facetTagField = entry.getValue().isActive() ? shs.getGlobalFacetTagField() : entry.getKey();

        // Clone the list - we don't want to remove these facets from the DB
        List<SearchFacetRange> facetRanges = new ArrayList<SearchFacetRange>(dto.getFacet().getSearchFacetRanges());

        if (extensionManager != null) {
            extensionManager.getProxy().filterSearchFacetRanges(dto, facetRanges);
        }

        if (facetRanges != null && facetRanges.size() > 0) {
            for (SearchFacetRange range : facetRanges) {
                query.addFacetQuery(getSolrTaggedFieldString(entry.getKey(), facetTagField, "ex", range));
            }
        } else {
            query.addFacetField(getSolrTaggedFieldString(entry.getKey(), facetTagField, "ex", null));
        }
    }
}
 
開發者ID:passion1014,項目名稱:metaworks_framework,代碼行數:29,代碼來源:SolrSearchServiceImpl.java

示例4: 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;
}
 
開發者ID:yiduwangkai,項目名稱:dubbox-solr,代碼行數:18,代碼來源:DefaultQueryParser.java

示例5: attachFacets

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void attachFacets(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap) {
    query.setFacet(true);
    for (Entry<String, SearchFacetDTO> entry : namedFacetMap.entrySet()) {
        SearchFacetDTO dto = entry.getValue();

        // Clone the list - we don't want to remove these facets from the DB
        List<SearchFacetRange> facetRanges = new ArrayList<SearchFacetRange>(dto.getFacet().getSearchFacetRanges());

        if (extensionManager != null) {
            extensionManager.getProxy().filterSearchFacetRanges(dto, facetRanges);
        }

        if (facetRanges != null && facetRanges.size() > 0) {
            for (SearchFacetRange range : facetRanges) {
                query.addFacetQuery(getSolrTaggedFieldString(entry.getKey(), "key", range));
            }
        } else {
            query.addFacetField(getSolrTaggedFieldString(entry.getKey(), "key", null));
        }
    }
}
 
開發者ID:takbani,項目名稱:blcdemo,代碼行數:23,代碼來源:SolrHelperServiceImpl.java

示例6: SolrFacetQueryFactoryImpl

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 *
 */
public SolrFacetQueryFactoryImpl() {
    // create the base query (copied on each request to create new queries)
    baseQuery = new SolrQuery();
    baseQuery.setRows(0);
    baseQuery.setFacet(true);
    baseQuery.setFacetMinCount(1);
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:11,代碼來源:SolrFacetQueryFactoryImpl.java

示例7: testGetFacets

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Test of getFacets method, of class SearchResultsDaoImpl.
 *
 * @throws java.lang.Exception
 */
@Test
public void testGetFacets() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setRows(10);
    query.setStart(0);
    query.setFields(FIELD_NAME, FIELD_ID, FIELD_DESCRIPTION);
    query.setQuery(null);

    query.setFacet(true);
    query.setFacetMinCount(1);
    query.addFacetField(FIELD_COLLECTION, FIELD_COUNTRY);

    List<FacetField> facetFields = instance.getFacets(query);
    assertNotNull(facetFields);
    assertEquals(2, facetFields.size());

    // 1 collection
    assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf(
            Matchers.<FacetField>hasProperty("name", equalTo(FIELD_COLLECTION)),
            Matchers.<FacetField>hasProperty("valueCount", equalTo(1)))));

    // 2 countries
    assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf(
            Matchers.<FacetField>hasProperty("name", equalTo(FIELD_COUNTRY)),
            Matchers.<FacetField>hasProperty("valueCount", equalTo(2)))));
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:32,代碼來源:SearchResultsDaoImplTest.java

示例8: addFacetParameters

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void addFacetParameters(SolrQuery query) {
  query.setFacet(true);
  query.addFacetField(facetFieldExtractor.getRandomFacetField());
  query.setFacetMinCount(facetMinCount);
  query.setFacetLimit(facetLimit);
  if(facetMethod != null && !"".equals(facetMethod)) {
    query.add("facet.method", facetMethod);
  }
  
}
 
開發者ID:lafourchette,項目名稱:solrmeter,代碼行數:11,代碼來源:ComplexQueryGenerator.java

示例9: modifySolrQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
protected void modifySolrQuery(SolrQuery qry, RenderTask task) {
	qry.setFacet(true);
	qry.setRows(0);
	qry.setFacetMinCount(1);
	qry.addFacetField(this.facetField);
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:8,代碼來源:Query.java

示例10: getEventPropertyNames

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public Set<String> getEventPropertyNames(String... globalAgentIds) {
    SolrQuery solrQuery = new SolrQuery(ALL_DOCS_QUERY);
    solrQuery.setRows(0);

    StringBuilder globalAgentIdFilterQuery = new StringBuilder();
    globalAgentIdFilterQuery.append(FIELD_GLOBAL_AGENT_ID);
    globalAgentIdFilterQuery.append(":(");
    for (String eachGlobalAgentId : globalAgentIds) {
        globalAgentIdFilterQuery.append(escapeSolr(eachGlobalAgentId));
        globalAgentIdFilterQuery.append(" OR ");
    }
    globalAgentIdFilterQuery.setLength(globalAgentIdFilterQuery.length() - 4);
    globalAgentIdFilterQuery.append(')');
    solrQuery.addFilterQuery(globalAgentIdFilterQuery.toString());

    solrQuery.setFacet(true);
    solrQuery.setFacetMinCount(1);
    solrQuery.addFacetField(FIELD_PROPERTY_ID);

    try {
        QueryResponse response = this.solrClient.query(solrQuery);

        Set<String> result = new TreeSet<>();
        for (Count eachCount : response.getFacetField(FIELD_PROPERTY_ID).getValues()) {
            result.add(eachCount.getName());
        }

        return result;
    } catch (SolrException | SolrServerException | IOException e) {
        throw new DataRetrievalException("Failed to retrieve event property names", e);
    }
}
 
開發者ID:Indoqa,項目名稱:logspace,代碼行數:34,代碼來源:SolrAgentService.java

示例11: 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;
}
 
開發者ID:fengtan,項目名稱:sophie,代碼行數:39,代碼來源:DocumentsTable.java

示例12: categoriesAvailable

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, 
        String facetPrefix, boolean displayproducts, int viewIndex, int viewSize, List<String> queryFilters, Boolean excludeVariants, String core) {
    // create the data model
    Map<String, Object> result = new HashMap<>();
    HttpSolrClient client = null;
    QueryResponse returnMap = new QueryResponse();
    try {
        // do the basic query
        client = SolrUtil.getHttpSolrClient(core);
        // create Query Object
        String query = "inStock[1 TO *]";
        if (categoryId != null)
            query += " +cat:"+ SolrExprUtil.escapeTermFull(categoryId);
        else if (productId != null)
            query += " +productId:" + SolrExprUtil.escapeTermFull(productId);
        SolrQuery solrQuery = new SolrQuery();
        solrQuery.setQuery(query);

        if (catalogId != null)
            solrQuery.addFilterQuery("+catalog:" + SolrExprUtil.escapeTermFull(catalogId));
        
        if (excludeVariants == null) excludeVariants = SolrProductSearch.excludeVariantsDefault;
        if (excludeVariants)
            SolrProductUtil.addExcludeVariantsFilter(solrQuery);
        
        if (displayproducts) {
            if (viewSize > -1) {
                solrQuery.setRows(viewSize);
            } else
                solrQuery.setRows(50000);
            if (viewIndex > -1) {
                // 2016-04-01: This must be calculated
                //solrQuery.setStart(viewIndex);
                if (viewSize > 0) {
                    solrQuery.setStart(viewSize * viewIndex);
                }
            }
        } else {
            solrQuery.setFields("cat");
            solrQuery.setRows(0);
        }
        
        if(UtilValidate.isNotEmpty(facetPrefix)){
            solrQuery.setFacetPrefix(facetPrefix);
        }
        
        solrQuery.setFacetMinCount(0);
        solrQuery.setFacet(true);
        solrQuery.addFacetField("cat");
        solrQuery.setFacetLimit(-1);
        if (Debug.verboseOn()) Debug.logVerbose("solr: solrQuery: " + solrQuery, module);
        returnMap = client.query(solrQuery,METHOD.POST);
        result.put("rows", returnMap);
        result.put("numFound", returnMap.getResults().getNumFound());
    } catch (Exception e) {
        Debug.logError(e.getMessage(), module);
    }
    return result;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:60,代碼來源:SolrCategoryUtil.java

示例13: queryFileTypes

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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

示例14: testGetFieldsPhaseError

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testGetFieldsPhaseError() throws SolrServerException {
  BadResponseWriter.failOnGetFields = true;
  BadResponseWriter.failOnGetTopIds = false;
  SolrQuery query = new SolrQuery();
  query.setQuery("subject:batman OR subject:superman");
  query.addField("id");
  query.addField("subject");
  query.set("distrib", "true");
  query.set("shards", shard1 + "," + shard2);
  query.set(ShardParams.SHARDS_INFO, "true");
  query.set("debug", "true");
  query.set("stats", "true");
  query.set("stats.field", "id");
  query.set("mlt", "true");
  query.set("mlt.fl", "title");
  query.set("mlt.count", "1");
  query.set("mlt.mintf", "0");
  query.set("mlt.mindf", "0");
  query.setHighlight(true);
  query.addFacetField("id");
  query.setFacet(true);
  
  ignoreException("Dummy exception in BadResponseWriter");
  try {
    collection1.query(query);
    fail("Should get an exception");
  } catch (Exception e) {
    //expected
  }
  query.set(ShardParams.SHARDS_TOLERANT, "true");
  QueryResponse response = collection1.query(query);
  assertTrue(response.getResponseHeader().getBooleanArg("partialResults"));
  NamedList<Object> shardsInfo = ((NamedList<Object>)response.getResponse().get("shards.info"));
  boolean foundError = false;
  for (int i = 0; i < shardsInfo.size(); i++) {
    if (shardsInfo.getName(i).contains("collection2")) {
      assertNotNull(((NamedList<Object>)shardsInfo.getVal(i)).get("error"));
      foundError = true;
      break;
    }
  }
  assertTrue(foundError);
  assertEquals(1, response.getResults().get(0).getFieldValue("id"));
  assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
  unIgnoreException("Dummy exception in BadResponseWriter");
}
 
開發者ID:europeana,項目名稱:search,代碼行數:48,代碼來源:TestTolerantSearch.java

示例15: testGetTopIdsPhaseError

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testGetTopIdsPhaseError() throws SolrServerException {
  BadResponseWriter.failOnGetTopIds = true;
  BadResponseWriter.failOnGetFields = false;
  SolrQuery query = new SolrQuery();
  query.setQuery("subject:batman OR subject:superman");
  query.addField("id");
  query.addField("subject");
  query.set("distrib", "true");
  query.set("shards", shard1 + "," + shard2);
  query.set(ShardParams.SHARDS_INFO, "true");
  query.set("debug", "true");
  query.set("stats", "true");
  query.set("stats.field", "id");
  query.set("mlt", "true");
  query.set("mlt.fl", "title");
  query.set("mlt.count", "1");
  query.set("mlt.mintf", "0");
  query.set("mlt.mindf", "0");
  query.setHighlight(true);
  query.addFacetField("id");
  query.setFacet(true);
  
  ignoreException("Dummy exception in BadResponseWriter");
  try {
    collection1.query(query);
    fail("Should get an exception");
  } catch (Exception e) {
    //expected
  }
  query.set(ShardParams.SHARDS_TOLERANT, "true");
  QueryResponse response = collection1.query(query);
  assertTrue(response.getResponseHeader().getBooleanArg("partialResults"));
  NamedList<Object> shardsInfo = ((NamedList<Object>)response.getResponse().get("shards.info"));
  boolean foundError = false;
  for (int i = 0; i < shardsInfo.size(); i++) {
    if (shardsInfo.getName(i).contains("collection2")) {
      assertNotNull(((NamedList<Object>)shardsInfo.getVal(i)).get("error"));
      foundError = true;
      break;
    }
  }
  assertTrue(foundError);
  
  assertEquals(1, response.getResults().get(0).getFieldValue("id"));
  assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
  unIgnoreException("Dummy exception in BadResponseWriter");
}
 
開發者ID:europeana,項目名稱:search,代碼行數:49,代碼來源:TestTolerantSearch.java


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