Java Code Examples for org.apache.solr.common.params.ModifiableSolrParams#remove()
The following examples show how to use
org.apache.solr.common.params.ModifiableSolrParams#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TermsComponentTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testTermsSortIndexDistribution() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(TermsParams.TERMS_SORT, TermsParams.TERMS_SORT_INDEX); params.set(TermsParams.TERMS_LIMIT, "any-number"); assertEquals(params.toString(), createShardQueryParamsString(params)); params.set(TermsParams.TERMS_MINCOUNT, "0"); assertEquals(params.toString(), createShardQueryParamsString(params)); params.set(TermsParams.TERMS_MINCOUNT, "1"); assertEquals(params.toString(), createShardQueryParamsString(params)); // include all (also lower mincount) since 2 shards can have one each params.set(TermsParams.TERMS_MINCOUNT, "2"); assertNotEquals(params.toString(), createShardQueryParamsString(params)); // "unlimited" since 2 shards can have 30 each, and term then should not be included params.remove(TermsParams.TERMS_MINCOUNT); params.set(TermsParams.TERMS_MAXCOUNT, "32"); assertNotEquals(params.toString(), createShardQueryParamsString(params)); }
Example 2
Source File: TestRandomFaceting.java From lucene-solr with Apache License 2.0 | 6 votes |
private String getIndexSortedAllFacetValues(ModifiableSolrParams in, List<String> methods) throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(in); params.set("facet.sort", "index"); String goodOldMethod = methods.get(random().nextInt( methods.size())); params.set("facet.method", goodOldMethod); params.set("facet.exists", "false"); if (random().nextBoolean()) { params.remove("facet.exists"); } params.set("facet.limit",-1); params.set("facet.offset",0); final String query; SolrQueryRequest req = null; try { req = req(params); query = h.query(req); } finally { req.close(); } return query; }
Example 3
Source File: DistributedFacetExistsSmallTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@ShardsFixed(num=4) public void test() throws Exception{ checkBasicRequest(); checkWithMinCountEqOne(); checkWithSortCount(); checkWithMethodSetPerField(); { // empty enum for checking npe final ModifiableSolrParams params = buildParams(); params.remove("facet.exists"); QueryResponse rsp = query(params); } checkRandomParams(); checkInvalidMincount(); }
Example 4
Source File: HttpSolrClient.java From lucene-solr with Apache License 2.0 | 6 votes |
protected ModifiableSolrParams calculateQueryParams(Set<String> queryParamNames, ModifiableSolrParams wparams) { ModifiableSolrParams queryModParams = new ModifiableSolrParams(); if (queryParamNames != null) { for (String param : queryParamNames) { String[] value = wparams.getParams(param) ; if (value != null) { for (String v : value) { queryModParams.add(param, v); } wparams.remove(param); } } } return queryModParams; }
Example 5
Source File: JSONTupleStream.java From lucene-solr with Apache License 2.0 | 6 votes |
public static JSONTupleStream create(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if(p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); } QueryRequest query = new QueryRequest( requestParams ); query.setPath(p); query.setResponseParser(new InputStreamResponseParser("json")); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream)genericResponse.get("stream"); InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); return new JSONTupleStream(reader); }
Example 6
Source File: RewriteFacetParametersComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void prepare(ResponseBuilder rb) throws IOException { SolrQueryRequest req = rb.req; SolrParams params = req.getParams(); ModifiableSolrParams fixed = new ModifiableSolrParams(); ModifiableSolrParams allParamsWithFix = new ModifiableSolrParams(params); fixFilterQueries(fixed, params, rb); fixFacetParams(fixed, params, rb); fixRows(fixed, params, rb); Set<String> fixedParameterNames = fixed.getParameterNames(); for (String fixedParam : fixedParameterNames) { allParamsWithFix.set(fixedParam, fixed.getParams(fixedParam)); } if (allParamsWithFix.get(CommonParams.SORT) != null) { allParamsWithFix.remove(CommonParams.RQ); } req.setParams(allParamsWithFix); }
Example 7
Source File: KnnStream.java From lucene-solr with Apache License 2.0 | 5 votes |
public void open() throws IOException { cloudSolrClient = cache.getCloudSolrClient(zkHost); ModifiableSolrParams params = getParams(this.props); StringBuilder builder = new StringBuilder(); for(String key : mltParams) { if(params.get(key) != null) { builder.append(' ').append(key).append('=').append(params.get(key)); params.remove(key); } } String k = params.get("k"); if(k != null) { params.add(ROWS, k); params.remove(k); } params.add(Q, "{!mlt"+builder.toString()+"}"+id); QueryRequest request = new QueryRequest(params); try { QueryResponse response = request.process(cloudSolrClient, collection); SolrDocumentList docs = response.getResults(); documentIterator = docs.iterator(); } catch (Exception e) { throw new IOException(e); } }
Example 8
Source File: TermsComponentTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testTermsWithJSON() throws Exception { ModifiableSolrParams params = params( "qt", "/terms", "terms", "true", "terms.fl", "standardfilt", "terms.lower", "a", "terms.sort", "index", "wt", "json" ); assertJQ(req(params), "/terms/standardfilt/[0]==a", "/terms/standardfilt/[1]==1"); // enable terms.ttf params.set("terms.ttf", "true"); assertJQ(req(params), "/terms/standardfilt/[0]==a", "/terms/standardfilt/[1]/df==1", "/terms/standardfilt/[1]/ttf==1"); // test the response with terms.list and terms.ttf=false params.set("terms.list", "spider,snake,shark"); params.remove("terms.ttf"); assertJQ(req(params), "/terms/standardfilt/[0]==shark", "/terms/standardfilt/[1]==2", "/terms/standardfilt/[2]==snake", "/terms/standardfilt/[3]==3", "/terms/standardfilt/[4]==spider", "/terms/standardfilt/[5]==1" ); // with terms.list and terms.ttf=true params.set("terms.ttf", "true"); assertJQ(req(params), "/terms/standardfilt/[0]==shark", "/terms/standardfilt/[1]/df==2", "/terms/standardfilt/[1]/ttf==2", "/terms/standardfilt/[2]==snake", "/terms/standardfilt/[3]/df==3", "/terms/standardfilt/[3]/ttf==3", "/terms/standardfilt/[4]==spider", "/terms/standardfilt/[5]/df==1", "/terms/standardfilt/[5]/ttf==1" ); }
Example 9
Source File: DistributedFacetExistsSmallTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void checkInvalidMincount() throws SolrServerException, IOException { final ModifiableSolrParams params = buildParams(); if (random().nextBoolean()) { params.remove("facet.exists"); params.set("f."+FLD+".facet.exists","true"); } if (random().nextBoolean()) { params.set("facet.mincount", ""+(2+random().nextInt(100)) ); } else { params.set("f."+FLD+".facet.mincount", ""+(2+random().nextInt(100)) ); } SolrException e = expectThrows(SolrException.class, () -> { if (random().nextBoolean()) { setDistributedParams(params); queryServer(params); } else { params.set("distrib", "false"); controlClient.query(params); } }); assertEquals(e.code(), ErrorCode.BAD_REQUEST.code); assertTrue(e.getMessage().contains("facet.exists")); assertTrue(e.getMessage().contains("facet.mincount")); assertTrue(e.getMessage().contains(FLD)); }
Example 10
Source File: SolrTestCaseHS.java From lucene-solr with Apache License 2.0 | 5 votes |
public static String getQueryResponse(String wt, SolrParams params) throws Exception { ModifiableSolrParams p = new ModifiableSolrParams(params); p.set("wt", wt); String path = p.get("qt"); p.remove("qt"); p.set("indent","true"); DirectSolrConnection connection = new DirectSolrConnection(h.getCore()); String raw = connection.request(path, p, null); return raw; }
Example 11
Source File: SolrStream.java From lucene-solr with Apache License 2.0 | 5 votes |
public TupleStreamParser constructParser(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if (p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); //performance optimization - remove extra whitespace by default when streaming modifiableSolrParams.set("indent", modifiableSolrParams.get("indent", "off")); } String wt = requestParams.get(CommonParams.WT, "json"); QueryRequest query = new QueryRequest(requestParams); query.setPath(p); query.setResponseParser(new InputStreamResponseParser(wt)); query.setMethod(SolrRequest.METHOD.POST); if(user != null && password != null) { query.setBasicAuthCredentials(user, password); } NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream) genericResponse.get("stream"); this.closeableHttpResponse = (CloseableHttpResponse)genericResponse.get("closeableResponse"); if (CommonParams.JAVABIN.equals(wt)) { return new JavabinTupleStreamParser(stream, true); } else { InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); return new JSONTupleStream(reader); } }
Example 12
Source File: RandomStream.java From lucene-solr with Apache License 2.0 | 5 votes |
public void open() throws IOException { if(cache != null) { cloudSolrClient = cache.getCloudSolrClient(zkHost); } else { final List<String> hosts = new ArrayList<>(); hosts.add(zkHost); cloudSolrClient = new CloudSolrClient.Builder(hosts, Optional.empty()).withSocketTimeout(30000).withConnectionTimeout(15000).build(); } ModifiableSolrParams params = getParams(this.props); params.remove(SORT); //Override any sort. Random rand = new Random(); int seed = rand.nextInt(); String sortField = "random_"+seed; params.add(SORT, sortField+" asc"); QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST); try { QueryResponse response = request.process(cloudSolrClient, collection); SolrDocumentList docs = response.getResults(); documentIterator = docs.iterator(); } catch (Exception e) { throw new IOException(e); } }
Example 13
Source File: DistributedTermsComponentTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected QueryResponse query(boolean setDistribParams, SolrParams p) throws Exception { QueryResponse queryResponse = super.query(setDistribParams, p); final ModifiableSolrParams params = new ModifiableSolrParams(p); // TODO: look into why passing true causes fails params.set("distrib", "false"); for (ResponseParser responseParser : getResponseParsers()) { final NamedList<Object> controlRsp = queryClient(controlClient, params, responseParser); params.remove("distrib"); if (setDistribParams) { setDistributedParams(params); } // query a random server int which = r.nextInt(clients.size()); SolrClient client = clients.get(which); NamedList<Object> rsp = queryClient(client, params, responseParser); // flags needs to be called here since only terms response is passed to compare // other way is to pass whole response to compare assertNull(compare(rsp.findRecursive("terms"), controlRsp.findRecursive("terms"), flags(handle, "terms"), handle)); } return queryResponse; }
Example 14
Source File: CollectionAdminRequest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public SolrParams getParams() { ModifiableSolrParams params = new ModifiableSolrParams(super.getParams()); // AsyncCollectionSpecificAdminRequest uses 'name' rather than 'collection' // TODO - deal with this inconsistency params.remove(CoreAdminParams.NAME); params.set(ZkStateReader.COLLECTION_PROP, this.collection); if (this.replica != null) params.set(ZkStateReader.REPLICA_PROP, this.replica); if (this.shard != null) params.set(ZkStateReader.SHARD_ID_PROP, this.shard); if (onlyIfDown != null) { params.set("onlyIfDown", onlyIfDown); } if (deleteDataDir != null) { params.set(CoreAdminParams.DELETE_DATA_DIR, deleteDataDir); } if (deleteInstanceDir != null) { params.set(CoreAdminParams.DELETE_INSTANCE_DIR, deleteInstanceDir); } if (deleteIndexDir != null) { params.set(CoreAdminParams.DELETE_INDEX, deleteIndexDir); } if (count != null) { params.set(COUNT_PROP, count); } return params; }
Example 15
Source File: MCRSolrProxyServlet.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * redirects to query handler by using value of 'qt' parameter */ private static void redirectToQueryHandler(HttpServletRequest request, HttpServletResponse resp) throws IOException { ModifiableSolrParams solrQueryParameter = getSolrQueryParameter(request); String queryHandlerPath = solrQueryParameter.get(QUERY_HANDLER_PAR_NAME, SOLR_QUERY_PATH); solrQueryParameter.remove(QUERY_HANDLER_PAR_NAME); Map<String, String[]> parameters = toMultiMap(solrQueryParameter); doRedirectToQueryHandler(resp, queryHandlerPath, parameters); }
Example 16
Source File: BaseDistributedSearchTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Returns the QueryResponse from {@link #queryServer} */ protected QueryResponse query(boolean setDistribParams, SolrParams p) throws Exception { final ModifiableSolrParams params = new ModifiableSolrParams(p); // TODO: look into why passing true causes fails params.set("distrib", "false"); final QueryResponse controlRsp = controlClient.query(params); validateControlData(controlRsp); if (shardCount == 0) {//mostly for temp debugging return controlRsp; } params.remove("distrib"); if (setDistribParams) setDistributedParams(params); QueryResponse rsp = queryServer(params); compareResponses(rsp, controlRsp); if (stress > 0) { log.info("starting stress..."); Thread[] threads = new Thread[nThreads]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread() { @Override public void run() { for (int j = 0; j < stress; j++) { int which = r.nextInt(clients.size()); SolrClient client = clients.get(which); try { QueryResponse rsp = client.query(new ModifiableSolrParams(params)); if (verifyStress) { compareResponses(rsp, controlRsp); } } catch (SolrServerException | IOException e) { throw new RuntimeException(e); } } } }; threads[i].start(); } for (Thread thread : threads) { thread.join(); } } return rsp; }
Example 17
Source File: AbstractAlfrescoDistributedIT.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
/** * Returns the QueryResponse from {@link #queryRandomShard} */ protected QueryResponse query(SolrClient solrClient, boolean setDistribParams, SolrParams p) throws Exception { Random r = SOLR_RANDOM_SUPPLIER.getRandomGenerator(); final ModifiableSolrParams params = new ModifiableSolrParams(p); // TODO: look into why passing true causes fails params.set("distrib", "false"); final QueryResponse controlRsp = solrClient.query(params); SOLR_RESPONSE_COMPARATOR.validateResponse(controlRsp); params.remove("distrib"); if (setDistribParams) setDistributedParams(params); QueryResponse rsp = queryRandomShard(params); SOLR_RESPONSE_COMPARATOR.compareResponses(rsp, controlRsp); if (stress > 0) { log.info("starting stress..."); Thread[] threads = new Thread[nThreads]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(() -> { for (int j = 0; j < stress; j++) { int which = r.nextInt(clientShards.size()); SolrClient client = clientShards.get(which); try { QueryResponse rsp1 = client.query(new ModifiableSolrParams(params)); if (verifyStress) { SOLR_RESPONSE_COMPARATOR.compareResponses(rsp1, controlRsp); } } catch (SolrServerException | IOException e) { throw new RuntimeException(e); } } }); threads[i].start(); } for (Thread thread : threads) { thread.join(); } } return rsp; }
Example 18
Source File: DistributedFacetExistsSmallTest.java From lucene-solr with Apache License 2.0 | 4 votes |
private void checkWithMethodSetPerField() throws Exception { final ModifiableSolrParams params = buildParams("f." + FLD + ".facet.exists", "true"); params.remove("facet.exists"); QueryResponse rsp = query(params); assertResponse(rsp); }
Example 19
Source File: AlfrescoCoreAdminHandlerIT.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void targetCoreNameCanBeSpecifiedInSeveralWays() { String coreName = "ThisIsTheCoreName"; ModifiableSolrParams params = new ModifiableSolrParams(); assertNull(alfrescoCoreAdminHandler.coreName(params)); params.set(CoreAdminParams.CORE, coreName); assertEquals(coreName, alfrescoCoreAdminHandler.coreName(params)); params.remove(CoreAdminParams.CORE); assertNull(alfrescoCoreAdminHandler.coreName(params)); params.set("coreName", coreName); assertEquals(coreName, alfrescoCoreAdminHandler.coreName(params)); assertEquals(coreName, alfrescoCoreAdminHandler.coreName(params)); }
Example 20
Source File: TaggedQueryHighlighter.java From solr-redis with Apache License 2.0 | 4 votes |
@Override public NamedList<Object> doHighlighting(final DocList docs, final Query query, final SolrQueryRequest req, final String[] defaultFields) throws IOException { final Collection<TaggedQuery> taggedQueries = new ArrayList<>(); final List<Query> otherQueries = new ArrayList<>(); try { final List<Query> extractedQueries = new ArrayList<>(); QueryExtractor.extractQuery(query, extractedQueries); for (final Query extractedQuery : extractedQueries) { if (extractedQuery instanceof TaggedQuery) { taggedQueries.add((TaggedQuery) extractedQuery); } } } catch (final UnsupportedOperationException ex) { logger.warn("Cannot highlight query.", ex); } if (taggedQueries.isEmpty()) { logger.debug("Running default highlighter. No tagged queries are used in main query."); return super.doHighlighting(docs, query, req, defaultFields); } else { logger.debug("Collecting highlights for Running default highlighter. No tagged queries are used in main query."); final Map<String, SimpleOrderedMap> results = new HashMap<>(); results.put(MAIN_HIGHLIGHT, (SimpleOrderedMap) super.doHighlighting(docs, query, req, defaultFields)); List<String> fieldsNameList = new ArrayList<>(); if (req.getParams().getParams(HighlightParams.FIELDS).length > 0) { fieldsNameList = Arrays.asList(SolrPluginUtils.split(req.getParams().getParams(HighlightParams.FIELDS)[0])); } final Set<String> originalFields = new HashSet<>(fieldsNameList); for (final TaggedQuery taggedQuery : taggedQueries) { final Set<String> fields = new HashSet<>(); QueryExtractor.extractFields(taggedQuery, fields); final ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); //Continue if original field set doesn't contain subfields or field tag if (!containsField(taggedQuery.getTag(), originalFields, fields)) { continue; } params.remove(HighlightParams.FIELDS); params.add(HighlightParams.FIELDS, fields.toArray(new String[0])); req.setParams(params); final SimpleOrderedMap partialResult = (SimpleOrderedMap) super.doHighlighting(docs, taggedQuery.getWrappedQuery(), req, defaultFields); results.put(taggedQuery.getTag(), partialResult); } return mergeResults(results); } }