Java Code Examples for org.apache.solr.common.params.SolrParams#wrapDefaults()

The following examples show how to use org.apache.solr.common.params.SolrParams#wrapDefaults() . 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: CollectionAdminRequest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
  params.add(CommonParams.NAME, aliasName);
  params.add(ROUTER_TYPE_NAME, RoutedAliasTypes.CATEGORY.name());
  params.add(ROUTER_FIELD, routerField);
  params.add(ROUTER_MAX_CARDINALITY, maxCardinality.toString());

  if (mustMatch != null) {
    params.add(ROUTER_MUST_MATCH, mustMatch);
  }

  // merge the above with collectionParams.  Above takes precedence.
  ModifiableSolrParams createCollParams = mergeCollParams(createCollTemplate);
  return SolrParams.wrapDefaults(params, createCollParams);
}
 
Example 2
Source File: QuerqyDismaxQParser.java    From querqy with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for the QParser
 *
 * @param qstr        The part of the query string specific to this parser
 * @param localParams The set of parameters that are specific to this QParser.  See http://wiki.apache.org/solr/LocalParams
 * @param params      The rest of the {@link SolrParams}
 * @param req         The original {@link SolrQueryRequest}
 * @param querqyParser The Querqy query parser to be applied to the input query string
 * @param rewriteChain The chain of rewriters to be applied to this request
 * @param infoLogging The info logging object for this request
 * @param termQueryCache The term query cache.
 *
 */
public QuerqyDismaxQParser(final String qstr, final SolrParams localParams, final SolrParams params,
                           final SolrQueryRequest req, final QuerqyParser querqyParser,
                           final RewriteChain rewriteChain, final InfoLogging infoLogging,
                           final TermQueryCache termQueryCache) {
    super(qstr, localParams, params, req);
    final String q = Objects.requireNonNull(qstr).trim();
    if (q.isEmpty()) {
        throw new SolrException(BAD_REQUEST, "Query string must not be empty");
    }
    this.userQueryString = q;
    this.querqyParser = querqyParser;

    requestAdapter = new DismaxSearchEngineRequestAdapter(this, req, userQueryString,
            SolrParams.wrapDefaults(localParams, params), querqyParser, rewriteChain, infoLogging, termQueryCache);


    controller = new QueryParsingController(requestAdapter);

}
 
Example 3
Source File: DisMaxQParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Query parse() throws SyntaxError {
  
  parsed = true;
  SolrParams solrParams = SolrParams.wrapDefaults(localParams, params);

  queryFields = parseQueryFields(req.getSchema(), solrParams);
  
  /* the main query we will execute.  we disable the coord because
   * this query is an artificial construct
   */
  BooleanQuery.Builder query = new BooleanQuery.Builder();

  boolean notBlank = addMainQuery(query, solrParams);
  if (!notBlank)
    return null;
  addBoostQuery(query, solrParams);
  addBoostFunctions(query, solrParams);

  return QueryUtils.build(query, this);
}
 
Example 4
Source File: SubQueryAugmenterFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void transform(SolrDocument doc, int docid) {

  final SolrParams docWithDeprefixed = SolrParams.wrapDefaults(
      new DocRowParams(doc, prefix, separator), baseSubParams);
  try {
    QueryResponse rsp = server.query(coreName, docWithDeprefixed);
    SolrDocumentList docList = rsp.getResults();
    doc.setField(getName(), new Result(docList));
  } catch (Exception e) {
    String docString = doc.toString();
    throw new SolrException(ErrorCode.BAD_REQUEST, "while invoking " +
        name + ":[subquery"+ (coreName!=null ? "fromIndex="+coreName : "") +"] on doc=" +
          docString.substring(0, Math.min(100, docString.length())), e.getCause());
  }
}
 
