Java Code Examples for org.apache.solr.common.params.ModifiableSolrParams

The following examples show how to use org.apache.solr.common.params.ModifiableSolrParams. These examples are extracted from open source projects. 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 Project: lucene-solr   Source File: OverseerNodePrioritizer.java    License: Apache License 2.0 6 votes vote down vote up
private void invokeOverseerOp(String electionNode, String op) {
  ModifiableSolrParams params = new ModifiableSolrParams();
  ShardHandler shardHandler = ((HttpShardHandlerFactory)shardHandlerFactory).getShardHandler(httpClient);
  params.set(CoreAdminParams.ACTION, CoreAdminAction.OVERSEEROP.toString());
  params.set("op", op);
  params.set("qt", adminPath);
  params.set("electionNode", electionNode);
  ShardRequest sreq = new ShardRequest();
  sreq.purpose = 1;
  String replica = zkStateReader.getBaseUrlForNodeName(LeaderElector.getNodeName(electionNode));
  sreq.shards = new String[]{replica};
  sreq.actualShards = sreq.shards;
  sreq.params = params;
  shardHandler.submit(sreq, replica, sreq.params);
  shardHandler.takeCompletedOrError();
}
 
Example 2
Source Project: solr-redis   Source File: TestRedisQParserPluginIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRetryOnConnectionProblem() {
  final String[] doc = {"id", "1", "string_field", "test"};
  assertU(adoc(doc));
  assertU(commit());

  final ModifiableSolrParams params = new ModifiableSolrParams();
  params.add("q", "*:*");
  params.add("fq", "{!redis command=smembers key=test_set}string_field");
  assertQ(req(params), "*[count(//doc)=1]", "//result/doc[1]/str[@name='id'][.='1']");

  jedis.configSet("timeout", "1");
  try {
    TimeUnit.SECONDS.sleep(2);
  } catch (final InterruptedException e) {
    Thread.currentThread().interrupt();
  }

  assertQ(req(params), "*[count(//doc)=1]", "//result/doc[1]/str[@name='id'][.='1']");
}
 
Example 3
Source Project: vind   Source File: IssueExampleTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests MBC-1203 (Static synonyms)
 * Attention! To enable this, make sure that you use the WhiteSpaceTokenizer (for query and index).
 */
@Test
@Ignore //At the moment synonyms are not supported in suggestions
public void testSynonymes() {

    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION, "true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q, "xalps");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD, "dynamic_multi_stored_suggest_analyzed_name");
    params.add(SuggestionRequestParams.SUGGESTION_DF, "suggestions");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ("suggester - test synonym mapping for single facet",req,
            "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='2']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='X-Alps'][.='1']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='My xa'][.='1']");
}
 
Example 4
Source Project: solr-redis   Source File: TestRedisQParserPluginIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFindThreeDocumentsSmembers() {
  final String[] doc1 = {"id", "1", "string_field", "test"};
  final String[] doc2 = {"id", "2", "string_field", "other_key"};
  final String[] doc3 = {"id", "3", "string_field", "other_key"};
  assertU(adoc(doc1));
  assertU(adoc(doc2));
  assertU(adoc(doc3));
  assertU(commit());

  jedis.sadd("test_set", "other_key");

  final ModifiableSolrParams params = new ModifiableSolrParams();
  params.add("q", "*:*");
  params.add("fq", "{!redis command=smembers key=test_set}string_field");
  params.add("sort", "id asc");
  assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/str[@name='id'][.='1']",
      "//result/doc[2]/str[@name='id'][.='2']", "//result/doc[3]/str[@name='id'][.='3']");
}
 
