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


Java SolrQuery.setFilterQueries方法代碼示例

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


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

示例1: getDatasetCount

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public long getDatasetCount() throws SearchException{
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    solrQuery.setFilterQueries(SearchFields.TYPE+":datasets",
            SearchFields.PUBLICATION_STATUS+":Published");
    solrQuery.setStart(0);
    solrQuery.setRows(0);
    QueryResponse queryResponse = null;
    try {
        queryResponse = solrServer.query(solrQuery);
        return queryResponse.getResults().getNumFound();
    } catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {  
        logger.log(Level.INFO, null, ex);
        throw new SearchException("Internal Dataverse Search Engine Error", ex);
    }
}
 
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:17,代碼來源:SolrSearchServiceBean.java

示例2: getDataverseCount

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public long getDataverseCount() throws SearchException{
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    solrQuery.setFilterQueries(SearchFields.TYPE+":dataverses",
            SearchFields.PUBLICATION_STATUS+":Published");
    solrQuery.setStart(0);
    solrQuery.setRows(0);
    QueryResponse queryResponse = null;
    try {
        queryResponse = solrServer.query(solrQuery);
        return queryResponse.getResults().getNumFound();
    } catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {  
        logger.log(Level.INFO, null, ex);
        throw new SearchException("Internal Dataverse Search Engine Error", ex);
    }
}
 
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:17,代碼來源:SolrSearchServiceBean.java

