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


Java SolrQuery.add方法代碼示例

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


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

示例1: processHighlightOptions

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Append highlighting parameters to {@link org.apache.solr.client.solrj.SolrQuery}
 *
 * @param solrQuery
 * @param query
 */
protected void processHighlightOptions(SolrQuery solrQuery, HighlightQuery query) {
	if (query.hasHighlightOptions()) {
		HighlightOptions highlightOptions = query.getHighlightOptions();
		solrQuery.setHighlight(true);
		if (!highlightOptions.hasFields()) {
			solrQuery.addHighlightField(HighlightOptions.ALL_FIELDS.getName());
		} else {
			for (Field field : highlightOptions.getFields()) {
				solrQuery.addHighlightField(field.getName());
			}
			for (FieldWithHighlightParameters fieldWithHighlightParameters : highlightOptions
					.getFieldsWithHighlightParameters()) {
				addPerFieldHighlightParameters(solrQuery, fieldWithHighlightParameters);
			}
		}
		for (HighlightParameter option : highlightOptions.getHighlightParameters()) {
			addOptionToSolrQuery(solrQuery, option);
		}
		if (highlightOptions.hasQuery()) {
			solrQuery.add(HighlightParams.Q, getQueryString(highlightOptions.getQuery()));
		}
	}
}
 
開發者ID:yiduwangkai,項目名稱:dubbox-solr,代碼行數:30,代碼來源:DefaultQueryParser.java

示例2: solrQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException {
    SolrQuery query = getBaseQuery(CommonParams.Q);

    // set support
    if (this.set != null) {
        String setId = this.set.getSetId();
        MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId);
        setConfig.getHandler().apply(this.set, query);
    }
    // from & until
    if (this.from != null || this.until != null) {
        String fromUntilCondition = buildFromUntilCondition(this.from, this.until);
        query.add(CommonParams.FQ, fromUntilCondition);
    }

    // cursor
    query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START));
    query.set(CommonParams.ROWS, String.valueOf(getPartitionSize()));
    query.set(CommonParams.SORT, "id asc");

    // do the query
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    QueryResponse response = solrClient.query(query);
    Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults());
    return new MCROAISolrResult(response, d -> toHeader(d, setResolver));
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:27,代碼來源:MCROAISolrSearcher.java