Example 5
Source File: AbstractTaggerTest.java    From SolrTextTagger with Apache License 2.0 5 votes vote down vote up
/** REMEMBER to close() the result req object. */
protected SolrQueryRequest reqDoc(String doc, SolrParams moreParams) {
  log.debug("Test doc: "+doc);
  SolrParams params = SolrParams.wrapDefaults(moreParams, baseParams);
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), params) {};
  Iterable<ContentStream> stream = Collections.singleton((ContentStream)new ContentStreamBase.StringStream(doc));
  req.setContentStreams(stream);
  return req;
}
 
Example 6
Source File: ExtendedDismaxQParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public ExtendedSolrQueryParser(QParser parser, String defaultField) {
  super(parser, defaultField);
  // Respect the q.op parameter before mm will be applied later
  SolrParams defaultParams = SolrParams.wrapDefaults(parser.getLocalParams(), parser.getParams());
  QueryParser.Operator defaultOp = QueryParsing.parseOP(defaultParams.get(QueryParsing.OP));
  setDefaultOperator(defaultOp);
}
 
Example 7
Source File: TestCloudPivotFacet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Executes a query and compares the results with the data available in the 
 * {@link PivotField} constraint -- this method is not recursive, and doesn't 
 * check anything about the sub-pivots (if any).
 *
 * @param pivotName pivot name
 * @param constraint filters on pivot
 * @param params base solr parameters
 */
private void assertPivotData(String pivotName, PivotField constraint, SolrParams params)
    throws SolrServerException, IOException {
  
  SolrParams p = SolrParams.wrapDefaults(params("rows","0"), params);
  QueryResponse res = cloudClient.query(p);
  String msg = pivotName + ": " + p;

  assertNumFound(msg, constraint.getCount(), res);

  if ( p.getBool(StatsParams.STATS, false) ) {
    // only check stats if stats expected
    assertPivotStats(msg, constraint, res);
  }
}
 
Example 8
Source File: LegacyFacet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void parseParams(String type, String param)  {
  facetValue = param;
  key = param;

  try {
    localParams = QueryParsing.getLocalParams(param, orig);

    if (localParams == null) {
      params = orig;
      required = new RequiredSolrParams(params);
      // setupStats();
      return;
    }

    params = SolrParams.wrapDefaults(localParams, orig);
    required = new RequiredSolrParams(params);

    // remove local params unless it's a query
    if (type != FacetParams.FACET_QUERY) {
      facetValue = localParams.get(CommonParams.VALUE);
    }

    // reset set the default key now that localParams have been removed
    key = facetValue;

    // allow explicit set of the key
    key = localParams.get(CommonParams.OUTPUT_KEY, key);

    // setupStats();
  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }
}
 
Example 9
Source File: FacetPivotSmallTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testPivotFacetIndexSortMincountAndLimit() throws Exception {
  // sort=index + mincount + limit
  index();
  indexMissing();

  for (SolrParams variableParams : new SolrParams[]{
      // we should get the same results regardless of overrequest
      params(),
      params()}) {
    SolrParams p = SolrParams.wrapDefaults(params("q", "*:*",
            "rows", "0",
            "facet", "true",
            "facet.pivot", "company_t",
            "facet.sort", "index",
            "facet.pivot.mincount", "4",
            "facet.limit", "4"),
        variableParams);
    final String facetPivotPrefix = "//lst[@name='facet_counts']/lst[@name='facet_pivot']/arr[@name='company_t']";
    SolrQueryRequest req = req(p);
    assertQ(req, facetPivotPrefix + "[count(./lst) = 4]",   // not enough values for pivot
        facetPivotPrefix + "/lst[1]/str[@name='value'][.='fujitsu']",
        facetPivotPrefix + "/lst[1]/int[@name='count'][.=4]",
        facetPivotPrefix + "/lst[2]/str[@name='value'][.='microsoft']",
        facetPivotPrefix + "/lst[2]/int[@name='count'][.=5]",
        facetPivotPrefix + "/lst[3]/str[@name='value'][.='null']",
        facetPivotPrefix + "/lst[3]/int[@name='count'][.=6]",
        facetPivotPrefix + "/lst[4]/str[@name='value'][.='polecat']",
        facetPivotPrefix + "/lst[4]/int[@name='count'][.=6]"
    );
  }
}
 