示例3: getQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getQuery() {
    SolrQuery solrQuery = new SolrQuery();
    MCRConfiguration config = MCRConfiguration.instance();
    // query
    String idQuery = getResult().stream()
        .map(getIdentifier())
        .map(MCRSolrUtils::escapeSearchValue)
        .collect(Collectors.joining(" OR ", "id:(", ")"));
    solrQuery.setQuery(idQuery);
    solrQuery.setFilterQueries(query);
    solrQuery.setFields("id");
    solrQuery.setRows(getResult().size());
    // request handler
    solrQuery.setRequestHandler(config.getString(getConfigPrefix() + "Search.RequestHandler", "/select"));
    return solrQuery;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:17,代碼來源:MCROAIQuerySetResolver.java

示例4: loadSpacesFromSolr

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void loadSpacesFromSolr() throws SolrServerException, IOException {
    this.logger.debug("Loading spaces from Config Solr.");
    Set<String> activeTokens = new HashSet<>();

    SolrQuery solrQuery = new SolrQuery("*:*");
    solrQuery.setFilterQueries(ConfigFieldConstants.FIELD_TYPE + ":" + CONFIG_TYPE);
    solrQuery.setRows(Integer.MAX_VALUE);

    QueryResponse queryResponse = this.solrClient.query(solrQuery);
    for (SolrDocument eachSolrDocument : queryResponse.getResults()) {
        String spaceName = SolrDocumentHelper.getString(eachSolrDocument, FIELD_NAME);
        String tokenString = SolrDocumentHelper.getString(eachSolrDocument, FIELD_CONTENT);
        String[] tokens = tokenString.split("\\s*,\\s*");

        for (String eachToken : tokens) {
            this.spaces.put(eachToken, spaceName);
            activeTokens.add(eachToken);
        }
    }

    this.spaces.keySet().retainAll(activeTokens);
}
 
開發者ID:Indoqa,項目名稱:logspace,代碼行數:23,代碼來源:SolrSpacesService.java

示例5: getAgentDescription

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public AgentDescription getAgentDescription(String globalAgentId) {
    try {
        SolrQuery solrQuery = new SolrQuery(FIELD_GLOBAL_AGENT_ID + ":\"" + globalAgentId + "\"");
        solrQuery.setFilterQueries(FIELD_TYPE + ":" + CONFIG_TYPE);

        QueryResponse queryResponse = this.solrClient.query(solrQuery);
        for (SolrDocument eachSolrDocument : queryResponse.getResults()) {
            String content = SolrDocumentHelper.getString(eachSolrDocument, FIELD_CONTENT);
            AgentControllerCapabilities controllerCapabilities = AgentControllerCapabilitiesJsonDeserializer.fromJson(content);

            AgentCapabilities agentCapabilities = this.getAgentCapabilities(controllerCapabilities, globalAgentId);
            if (agentCapabilities != null) {
                return this.createAgentDescription(controllerCapabilities, agentCapabilities);
            }
        }

        return null;
    } catch (SolrServerException | IOException e) {
        throw new DataRetrievalException("Could not retrieve capabilities.", e);
    }
}
 
開發者ID:Indoqa,項目名稱:logspace,代碼行數:23,代碼來源:SolrCapabilitiesService.java

示例6: checkIndex

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Integrity check.
 */
public void checkIndex()
{
   try
   {
      SolrQuery query = new SolrQuery("*:*");
      query.setFilterQueries("*");
      query.setStart(0);
      Iterator<SolrDocument> it = solrDao.scroll(query);
      while (it.hasNext())
      {
         SolrDocument doc = it.next();
         Long pid = (Long) doc.get("id");
         Product product = productService.systemGetProduct(pid);
         if (product == null)
         {
            Long id = (Long) doc.getFieldValue("id");
            LOGGER.warn("Removing unknown product " + id + " from solr index");
            try
            {
               solrDao.remove(id);
               // decrease the offset, because a product has been removed
               query.setStart(query.getStart() - 1);
            }
            catch (IOException e)
            {
               LOGGER.error("Cannot remove Solr entry " + id, e);
            }
         }
      }
   }
   catch (IOException|SolrServerException ex)
   {
      LOGGER.error("Cannot check the index", ex);
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:39,代碼來源:SearchService.java

示例7: testCompareWithNonDistributedRequest

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public void testCompareWithNonDistributedRequest() throws SolrServerException {
  SolrQuery query = new SolrQuery();
  query.setQuery("id:1");
  query.setFilterQueries("id:[0 TO 10]");
  query.set("debug",  "true");
  query.set("distrib", "true");
  query.setFields("id", "text");
  query.set("shards", shard1 + "," + shard2);
  QueryResponse distribResponse = collection1.query(query);
  
  // same query but not distributed
  query.set("distrib", "false");
  query.remove("shards");
  QueryResponse nonDistribResponse = collection1.query(query);
  
  assertNotNull(distribResponse.getDebugMap().get("track"));
  assertNull(nonDistribResponse.getDebugMap().get("track"));
  assertEquals(distribResponse.getDebugMap().size() - 1, nonDistribResponse.getDebugMap().size());
  
  assertSectionEquals(distribResponse, nonDistribResponse, "explain");
  assertSectionEquals(distribResponse, nonDistribResponse, "rawquerystring");
  assertSectionEquals(distribResponse, nonDistribResponse, "querystring");
  assertSectionEquals(distribResponse, nonDistribResponse, "parsedquery");
  assertSectionEquals(distribResponse, nonDistribResponse, "parsedquery_toString");
  assertSectionEquals(distribResponse, nonDistribResponse, "QParser");
  assertSectionEquals(distribResponse, nonDistribResponse, "filter_qieries");
  assertSectionEquals(distribResponse, nonDistribResponse, "parsed_filter_qieries");
  
  // timing should have the same sections:
  assertSameKeys((NamedList<?>)nonDistribResponse.getDebugMap().get("timing"), (NamedList<?>)distribResponse.getDebugMap().get("timing"));
}
 
開發者ID:europeana,項目名稱:search,代碼行數:32,代碼來源:DistributedDebugComponentTest.java

示例8: createQueryException

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private QueryException createQueryException() {
	QueryException queryException = new QueryException();
	SolrQuery query = new SolrQuery();
	query.setQuery("test");
	query.setFilterQueries("field=value");
	query.addFacetQuery("filterQuery=value");
	queryException.setQuery(query);
	return queryException;
}
 
開發者ID:lafourchette,項目名稱:solrmeter,代碼行數:10,代碼來源:QueryLogStatisticTestCase.java

示例9: appendFilterQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Set filter filter queries for {@link org.apache.solr.client.solrj.SolrQuery}
 *
 * @param solrQuery
 * @param filterQueries
 */
protected void appendFilterQuery(SolrQuery solrQuery, List<FilterQuery> filterQueries) {
	if (CollectionUtils.isEmpty(filterQueries)) {
		return;
	}
	List<String> filterQueryStrings = getFilterQueryStrings(filterQueries);

	if (!filterQueryStrings.isEmpty()) {
		solrQuery.setFilterQueries(convertStringListToArray(filterQueryStrings));
	}
}
 
開發者ID:yiduwangkai,項目名稱:dubbox-solr,代碼行數:17,代碼來源:DefaultQueryParser.java

示例10: exec

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void exec(RenderTask task) throws Exception {
	if (this.solr == null) {
		this.solr = task.getResource(SolrServer.class);
	}

	// create/edit query
    String newQry = evalQueryString(task, getQueryString());
    SolrQuery solrParams = new SolrQuery(newQry);
    if (this.fq != null) {
    	solrParams.setFilterQueries(evalQueryString(task, this.fq));
    }
    
    // add sort+limit criteria (if found)
    String sortCol = task.getParamStr("sort.col"); 
    String sortDir = task.getParamStr("sort.dir");
    int limit = task.getParamInt("row.count");
    if (sortCol != null && sortDir != null) {
    	solrParams.addSort(sortCol, ORDER.valueOf(sortDir.toLowerCase()));
    }
    if (limit > 0) {
    	solrParams.setRows(limit);
    }
    
    // include debug info
    
    // execute SOLR query and include debug info
    modifySolrQuery(solrParams, task);
    task.addAction(new DebugInfo("solr.query", solrParams.toString()));
    QueryResponse resp = solr.query(solrParams);
    mapResults(task, resp);
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:33,代碼來源:Query.java

示例11: loadAgentDescription

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private AgentDescription loadAgentDescription(String globalAgentId) throws SolrServerException, IOException {
    SolrQuery query = new SolrQuery(ALL_DOCS_QUERY);
    query.setRows(0);

    query.setFilterQueries(FIELD_GLOBAL_AGENT_ID + ":\"" + globalAgentId + "\"");

    query.setFacetMinCount(1);
    query.addFacetField(FIELD_SPACE, FIELD_SYSTEM, FIELD_PROPERTY_ID);

    QueryResponse response = this.solrClient.query(query);

    AgentDescription result = new AgentDescription();
    result.setGlobalId(globalAgentId);
    result.setName(IdHelper.getAgentId(globalAgentId));
    result.setSpace(this.getFirstFacetValue(response, FIELD_SPACE));
    result.setSystem(this.getFirstFacetValue(response, FIELD_SYSTEM));

    List<PropertyDescription> propertyDescriptions = new ArrayList<>();
    FacetField facetField = response.getFacetField(FIELD_PROPERTY_ID);
    for (Count eachValue : facetField.getValues()) {
        propertyDescriptions.add(createPropertyDescription(eachValue.getName()));
    }
    Collections.sort(propertyDescriptions);
    result.setPropertyDescriptions(propertyDescriptions);

    return result;
}
 
開發者ID:Indoqa,項目名稱:logspace,代碼行數:28,代碼來源:SolrAgentService.java

示例12: 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;
}
 
開發者ID:nla,項目名稱:bamboo,代碼行數:11,代碼來源:RuleChangeUpdateManager.java

示例13: addQueryFacetParameters

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
protected final void addQueryFacetParameters(final SolrQuery query, QueryFacetsSelection queryFacetsSelections) {
    final String queryString = queryFacetsSelections.getQuery();
    if (queryString == null) {
        query.setQuery(SOLR_SEARCH_ALL);
    } else {
        // escape query content and wrap in quotes to make literal query
        query.setQuery(queryString);
    }
    final Map<String, FacetSelection> selections = queryFacetsSelections.getSelection();
    if (selections != null) {
        final List<String> encodedQueries = new ArrayList(selections.size()); // assuming every facet has one selection, most common scenario
        for (Map.Entry<String, FacetSelection> selectionEntry : selections.entrySet()) {
            final String facetName = selectionEntry.getKey();
            final FacetSelection selection = selectionEntry.getValue();
            if (selection != null) {
                switch (selection.getSelectionType()) {
                    case NOT_EMPTY:
                        //TODO: test
                        encodedQueries.add(String.format("%s:[* TO *]", facetName));
                        break;
                    case AND:
                        for (String value : selection.getValues()) {
                            if (selection.getQualifier(value) == FacetSelectionValueQualifier.NOT) {
                                encodedQueries.add(createNegativeFilterQuery(facetName, value));
                            } else {
                                encodedQueries.add(createFilterQuery(facetName, value));
                            }
                        }
                        break;
                    case OR:
                        // notice that OR ignores qualifiers, so it does not support e.g. (A OR (NOT B))
                        encodedQueries.add(createFacetOrQuery(facetName, selection.getValues()));
                        // replace facet field with version prefixed with exclude statement 
                        // (see <http://wiki.apache.org/solr/SimpleFacetParameters#Multi-Select_Faceting_and_LocalParams>)
                        query.removeFacetField(facetName);
                        query.addFacetField(String.format("{!ex=%1$s}%1$s", facetName));
                        break;
                    default:
                        throw new UnsupportedOperationException("Unsupported selection type: " + selection.getSelectionType());
                }
            }
        }
        query.setFilterQueries(encodedQueries.toArray(new String[encodedQueries.size()]));
    }
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:46,代碼來源:AbstractSolrQueryFactory.java

示例14: getSolrQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
     * 分頁查詢,包含查詢,分頁,高亮及獲取高亮處摘要等內容;不同於數據庫的查詢分頁,
     * solr的查詢返回值中有文檔總數,所以無需再次查詢總條數。
     *
     * @param solrServer, page 自定義的翻頁對象,包含查詢信息及當前頁數據列表。
     * @return List<FileModel>
     */
    public PageModel getSolrQuery(SolrServer solrServer, PageModel pageModel, Map filterQuery) {

        String type = (String) filterQuery.get("type");
        if(type == null || "".equals(type)) {
            type = "*";
        }

        String role = (String) filterQuery.get("role");
        if(role == null || "".equals(role)) {
            role = "anonymous";
        }

        SolrQuery query = new SolrQuery();

        // 獲取查詢參數
        String para = pageModel.getParameter();

//        System.out.println("para: " + para + ";  type: " + type);

        //TODO
        // 過濾文件與權限類型
//        query.setQuery("content_text:" + para);
        query.setQuery(para);
        query.setFilterQueries(
                "(" + getTypeFilter(type) + ")"
                        + "AND (" + getRoleFilter(role) + ")"
        );
        query.set("defType","edismax");
        query.set("qf","file_name^10 content_text^1");
//        query.addSort("upload_time", SolrQuery.ORDER.desc);
        query.setStart((int)pageModel.getStart());
        query.setRows(pageModel.getSize());

//        System.out.println(page.getStart() + "  " + page.getSize());

        //設置高亮
        query.setHighlight(true);// 開啟高亮組件
        query.addHighlightField("file_name");// 高亮字段
        query.addHighlightField("content_text");// 高亮字段
        query.setHighlightSimplePre("<hlt>");//標記,高亮關鍵字前綴
        query.setHighlightSimplePost("</hlt>");//後綴
        query.setHighlight(true).setHighlightSnippets(2); //獲取高亮分片數,一般搜索詞可能分布在文章中的不同位置,其所在一定長度的語句即為一個片段,默認為1,但根據業務需要有時候需要多取出幾個分片。 - 此處設置決定下文中titleList, contentList中元素的個數
        query.setHighlightFragsize(150);//每個分片的最大長度,默認為100。適當設置此值,如果太小,高亮的標題可能會顯不全;設置太大,摘要可能會太長。

        return getPageModel(solrServer, pageModel, query);
    }
 
開發者ID:hackty,項目名稱:hadooptools,代碼行數:54,代碼來源:QueryFileServiceSolrMRImpl.java

示例15: 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


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