示例3: testThatSpellCheckerShouldNotAcceptAnInexistingSpellCheckerDictionaryName

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Test
   public void testThatSpellCheckerShouldNotAcceptAnInexistingSpellCheckerDictionaryName() {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQueryType(Constants.SolrQueryType.spellcheck.toString());
solrQuery.add(Constants.SPELLCHECKER_DICTIONARY_NAME_PARAMETER,
	"notExistingInSolrConfig.xml");
solrQuery.add(Constants.SPELLCHECKER_BUILD_PARAMETER, "true");
solrQuery.add(Constants.SPELLCHECKER_ENABLED_PARAMETER, "true");
solrQuery.setQuery("spell");
try {
    QueryResponse response = solrClient.getServer().query(solrQuery);
    if (response.getStatus() != 0) {
	fail("Status should not be 0 when the name of the dictionnary name is not defined in solrConfig.xml");
    }
    fail("dictionnary name that are not defined in solrConfig.xml should not be accepted");
} catch (Exception e) {
  logger.error(e);
}

   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:21,代碼來源:SpellCheckerIndexerTest.java

示例4: checkSuggesters

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private List<String> checkSuggesters(List<String> suggesters){
	List<String> workingSuggesters = new ArrayList<String>();
	ModifiableSolrParams params = new ModifiableSolrParams()
			.add("key", "suggest")
			.add("stats", "true");
	SolrQuery query = new SolrQuery().setRequestHandler("/admin/mbeans");
	query.add(params);
	SolrResponseBase response = searchableObjectService.search(query);
	NamedList<Object> responseStats = (NamedList<Object>) response.getResponse().findRecursive("solr-mbeans","OTHER","suggest","stats");
	for(Entry<String, Object> suggester : responseStats){
		if(!suggester.getKey().equals("totalSizeInBytes") 
				&& !(((String) suggester.getValue()).contains("sizeInBytes=0"))) {
			workingSuggesters.add(suggester.getKey());
		}
	}

	return workingSuggesters;
}
 
開發者ID:RBGKew,項目名稱:powop,代碼行數:20,代碼來源:ApiController.java

示例5: testQtUpdateFails

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/** SOLR-3161
 * Technically stream.body isn't remote streaming, but there wasn't a better place for this test method. */
@Test(expected = SolrException.class)
public void testQtUpdateFails() throws SolrServerException {
  SolrQuery query = new SolrQuery();
  query.setQuery( "*:*" );//for anything
  query.add("echoHandler","true");
  //sneaky sneaky
  query.add("qt","/update");
  query.add("stream.body","<delete><query>*:*</query></delete>");

  QueryRequest queryRequest = new QueryRequest(query) {
    @Override
    public String getPath() { //don't let superclass substitute qt for the path
      return "/select";
    }
  };
  QueryResponse rsp = queryRequest.process(getSolrServer());
  //!! should *fail* above for security purposes
  String handler = (String) rsp.getHeader().get("handler");
  System.out.println(handler);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:23,代碼來源:TestRemoteStreaming.java

示例6: fromString

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
protected  SolrQuery fromString(String queryString) {
  SolrQuery query =new SolrQuery();
  try {
    List<String> paramsFrom = getParamsFrom(queryString);
    for(String param : paramsFrom){
      List<String> keyValuePair = getKeyValuePair(param);
      String key = keyValuePair.get(0);
      String val = keyValuePair.get(1);
      query.add(key, val);
    }
  } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
  }

  if(forceEchoParamsAll){
    query.remove("echoParams");
    query.add("echoParams", "all");
  }

  return query;
}
 
開發者ID:lafourchette,項目名稱:solrmeter,代碼行數:22,代碼來源:ExternalFileQueryGenerator.java

示例7: prepareQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery prepareQuery(PatientSearch search, boolean highlight) {
	SolrQuery query = search.initQuery();
	query.addFilterQuery("domain:med");
	query.addSort("overall_stop", ORDER.desc);
	query.addField("qualified_name");
	query.addField("va_type");
	query.addField("last_filled");
	query.addField("last_give");
	query.addField(CLASS_FIELD);
	query.set(GroupParams.GROUP, true);
	query.set(GroupParams.GROUP_FIELD, "kind");
	query.add(GroupParams.GROUP_FIELD, "qualified_name");
	
	if (highlight) {
		query.setHighlight(true);
	    query.addHighlightField("administration_comment");
	    query.addHighlightField("prn_reason");
	    query.setHighlightFragsize(72);
	    query.setHighlightSnippets(5);
	}
	
	return query;
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:24,代碼來源:MedsSearchFrame.java

示例8: buildFilterString

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public static void buildFilterString(Filter filter, DocumentFactory factory,DocumentFactory childFactory,SolrQuery query,String searchContext, boolean strict) {
   // query.add(CommonParams.FQ,"_type_:"+factory.getType());
    final String serialize = filter.accept(new SolrFilterSerializerVisitor(factory,childFactory,searchContext, strict));
    if(StringUtils.isNotBlank(serialize)) {
        query.add(CommonParams.FQ, serialize);
    }
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:8,代碼來源:SolrUtils.java

示例9: execute

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public SearchResult<? extends Result> execute(ComponentConfiguration conf, Template intent, Conversation conversation, MultiValueMap<String, String> queryParams) throws IOException {
    // read default page-size from builder-configuration
    int pageSize = conf.getConfiguration(CONFIG_KEY_PAGE_SIZE, 3);
    // if present, a queryParam 'rows' takes precedence.
    pageSize = toInt(queryParams.getFirst("rows"), pageSize);
    long offset = toInt(queryParams.getFirst("start"), 0);


    final QueryRequest solrRequest = buildSolrRequest(conf, intent, conversation, offset, pageSize, queryParams);
    if (solrRequest == null) {
        return new SearchResult<ConversationResult>(pageSize);
    }

    try (SolrClient solrClient = solrServer.getSolrClient(conversationCore)) {
        final NamedList<Object> response = solrClient.request(solrRequest);
        final QueryResponse solrResponse = new QueryResponse(response, solrClient);
        final SolrDocumentList solrResults = solrResponse.getResults();

        final List<ConversationResult> results = new ArrayList<>();
        for (SolrDocument solrDocument : solrResults) {
            //get the answers /TODO hacky, should me refactored (at least ordered by rating)
            SolrQuery query = new SolrQuery("*:*");
            query.add("fq",String.format("conversation_id:\"%s\"",solrDocument.get("conversation_id")));
            query.add("fq", "message_idx:[1 TO *]");
            query.setFields("*","score");
            query.setSort("time", SolrQuery.ORDER.asc);
            //query.setRows(3);

            QueryResponse answers = solrClient.query(query);

            results.add(toHassoResult(conf, solrDocument, answers.getResults(), intent.getType()));
        }
        return new SearchResult<>(solrResults.getNumFound(), solrResults.getStart(), pageSize, results);
    } catch (SolrServerException e) {
        throw new IOException(e);
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:39,代碼來源:ConversationQueryBuilder.java

示例10: apply

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public void apply(MCRSet set, SolrQuery query) {
    String setSpec = set.getSpec();
    String classid = MCRClassificationAndSetMapper.mapSetToClassification(getConfigPrefix(), set.getSetId());
    //Check: Is it possible for setSpec to NOT contain ":" here?
    String value = setSpec.contains(":") ? setSpec.substring(setSpec.indexOf(":")) : ":*";
    String setFilter = classField + ":" + MCRSolrUtils.escapeSearchValue(classid + value);
    query.add(CommonParams.FQ, setFilter);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:9,代碼來源:MCROAIClassificationToSetHandler.java

示例11: query

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
SearchResult query(Document document, SolrUrl solrUrl, SolrClient solrClient) {
    SolrQuery solrQuery = new SolrQuery();

    Map<String, String> valueMap = new HashMap<String, String>();
    String queryString = document.getFieldValue("query");
    valueMap.put("query", queryString);

    StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap);
    for(Map<String, String> map : solrUrl.getQuery()) {
        for(String key: map.keySet()) {
            String value = map.get(key);
            value = strSubstitutor.replace(value);
            solrQuery.add(key, value);
        }
    }
    SearchResult searchResult = new SearchResult();
    try {
        QueryResponse response = solrClient.query(solrQuery);

        searchResult.setResponseTime(response.getQTime());
        searchResult.setNumFound(response.getResults().getNumFound());
        searchResult.setQuery(queryString);

        Iterator<SolrDocument> resultIterator = response.getResults().iterator();
        int position = 0;
        while(resultIterator.hasNext()) {
            SolrDocument solrDocument = resultIterator.next();
            String id = (String) solrDocument.getFieldValue("id");
            Result result = new Result(id,position++);
            searchResult.getResultList().add(result);
        }
    } catch (Exception e) {
        if(failOnError) {
            throw new RuntimeException(e);
        } else {
            searchResult.setValid(false);
            searchResult.setErrorMessage(e.getMessage());
        }

    }
    return searchResult;
}
 
開發者ID:tblsoft,項目名稱:solr-cmd-utils,代碼行數:43,代碼來源:SolrCompareFilter.java

示例12: query

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * 查詢 solr,
 *
 * @param coreName         core 名稱, 如: core1 core0
 * @param solrSearchParams 查詢參數, 與 solr 後台 一 一對應
 * @return
 */
public QueryResponse query(String coreName, SolrSearchParams solrSearchParams) {
    if (StringUtils.isEmpty(coreName) || null == solrSearchParams) {
        logger.error("沒有傳遞有效參數!!");
        return null;
    }
    HttpSolrServer server = new HttpSolrServer(getHttpSolrServerUrl(coreName));
    SolrQuery params = new SolrQuery();

    if (StringUtils.isNoneEmpty(solrSearchParams.getQ())) {
        params.add("q", solrSearchParams.getQ());
    }
    if (StringUtils.isNotEmpty(solrSearchParams.getSort())) {
        params.add("sort", solrSearchParams.getSort());
    }
    if (null != solrSearchParams.getWt()) {
        params.add("wt", solrSearchParams.getWt().getType());
    }

    // 分頁查詢
    if (null == solrSearchParams.getPageNum() || solrSearchParams.getPageNum() <= 0) {
        solrSearchParams.setPageNum(1);
    }
    if (null == solrSearchParams.getPageSize() || solrSearchParams.getPageSize() <= 0) {
        solrSearchParams.setPageSize(10);
    }
    params.add("start", String.valueOf(((solrSearchParams.getPageNum() - 1) * solrSearchParams.getPageSize())));
    params.add("rows", solrSearchParams.getPageSize().toString());

    QueryResponse rsp = null;
    try {
        rsp = server.query(params);
    } catch (SolrServerException e) {
        logger.error("solr query 異常, e:{}", e.getMessage());
    }

    return rsp;
}
 
開發者ID:blogshun,項目名稱:ants-project,代碼行數:45,代碼來源:SolrClientService.java

示例13: buildIndex

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public boolean buildIndex(
    SpellCheckerDictionaryNames spellCheckerDictionaryName) {
if (!SpellCheckerConfig.isEnabled()) {
    return false;
}

SolrQuery solrQuery = new SolrQuery();
solrQuery.setQueryType(Constants.SolrQueryType.spellcheck.toString());
solrQuery.add(Constants.SPELLCHECKER_DICTIONARY_NAME_PARAMETER,
	spellCheckerDictionaryName.toString());
solrQuery.add(Constants.SPELLCHECKER_BUILD_PARAMETER, "true");
solrQuery.add(Constants.SPELLCHECKER_ENABLED_PARAMETER, "true");
solrQuery.setQuery("spell");
try {
    QueryResponse response = solrClient.getServer().query(solrQuery);
    if (response.getStatus() != 0) {
	 logger.error("Indexing dictionary "
		    + spellCheckerDictionaryName.name()+" fails");
	return false;
    }
    logger.info("Successfully indexing dictionary "
	    + spellCheckerDictionaryName.name());
    return true;

} catch (Exception e) {
    logger.error("An error has occured when indexing spellchecker "
	    + spellCheckerDictionaryName + " : " + e);
    return false;
}

   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:32,代碼來源:SpellCheckerIndexer.java

示例14: testNoUrlAccess

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/** Do a select query with the stream.url. Solr should fail */
@Test
public void testNoUrlAccess() throws Exception {
  SolrQuery query = new SolrQuery();
  query.setQuery( "*:*" );//for anything
  query.add("stream.url",makeDeleteAllUrl());
  try {
    getSolrServer().query(query);
    fail();
  } catch (SolrException se) {
    assertSame(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode(se.code()));
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:14,代碼來源:TestRemoteStreaming.java

示例15: addRandomExtraParameters

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Adds a random line of the extra parameters extractor
 * @param query
 */
private void addRandomExtraParameters(SolrQuery query) {
  String randomExtraParam = extraParameterExtractor.getRandomQuery();
  if(randomExtraParam == null || "".equals(randomExtraParam.trim())) {
    return;
  }
  for(String param:randomExtraParam.split("&")) {//TODO parametrize
    int equalSignIndex = param.indexOf("=");
    if(equalSignIndex > 0) {
      query.add(param.substring(0, equalSignIndex).trim(), param.substring(equalSignIndex + 1).trim());
    }
  }
}
 
開發者ID:lafourchette,項目名稱:solrmeter,代碼行數:17,代碼來源:ComplexQueryGenerator.java


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