Example 5
Source Project: solr-redis   Source File: TestTaggedQueryHighlighterIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHighlightNoDuplicates() {
  final String[] doc1 = {"id", "1", "string_field", "test1"};
  assertU(adoc(doc1));
  assertU(commit());

  ModifiableSolrParams params = new ModifiableSolrParams();
  params.add("q", "({!redis command=smembers key=test_set1 v=string_field tag=test_tag1})"
          + " OR ({!redis command=smembers key=test_set1 v=string_field tag=test_tag1})");
  params.add("hl", "true");
  params.add("hl.fl", "test_tag1");
  assertQ(req(params),
          "*[count(//doc)=1]",
          "count(//lst[@name='highlighting']/*)=1",
          "//lst[@name='highlighting']/lst[@name='1']/arr[@name='test_tag1']/str='<em>test1</em>'");
}
 
Example 6
Source Project: lucene-solr   Source File: RoutedAliasUpdateProcessor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
  routedAlias.validateRouteValue(cmd);

  // to avoid potential for race conditions, this next method should not get called again unless
  // we have created a collection synchronously
  routedAlias.updateParsedCollectionAliases(this.zkController.zkStateReader, false);

  String targetCollection = routedAlias.createCollectionsIfRequired(cmd);

  if (thisCollection.equals(targetCollection)) {
    // pass on through; we've reached the right collection
    super.processAdd(cmd);
  } else {
    // send to the right collection
    SolrCmdDistributor.Node targetLeaderNode = routeDocToSlice(targetCollection, cmd.getSolrInputDocument());
    cmdDistrib.distribAdd(cmd, Collections.singletonList(targetLeaderNode), new ModifiableSolrParams(outParamsToLeader));
  }
}
 
Example 7
@SuppressWarnings({ "unchecked", "rawtypes" })
private NamedList<Integer> getFacets(SolrQueryRequest request, String query, String field, int minCount)
{
    ModifiableSolrParams params =
            new ModifiableSolrParams(request.getParams())
                    .set(CommonParams.Q, query)
                    .set(CommonParams.ROWS, 0)
                    .set(FacetParams.FACET, true)
                    .set(FacetParams.FACET_FIELD, field)
                    .set(FacetParams.FACET_MINCOUNT, minCount);

    SolrQueryResponse response = cloud.getResponse(nativeRequestHandler, request, params);
    NamedList facetCounts = (NamedList) response.getValues().get("facet_counts");
    NamedList facetFields = (NamedList) facetCounts.get("facet_fields");
    return (NamedList) facetFields.get(field);
}
 
Example 8
Source Project: lucene-solr   Source File: TestDefaultStatsCache.java    License: Apache License 2.0 6 votes vote down vote up
protected void dfQuery(Object... q) throws Exception {
  final ModifiableSolrParams params = new ModifiableSolrParams();
  
  for (int i = 0; i < q.length; i += 2) {
    params.add(q[i].toString(), q[i + 1].toString());
  }
  
  final QueryResponse controlRsp = controlClient.query(params);
  
  // query a random server
  params.set("shards", shards);
  int which = r.nextInt(clients.size());
  SolrClient client = clients.get(which);
  QueryResponse rsp = client.query(params);
  checkResponse(controlRsp, rsp);
}
 
Example 9
Source Project: lucene-solr   Source File: SolrClientNodeStateProvider.java    License: Apache License 2.0 6 votes vote down vote up
static void fetchReplicaMetrics(String solrNode, ClientSnitchCtx ctx, Map<String, Object> metricsKeyVsTag) {
  if (!ctx.isNodeAlive(solrNode)) return;
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.add("key", metricsKeyVsTag.keySet().toArray(new String[0]));
  try {
    SimpleSolrResponse rsp = ctx.invokeWithRetry(solrNode, CommonParams.METRICS_PATH, params);
    metricsKeyVsTag.forEach((key, tag) -> {
      Object v = Utils.getObjectByPath(rsp.nl, true, Arrays.asList("metrics", key));
      if (tag instanceof Function) {
        @SuppressWarnings({"unchecked"})
        Pair<String, Object> p = (Pair<String, Object>) ((Function) tag).apply(v);
        ctx.getTags().put(p.first(), p.second());
      } else {
        if (v != null) ctx.getTags().put(tag.toString(), v);
      }
    });
  } catch (Exception e) {
    log.warn("could not get tags from node {}", solrNode, e);
  }
}
 