Example 10
Source File: FacetPivotSmallTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testPivotFacetIndexSortMincountLimitAndOffset() throws Exception {
  // sort=index + mincount + limit + offset
  index();
  indexMissing();

  for (SolrParams variableParams : new SolrParams[]{
      // we should get the same results regardless of overrequest
      params(),
      params()}) {
    SolrParams p = SolrParams.wrapDefaults(params("q", "*:*",
            "rows", "0",
            "facet", "true",
            "facet.pivot", "company_t",
            "facet.sort", "index",
            "facet.pivot.mincount", "4",
            "facet.offset", "1",
            "facet.limit", "4"),
        variableParams);
    final String facetPivotPrefix = "//lst[@name='facet_counts']/lst[@name='facet_pivot']/arr[@name='company_t']";
    SolrQueryRequest req = req(p);
    assertQ(req, facetPivotPrefix + "[count(./lst) = 3]", // asked for 4, but not enough meet the mincount
        facetPivotPrefix + "/lst[1]/str[@name='value'][.='microsoft']",
        facetPivotPrefix + "/lst[1]/int[@name='count'][.=5]",
        facetPivotPrefix + "/lst[2]/str[@name='value'][.='null']",
        facetPivotPrefix + "/lst[2]/int[@name='count'][.=6]",
        facetPivotPrefix + "/lst[3]/str[@name='value'][.='polecat']",
        facetPivotPrefix + "/lst[3]/int[@name='count'][.=6]"
    );
  }
}
 
Example 11
Source File: SolrFragmentsBuilder.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Return a {@link org.apache.lucene.search.vectorhighlight.FragmentsBuilder} appropriate for this field.
 * 
 * @param params The params controlling Highlighting
 * @return An appropriate {@link org.apache.lucene.search.vectorhighlight.FragmentsBuilder}.
 */
public FragmentsBuilder getFragmentsBuilder(SolrParams params, BoundaryScanner bs) {
  numRequests.inc();
  params = SolrParams.wrapDefaults(params, defaults);

  return getFragmentsBuilder( params, getPreTags( params, null ), getPostTags( params, null ), bs );
}
 
Example 12
Source File: SolrFragmentsBuilder.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private String[] getTags( SolrParams params, String paramName, String fieldName, String def ){
  params = SolrParams.wrapDefaults(params, defaults);

  String value = null;
  if( fieldName == null )
    value = params.get( paramName, def );
  else
    value = params.getFieldParam( fieldName, paramName, def );
  String[] tags = value.split( "," );
  for( int i = 0; i < tags.length; i++ ){
    tags[i] = tags[i].trim();
  }
  return tags;
}
 
Example 13
Source File: FacetPivotSmallTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testPivotFacetIndexSortMincountLimitAndOffsetPermutations() throws Exception {
  // sort=index + mincount + limit + offset (more permutations)
  index();
  indexMissing();

  for (SolrParams variableParams : new SolrParams[]{
      // all of these combinations should result in the same first value
      params("facet.pivot.mincount", "4",
          "facet.offset", "2"),
      params("facet.pivot.mincount", "5",
          "facet.offset", "1"),
      params("facet.pivot.mincount", "6",
          "facet.offset", "0")}) {
    SolrParams p = SolrParams.wrapDefaults(params("q", "*:*",
            "rows", "0",
            "facet", "true",
            "facet.limit", "1",
            "facet.sort", "index",
            "facet.overrequest.ratio", "0",
            "facet.pivot", "company_t"),
        variableParams);
    final String facetPivotPrefix = "//lst[@name='facet_counts']/lst[@name='facet_pivot']/arr[@name='company_t']";
    SolrQueryRequest req = req(p);
    assertQ(req, facetPivotPrefix + "[count(./lst) = 1]", // asked for 4, but not enough meet the mincount
        facetPivotPrefix + "/lst[1]/str[@name='value'][.='null']",
        facetPivotPrefix + "/lst[1]/int[@name='count'][.=6]"
    );
  }
}
 