Example 10
@Override
public void prepare(ResponseBuilder rb) throws IOException {
  if (!enabled) {
    return;
  }

  String userName = sentryInstance.getUserName(rb.req);
  String superUser = System.getProperty("solr.authorization.superuser", "solr");
  if (superUser.equals(userName)) {
    return;
  }
  Set<String> roles = sentryInstance.getRoles(userName);
  if (roles != null && roles.size() > 0) {
    String filterQuery = getFilterQueryStr(roles);
    ModifiableSolrParams newParams = new ModifiableSolrParams(rb.req.getParams());
    newParams.add("fq", filterQuery);
    rb.req.setParams(newParams);
  } else {
    throw new SolrException(SolrException.ErrorCode.UNAUTHORIZED,
      "Request from user: " + userName +
      " rejected because user is not associated with any roles");
  }
}
 
Example 11
Source Project: BioSolr   Source File: AbstractXJoinTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example 12
Source Project: lucene-solr   Source File: FeaturesSelectionStream.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
public NamedList<Double> call() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams();
  HttpSolrClient solrClient = cache.getHttpSolrClient(baseUrl);

  params.add(DISTRIB, "false");
  params.add("fq","{!igain}");

  for(Map.Entry<String, String> entry : paramsMap.entrySet()) {
    params.add(entry.getKey(), entry.getValue());
  }

  params.add("outcome", outcome);
  params.add("positiveLabel", Integer.toString(positiveLabel));
  params.add("field", field);
  params.add("numTerms", String.valueOf(numTerms));

  QueryRequest request= new QueryRequest(params);
  QueryResponse response = request.process(solrClient);
  NamedList res = response.getResponse();
  return res;
}
 
Example 13
Source Project: BioSolr   Source File: TestXJoinSearchComponent.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void testGroupedSimple() {
  ModifiableSolrParams params = new ModifiableSolrParams();    
  params.add("group", "true");
  params.add("group.field", "colour");
  params.add("group.format", "simple");
  NamedList results = test(params, "xjoin");
  testXJoinResults(results, "xjoin");
  NamedList grouped = (NamedList)results.get("grouped");
  NamedList colours = (NamedList)grouped.get("colour");
  assertEquals(2, colours.get("matches"));
  DocList docs = (DocList)colours.get("doclist");
  assertEquals(docs.size(), 2);
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(1, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(3, it.nextDoc());
  assertFalse(it.hasNext());
}
 
Example 14
/**
 * Asserts that the input {@link ShardState} and the CoreAdmin.SUMMARY response give the same information.
 *
 * @param state the {@link ShardState} instance.
 * @param core the target {@link SolrCore} instance.
 */
public static void assertShardAndCoreSummaryConsistency(ShardState state, SolrCore core) {
    SolrParams params =
            new ModifiableSolrParams()
                    .add(CoreAdminParams.CORE, core.getName())
                    .add(CoreAdminParams.ACTION, "SUMMARY");

    SolrQueryRequest request = new LocalSolrQueryRequest(core, params);
    SolrQueryResponse response = new SolrQueryResponse();
    coreAdminHandler(core).handleRequest(request, response);

    NamedList<?> summary =
            ofNullable(response.getValues())
                    .map(values -> values.get("Summary"))
                    .map(NamedList.class::cast)
                    .map(values -> values.get(core.getName()))
                    .map(NamedList.class::cast)
                    .orElseGet(NamedList::new);

    assertEquals(state.getLastIndexedChangeSetId(), summary.get("Id for last Change Set in index"));
    assertEquals(state.getLastIndexedChangeSetCommitTime(), summary.get("Last Index Change Set Commit Time"));
    assertEquals(state.getLastIndexedTxCommitTime(), summary.get("Last Index TX Commit Time"));
    assertEquals(state.getLastIndexedTxId(), summary.get("Id for last TX in index"));
}
 
Example 15
Source Project: BioSolr   Source File: TestXJoinSearchComponent.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void testGroupedSimple() {
  ModifiableSolrParams params = new ModifiableSolrParams();    
  params.add("group", "true");
  params.add("group.field", "colour");
  params.add("group.format", "simple");
  NamedList results = test(params, "xjoin");
  testXJoinResults(results, "xjoin");
  NamedList grouped = (NamedList)results.get("grouped");
  NamedList colours = (NamedList)grouped.get("colour");
  assertEquals(2, colours.get("matches"));
  DocList docs = (DocList)colours.get("doclist");
  assertEquals(docs.size(), 2);
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(1, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(3, it.nextDoc());
  assertFalse(it.hasNext());
}
 
Example 16
Source Project: lucene-solr   Source File: CarrotClusteringEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPassingOfCustomFields() throws Exception {
  final ModifiableSolrParams params = new ModifiableSolrParams();
  params.add(CarrotParams.CUSTOM_FIELD_NAME, "intfield_i:intfield");
  params.add(CarrotParams.CUSTOM_FIELD_NAME, "floatfield_f:floatfield");
  params.add(CarrotParams.CUSTOM_FIELD_NAME, "heading:multi");
  
  // Let the echo mock clustering algorithm know which custom field to echo
  params.add("custom-fields", "intfield,floatfield,multi");
  
  final List<String> labels = getLabels(checkEngine(
      getClusteringEngine("echo"), 1, 1, new TermQuery(new Term("url",
          "custom_fields")), params).get(0));
  assertEquals(5, labels.size());
  assertEquals("Integer field", "10", labels.get(2));
  assertEquals("Float field", "10.5", labels.get(3));
  assertEquals("List field", "[first, second]", labels.get(4));
}
 
Example 17
Source Project: querqy   Source File: QuerqyDismaxQParserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testThatInterdependentLuceneQueriesWillNotBeCachedSeparately() throws Exception {

    when(request.getSchema()).thenReturn(schema);
    when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
    when(rewriteChain.rewrite(any(), any())).thenReturn(new ExpandedQuery(new MatchAllQuery()));

    final ModifiableSolrParams solrParams = new ModifiableSolrParams();
    solrParams.add("qf", "f1");

    final ModifiableSolrParams localParams = new ModifiableSolrParams();
    localParams.add(CommonParams.CACHE, "sep");

    final QuerqyDismaxQParser parser = new QuerqyDismaxQParser("*:*", localParams, solrParams, request,
            querqyParser, rewriteChain, infoLogging, null);
    parser.luceneQueries = new LuceneQueries(new MatchAllDocsQuery(), Collections.emptyList(),
            Collections.singletonList(new MatchAllDocsQuery()), new MatchAllDocsQuery(), true);
    parser.applyLocalParams();

    final Query query = parser.getQuery();
    Assert.assertFalse(query instanceof ExtendedQuery);
}
 
Example 18
Source Project: lucene-solr   Source File: TestCollectionAPI.java    License: Apache License 2.0 6 votes vote down vote up
private void listCollection() throws IOException, SolrServerException {
  try (CloudSolrClient client = createCloudClient(null)) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.LIST.toString());
    @SuppressWarnings({"rawtypes"})
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");

    NamedList<Object> rsp = client.request(request);
    @SuppressWarnings({"unchecked"})
    List<String> collections = (List<String>) rsp.get("collections");
    assertTrue("control_collection was not found in list", collections.contains("control_collection"));
    assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
    assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
    assertTrue(COLLECTION_NAME1 + " was not found in list", collections.contains(COLLECTION_NAME1));
  }

}
 