Example 14
Source File: HtmlFormatter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Formatter getFormatter(String fieldName, SolrParams params ) 
{
  numRequests.inc();
  params = SolrParams.wrapDefaults(params, defaults);

  return new SimpleHTMLFormatter(
      params.getFieldParam(fieldName, HighlightParams.SIMPLE_PRE,  "<em>" ), 
      params.getFieldParam(fieldName, HighlightParams.SIMPLE_POST, "</em>"));
}
 
Example 15
Source File: SimpleQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public SimpleQParser (String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {

      super(qstr, localParams, params, req);
      // Some of the parameters may come in through localParams, so combine them with params.
      SolrParams defaultParams = SolrParams.wrapDefaults(localParams, params);

      // This will be used to specify what fields and boosts will be used by SimpleQueryParser.
      Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(defaultParams.get(SimpleParams.QF));

      if (queryFields.isEmpty()) {
        // It qf is not specified setup up the queryFields map to use the defaultField.
        String defaultField = defaultParams.get(CommonParams.DF);

        if (defaultField == null) {
          // A query cannot be run without having a field or set of fields to run against.
          throw new IllegalStateException("Neither " + SimpleParams.QF + " nor " + CommonParams.DF
              + " are present.");
        }

        queryFields.put(defaultField, 1.0F);
      }
      else {
        for (Map.Entry<String, Float> queryField : queryFields.entrySet()) {
          if (queryField.getValue() == null) {
            // Some fields may be specified without a boost, so default the boost to 1.0 since a null value
            // will not be accepted by SimpleQueryParser.
            queryField.setValue(1.0F);
          }
        }
      }

      // Setup the operations that are enabled for the query.
      int enabledOps = 0;
      String opParam = defaultParams.get(SimpleParams.QO);

      if (opParam == null) {
        // All operations will be enabled.
        enabledOps = -1;
      } else {
        // Parse the specified enabled operations to be used by the query.
        String[] operations = opParam.split(",");

        for (String operation : operations) {
          Integer enabledOp = OPERATORS.get(operation.trim().toUpperCase(Locale.ROOT));

          if (enabledOp != null) {
            enabledOps |= enabledOp;
          }
        }
      }

      // Create a SimpleQueryParser using the analyzer from the schema.
      final IndexSchema schema = req.getSchema();
      parser = new SolrSimpleQueryParser(req.getSchema().getQueryAnalyzer(), queryFields, enabledOps, this, schema);

      // Set the default operator to be either 'AND' or 'OR' for the query.
      QueryParser.Operator defaultOp = QueryParsing.parseOP(defaultParams.get(QueryParsing.OP));

      if (defaultOp == QueryParser.Operator.AND) {
        parser.setDefaultOperator(BooleanClause.Occur.MUST);
      }
    }
 
Example 16
Source File: DistribCursorPagingTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private SolrParams p(SolrParams params, String... other) {
  SolrParams extras = params(other);
  return SolrParams.wrapDefaults(params, extras);
}
 
Example 17
Source File: TestStressThreadBackup.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** TODO: SOLR-9239, no solrj API for CoreAdmin Backups */
protected GenericSolrRequest makeCoreAdmin(CoreAdminAction action, SolrParams p) {
  return new GenericSolrRequest(GenericSolrRequest.METHOD.POST, "/admin/cores",
                                SolrParams.wrapDefaults(params(CoreAdminParams.ACTION, action.toString()), p));
}
 
Example 18
Source File: PivotFacetProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private ParsedParams getParsedParams(SolrParams params, DocSet docs, FacetComponent.FacetBase facet) {
  SolrParams wrapped = SolrParams.wrapDefaults(facet.localParams, global);
  SolrParams required = new RequiredSolrParams(params);
  return new ParsedParams(facet.localParams, wrapped, required, facet.facetOn, docs, facet.getKey(), facet.getTags(), -1);
}
 
Example 19
Source File: FacetPivotSmallTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testPivotFacetMissing() throws Exception {
  // Test facet.missing=true with diff sorts
  index();
  indexMissing();

  SolrParams missingA = params("q", "*:*",
      "rows", "0",
      "facet", "true",
      "facet.pivot", "place_t,company_t",
      // default facet.sort
      FacetParams.FACET_MISSING, "true");

  final String facetPivotPrefix = "//lst[@name='facet_counts']/lst[@name='facet_pivot']/arr[@name='place_t,company_t']/lst";
  SolrQueryRequest req = req(missingA);
  assertQ(req, facetPivotPrefix + "/arr[@name='pivot'][count(.) > 0]",   // not enough values for pivot
      facetPivotPrefix + "[7]/null[@name='value'][.='']",   // not the missing place value
      facetPivotPrefix + "[7]/int[@name='count'][.=2]",       // wrong missing place count
      facetPivotPrefix + "[7]/arr[@name='pivot'][count(.) > 0]", // not enough sub-pivots for missing place
      facetPivotPrefix + "[7]/arr[@name='pivot']/lst[6]/null[@name='value'][.='']", // not the missing company value
      facetPivotPrefix + "[7]/arr[@name='pivot']/lst[6]/int[@name='count'][.=1]", // wrong missing company count
      facetPivotPrefix + "[7]/arr[@name='pivot']/lst[6][not(arr[@name='pivot'])]" // company shouldn't have sub-pivots
  );

  SolrParams missingB = SolrParams.wrapDefaults(missingA,
      params(FacetParams.FACET_LIMIT, "4",
          "facet.sort", "index"));


  req = req(missingB);
  assertQ(req, facetPivotPrefix + "/arr[@name='pivot'][count(.) > 0]",   // not enough values for pivot
      facetPivotPrefix + "[5]/null[@name='value'][.='']",   // not the missing place value
      facetPivotPrefix + "[5]/int[@name='count'][.=2]",       // wrong missing place count
      facetPivotPrefix + "[5]/arr[@name='pivot'][count(.) > 0]", // not enough sub-pivots for missing place
      facetPivotPrefix + "[5]/arr[@name='pivot']/lst[5]/null[@name='value'][.='']", // not the missing company value
      facetPivotPrefix + "[5]/arr[@name='pivot']/lst[5]/int[@name='count'][.=1]", // wrong missing company count
      facetPivotPrefix + "[5]/arr[@name='pivot']/lst[5][not(arr[@name='pivot'])]" // company shouldn't have sub-pivots
  );

  SolrParams missingC = SolrParams.wrapDefaults(missingA,
      params(FacetParams.FACET_LIMIT, "0", "facet.sort", "index"));

  assertQ(req(missingC), facetPivotPrefix + "/arr[@name='pivot'][count(.) > 0]",   // not enough values for pivot
      facetPivotPrefix + "[1]/null[@name='value'][.='']",   // not the missing place value
      facetPivotPrefix + "[1]/int[@name='count'][.=2]",       // wrong missing place count
      facetPivotPrefix + "[1]/arr[@name='pivot'][count(.) > 0]", // not enough sub-pivots for missing place
      facetPivotPrefix + "[1]/arr[@name='pivot']/lst[1]/null[@name='value'][.='']", // not the missing company value
      facetPivotPrefix + "[1]/arr[@name='pivot']/lst[1]/int[@name='count'][.=1]", // wrong missing company count
      facetPivotPrefix + "[1]/arr[@name='pivot']/lst[1][not(arr[@name='pivot'])]" // company shouldn't have sub-pivots
  );
}
 
Example 20
Source File: SolrBoundaryScanner.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public BoundaryScanner getBoundaryScanner(String fieldName, SolrParams params){
  numRequests.inc();
  params = SolrParams.wrapDefaults(params, defaults);

  return get(fieldName, params);
}