Example 19
Source Project: storm-solr   Source File: TestSolrCloudClusterSupport.java    License: Apache License 2.0 5 votes vote down vote up
protected static void createCollection(String collectionName, int numShards, int replicationFactor, String
    confName, File confDir) throws Exception {
  if (confDir != null) {
    assertTrue("Specified Solr config directory '" +
        confDir.getAbsolutePath() + "' not found!", confDir.isDirectory());

    // upload the test configs
    SolrZkClient zkClient = cloudSolrClient.getZkStateReader().getZkClient();
    ZkConfigManager zkConfigManager =
        new ZkConfigManager(zkClient);

    zkConfigManager.uploadConfigDir(confDir.toPath(), confName);
  }

  ModifiableSolrParams modParams = new ModifiableSolrParams();
  modParams.set(CoreAdminParams.ACTION, CollectionParams.CollectionAction.CREATE.name());
  modParams.set("name", collectionName);
  modParams.set("numShards", numShards);
  modParams.set("replicationFactor", replicationFactor);


  int liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes().size();
  int maxShardsPerNode = (int) Math.ceil(((double) numShards * replicationFactor) / liveNodes);

  modParams.set("maxShardsPerNode", maxShardsPerNode);
  modParams.set("collection.configName", confName);
  QueryRequest request = new QueryRequest(modParams);
  request.setPath("/admin/collections");
  cloudSolrClient.request(request);
  ensureAllReplicasAreActive(collectionName, numShards, replicationFactor, 20);
}
 
Example 20
Source Project: lucene-solr   Source File: SimpleFacetsTest.java    License: Apache License 2.0 5 votes vote down vote up
private void addCommonRandomRangeParams(ModifiableSolrParams params) {
  for (int i = 0; i < random().nextInt(2); i++) {
    params.add(FacetParams.FACET_RANGE_OTHER, FacetRangeOther.values()[random().nextInt(FacetRangeOther.values().length)].toString());
  }
  if (random().nextBoolean()) {
    params.add(FacetParams.FACET_RANGE_INCLUDE, FacetRangeInclude.values()[random().nextInt(FacetRangeInclude.values().length)].toString());
  }
  if (random().nextBoolean()) {
    params.add(FacetParams.FACET_MINCOUNT, String.valueOf(random().nextInt(10)));
  }
  params.add(FacetParams.FACET_RANGE_HARD_END, String.valueOf(random().nextBoolean()));
}
 
Example 21
Source Project: lucene-solr   Source File: CollectionAdminRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
  params.set(CoreAdminParams.NAME, aliasName);
  params.set("collections", aliasedCollections);
  return params;
}
 
Example 22
Source Project: lucene-solr   Source File: MockShardHandlerFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ShardHandler getShardHandler() {
  return new ShardHandler() {
    @Override
    public void prepDistributed(ResponseBuilder rb) {}

    @Override
    public void submit(ShardRequest sreq, String shard,
        ModifiableSolrParams params) {}

    @Override
    public ShardResponse takeCompletedIncludingErrors() {
      return null;
    }

    @Override
    public ShardResponse takeCompletedOrError() {
      return null;
    }

    @Override
    public void cancelAll() {}

    @Override
    public ShardHandlerFactory getShardHandlerFactory() {
      return MockShardHandlerFactory.this;
    }
  };
}
 
Example 23
Source Project: lucene-solr   Source File: CollectionAdminRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
  params.set(CoreAdminParams.COLLECTION, collection);
  params.set("target.collection", targetCollection);
  params.set("split.key", splitKey);
  if (forwardTimeout != null) {
    params.set("forward.timeout", forwardTimeout);
  }
  if (properties != null) {
    addProperties(params, properties);
  }

  return params;
}
 
Example 24
Source Project: query-segmenter   Source File: QuerySegmenterQParserTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * The query "solr" should be rewritten to "project:Solr" thus limiting the results to only document 1.
 */
@Test
public void test_only_solr_project_with_request_handler() {

  ModifiableSolrParams params = new ModifiableSolrParams();
  params.add(CommonParams.QT, DISMAX_QPARSER);
  params.add("qq", "solr");

  SolrQueryRequest req = request(params);

  assertQ(req, "//result[@name='response'][@numFound='1']",
      "//result[@name='response']/doc[1]/str[@name='id'][.='1']");
}
 
Example 25
Source Project: lucene-solr   Source File: BaseDistributedSearchTestCase.java    License: Apache License 2.0 5 votes vote down vote up
protected UpdateResponse delQ(SolrClient client, SolrParams params, String... queries) throws IOException, SolrServerException {
  UpdateRequest ureq = new UpdateRequest();
  ureq.setParams(new ModifiableSolrParams(params));
  for (String q: queries) {
    ureq.deleteByQuery(q);
  }
  return ureq.process(client);
}
 
Example 26
Source Project: lucene-solr   Source File: CarrotClusteringEngineTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSolrStopWordsUsedInCarrot2Clustering() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("merge-resources", false);
  params.set(AttributeUtils.getKey(
      LexicalResourcesCheckClusteringAlgorithm.class, "wordsToCheck"),
  "online,solrownstopword");

  // "solrownstopword" is in stopwords.txt, so we're expecting
  // only one cluster with label "online".
  final List<NamedList<Object>> clusters = checkEngine(
      getClusteringEngine("lexical-resource-check"), 1, params);
  assertEquals(getLabels(clusters.get(0)), Collections.singletonList("online"));
}
 
Example 27
Source Project: lucene-solr   Source File: BaseDistributedSearchTestCase.java    License: Apache License 2.0 5 votes vote down vote up
protected UpdateResponse del(SolrClient client, SolrParams params, Object... ids) throws IOException, SolrServerException {
  UpdateRequest ureq = new UpdateRequest();
  ureq.setParams(new ModifiableSolrParams(params));
  for (Object id: ids) {
    ureq.deleteById(id.toString());
  }
  return ureq.process(client);
}
 
Example 28
public void testCopyFieldByIndexing() throws Exception {
  String content = "This is a text that should be copied to a string field and cutoff at 10 characters";
  SolrInputDocument d = processAdd("add-fields-default-mapping", doc(f("id", "1"), f("mynewfield", content)));
  assertU(commit());

  ModifiableSolrParams params = new ModifiableSolrParams();
  params.add("q", "*:*").add("facet", "true").add("facet.field", "mynewfield_str");
  assertQ(req(params)
          , "*[count(//doc)=1]"
          ,"//lst[@name='mynewfield_str']/int[@name='This is a '][.='1']"
          );
}
 
Example 29
Source Project: lucene-solr   Source File: TermsComponentTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRegexpFlagParsing() {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(TermsParams.TERMS_REGEXP_FLAG, "case_insensitive", "literal", "comments", "multiline", "unix_lines",
            "unicode_case", "dotall", "canon_eq");
    try (TermsComponent termsComponent = new TermsComponent()) {
      int flags = termsComponent.resolveRegexpFlags(params);
      int expected = Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.COMMENTS | Pattern.MULTILINE | Pattern.UNIX_LINES
          | Pattern.UNICODE_CASE | Pattern.DOTALL | Pattern.CANON_EQ;
      assertEquals(expected, flags);
    } catch (IOException e) {
      fail("Error closing TermsComponent");
    }
}
 
Example 30
Source Project: BioSolr   Source File: TestXJoinQParserPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private static Query parse(String v) throws SyntaxError {
  ModifiableSolrParams localParams = new ModifiableSolrParams();
  localParams.add(QueryParsing.V, v);
  QParserPlugin qpp = core.getQueryPlugin(PARSER_NAME);
  QParser qp = qpp.createParser(null, localParams, null, req);
  return qp.parse();
}