org.apache.solr.search.SyntaxError Java Examples

The following examples show how to use org.apache.solr.search.SyntaxError. 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: FacetMapperTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws SyntaxError {

    HashMap<String, String> dateIntervals = new HashMap<>();
    dateIntervals.put("after","[NOW+23DAYS/DAY TO *]");
    dateIntervals.put("before","[* TO NOW+23DAYS/DAY]");

    HashMap<String, String> numberIntervals = new HashMap<>();
    numberIntervals.put("bigger","[23 TO *]");
    numberIntervals.put("smaller","[* TO 22]");

    SingleValueFieldDescriptor.UtilDateFieldDescriptor<Date> testDateField = new FieldDescriptorBuilder().buildUtilDateField("test1");
    FieldDescriptor<Float> testNumericField = new FieldDescriptorBuilder().buildNumericField("numericTest", Float.class);

    Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(testDateField, "dateFacet",dateIntervals).getName().equals("dateFacet"));
    Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(testNumericField, "numericFacet", numberIntervals).getName().equals("numericFacet"));

    Assert.assertTrue(true);
}
 
Example #2
Source File: FacetMapperTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
public void testComplexField() throws SyntaxError {

    HashMap<String, String> dateIntervals = new HashMap<>();
    dateIntervals.put("after","[NOW+23DAYS/DAY TO *]");
    dateIntervals.put("before","[* TO NOW+23DAYS/DAY]");

    HashMap<String, String> numberIntervals = new HashMap<>();
    numberIntervals.put("bigger","[23 TO *]");
    numberIntervals.put("smaller","[* TO 22]");

    SingleValuedComplexField.UtilDateComplexField<Taxonomy,Date,Date> complexDateField = new ComplexFieldDescriptorBuilder<Taxonomy,Date,Date>()
            .setFacet(true, tax -> Arrays.asList(tax.getDate()))
            .buildUtilDateComplexField("complexDateTax", Taxonomy.class, Date.class, Date.class);

    SingleValuedComplexField.NumericComplexField<Taxonomy,Number,Number> complexNumberField = new ComplexFieldDescriptorBuilder<Taxonomy,Number,Number>()
            .setFacet(true, tax -> Arrays.asList(tax.getTerm()))
            .buildNumericComplexField("complexNumberTax", Taxonomy.class, Number.class, Number.class);

    Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(complexDateField, "dateFacet",dateIntervals).getName().equals("dateFacet"));
    Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(complexNumberField, "numericFacet", numberIntervals).getName().equals("numericFacet"));

    Assert.assertTrue(true);
}
 
Example #3
Source File: AlfrescoReRankQParserPlugin.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Query parse() throws SyntaxError {
    String reRankQueryString = localParams.get("reRankQuery");
    boolean scale = localParams.getBool("scale", false);
    QParser reRankParser = QParser.getParser(reRankQueryString, null, req);
    Query reRankQuery = reRankParser.parse();

    int reRankDocs  = localParams.getInt("reRankDocs", 200);
    reRankDocs = Math.max(1, reRankDocs); //

    double reRankWeight = localParams.getDouble("reRankWeight",2.0d);

    int start = params.getInt(CommonParams.START,0);
    int rows = params.getInt(CommonParams.ROWS,10);
    int length = start+rows;
    return new ReRankQuery(reRankQuery, reRankDocs, reRankWeight, length, scale);
}
 
Example #4
Source File: NvlValueSourceParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  ValueSource source = fp.parseValueSource();
  final float nvl = fp.parseFloat();

  return new SimpleFloatFunction(source) {
    @Override
  protected String name() {
      return "nvl";
    }

    @Override
    protected float func(int doc, FunctionValues vals) throws IOException {
      float v = vals.floatVal(doc);
      if (v == nvlFloatValue) {
        return nvl;
      } else {
        return v;
      }
    }
  };
}
 
Example #5
Source File: SimpleFacets.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of facet counts for each of the facet queries
 * specified in the params
 *
 * @see FacetParams#FACET_QUERY
 */
public NamedList<Integer> getFacetQueryCounts() throws IOException,SyntaxError {

  NamedList<Integer> res = new SimpleOrderedMap<>();

  /* Ignore CommonParams.DF - could have init param facet.query assuming
   * the schema default with query param DF intented to only affect Q.
   * If user doesn't want schema default for facet.query, they should be
   * explicit.
   */
  // SolrQueryParser qp = searcher.getSchema().getSolrQueryParser(null);

  String[] facetQs = global.getParams(FacetParams.FACET_QUERY);

  if (null != facetQs && 0 != facetQs.length) {
    for (String q : facetQs) {
      final ParsedParams parsed = parseParams(FacetParams.FACET_QUERY, q);
      getFacetQueryCount(parsed, res);
    }
  }

  return res;
}
 
Example #6
Source File: IntervalFacets.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private int unescape(String s, int i, int n, StringBuilder sb) throws SyntaxError {
  for (; i < n; ++i) {
    char c = s.charAt(i);
    if (c == '\\') {
      ++i;
      if (i < n) {
        c = s.charAt(i);
      } else {
        throw new SyntaxError("Unfinished escape at index " + i + " in facet interval " + s);
      }
    } else if (c == ',') {
      return i + 1;
    }
    sb.append(c);
  }
  return n;
}
 
Example #7
Source File: ClassificationUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
  String trainingFilterQueryString = (params.get(KNN_FILTER_QUERY));
  try {
    if (trainingFilterQueryString != null && !trainingFilterQueryString.isEmpty()) {
      Query trainingFilterQuery = this.parseFilterQuery(trainingFilterQueryString, params, req);
      classificationParams.setTrainingFilterQuery(trainingFilterQuery);
    }
  } catch (SyntaxError | RuntimeException syntaxError) {
    throw new SolrException
        (SolrException.ErrorCode.SERVER_ERROR,
            "Classification UpdateProcessor Training Filter Query: '" + trainingFilterQueryString + "' is not supported", syntaxError);
  }

  IndexSchema schema = req.getSchema();
  IndexReader indexReader = req.getSearcher().getIndexReader();

  return new ClassificationUpdateProcessor(classificationParams, next, indexReader, schema);
}
 
Example #8
Source File: SolrPluginUtils.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Executes a basic query
 */
public static DocList doSimpleQuery(String sreq,
                                    SolrQueryRequest req,
                                    int start, int limit) throws IOException {
  List<String> commands = StrUtils.splitSmart(sreq,';');

  String qs = commands.size() >= 1 ? commands.get(0) : "";
  try {
  Query query = QParser.getParser(qs, req).getQuery();

  // If the first non-query, non-filter command is a simple sort on an indexed field, then
  // we can use the Lucene sort ability.
  Sort sort = null;
  if (commands.size() >= 2) {
    sort = SortSpecParsing.parseSortSpec(commands.get(1), req).getSort();
  }

  DocList results = req.getSearcher().getDocList(query,(DocSet)null, sort, start, limit);
  return results;
  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing query: " + qs);
  }

}
 
Example #9
Source File: DirectUpdateHandler2.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private Query getQuery(DeleteUpdateCommand cmd) {
  Query q;
  try {
    // move this higher in the stack?
    QParser parser = QParser.getParser(cmd.getQuery(), cmd.req);
    q = parser.getQuery();
    q = QueryUtils.makeQueryable(q);

    // Make sure not to delete newer versions
    if (ulog != null && cmd.getVersion() != 0 && cmd.getVersion() != -Long.MAX_VALUE) {
      BooleanQuery.Builder bq = new BooleanQuery.Builder();
      bq.add(q, Occur.MUST);
      SchemaField sf = ulog.getVersionInfo().getVersionField();
      ValueSource vs = sf.getType().getValueSource(sf, null);
      ValueSourceRangeFilter filt = new ValueSourceRangeFilter(vs, Long.toString(Math.abs(cmd.getVersion())), null, true, true);
      FunctionRangeQuery range = new FunctionRangeQuery(filt);
      bq.add(range, Occur.MUST_NOT);  // formulated in the "MUST_NOT" sense so we can delete docs w/o a version (some tests depend on this...)
      q = bq.build();
    }

    return q;

  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }
}
 
Example #10
Source File: GeoDistValueSourceParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError {
  String sfield = fp.getParam(SpatialParams.FIELD);
  if (sfield == null) return null;
  SchemaField sf = fp.getReq().getSchema().getField(sfield);
  FieldType type = sf.getType();
  if (type instanceof AbstractSpatialFieldType) {
    @SuppressWarnings({"rawtypes"})
    AbstractSpatialFieldType asft = (AbstractSpatialFieldType) type;
    return new SpatialStrategyMultiValueSource(asft.getStrategy(sfield), asft.getDistanceUnits());
  }
  ValueSource vs = type.getValueSource(sf, fp);
  if (vs instanceof MultiValueSource) {
    return (MultiValueSource)vs;
  }
  throw new SyntaxError("Spatial field must implement MultiValueSource or extend AbstractSpatialFieldType:" + sf);
}
 
Example #11
Source File: FacetParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Parses simple strings like "avg(x)" or robust Maps that may contain local params */
private AggValueSource parseStat(String key, Object args) throws SyntaxError {
  assert null != args;

  if (args instanceof CharSequence) {
    // Both of these variants are already unpacked for us in this case, and use no local params...
    // 1) x:{func:'min(foo)'}
    // 2) x:'min(foo)'
    return parseStatWithParams(key, null, args.toString());
  }

  if (args instanceof Map) {
    @SuppressWarnings({"unchecked"})
    final Map<String,Object> statMap = (Map<String,Object>)args;
    return parseStatWithParams(key, jsonToSolrParams(statMap), statMap.get("func").toString());
  }

  throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
      "Stats must be specified as either a simple string, or a json Map");

}
 
Example #12
Source File: PercentileAgg.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  List<Double> percentiles = new ArrayList<>();
  ValueSource vs = fp.parseValueSource();
  while (fp.hasMoreArguments()) {
    double val = fp.parseDouble();
    if (val<0 || val>100) {
      throw new SyntaxError("requested percentile must be between 0 and 100.  got " + val);
    }
    percentiles.add(val);
  }

  if (percentiles.isEmpty()) {
    throw new SyntaxError("expected percentile(valsource,percent1[,percent2]*)  EXAMPLE:percentile(myfield,50)");
  }

  return new PercentileAgg(vs, percentiles);
}
 
Example #13
Source File: GraphQueryParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void validateFields(String field) throws SyntaxError {

    if (req.getSchema().getField(field) == null) {
      throw new SyntaxError("field " + field + " not defined in schema");
    }

    if (req.getSchema().getField(field).getType().isPointField()) {
      if (req.getSchema().getField(field).hasDocValues()) {
        return;
      } else {
        throw new SyntaxError("point field " + field + " must have docValues=true");
      }
    }

    if (req.getSchema().getField(field).getType() instanceof StrField) {
      if ((req.getSchema().getField(field).hasDocValues() || req.getSchema().getField(field).indexed())) {
        return;
      } else {
        throw new SyntaxError("string field " + field + " must have indexed=true or docValues=true");
      }
    }

    throw new SyntaxError("FieldType for field=" + field + " not supported");

  }
 
Example #14
Source File: CountUsageValueSourceParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  String key = fp.parseArg();
  double val = fp.parseDouble();
  
  AtomicInteger counter = new AtomicInteger();
  if (null != counters.putIfAbsent(key, counter)) {
    throw new IllegalArgumentException("Key has already been used: " + key);
  } 
  return new CountDocsValueSource(counter, val);
}
 
Example #15
Source File: RangeFacetProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
private <T extends Comparable<T>> NamedList getFacetRangeCounts(final RangeFacetRequest rfr)
    throws IOException, SyntaxError {

  final NamedList<Object> res = new SimpleOrderedMap<>();
  final NamedList<Integer> counts = new NamedList<>();
  res.add("counts", counts);

  // explicitly return the gap.
  res.add("gap", rfr.getGapObj());

  DocSet docSet = computeDocSet(docsOrig, rfr.getExcludeTags());

  for (RangeFacetRequest.FacetRange range : rfr.getFacetRanges()) {
    if (range.other != null) {
      // these are added to top-level NamedList
      // and we always include them regardless of mincount
      res.add(range.other.toString(), rangeCount(docSet, rfr, range));
    } else {
      final int count = rangeCount(docSet, rfr, range);
      if (count >= rfr.getMinCount()) {
        counts.add(range.lower, count);
      }
    }
  }

  // explicitly return the start and end so all the counts
  // (including before/after/between) are meaningful - even if mincount
  // has removed the neighboring ranges
  res.add("start", rfr.getStartObj());
  res.add("end", rfr.getEndObj());

  return res;
}
 
Example #16
Source File: FacetParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void parseSubs(Object o) throws SyntaxError {
  if (o==null) return;
  if (o instanceof Map) {
    @SuppressWarnings({"unchecked"})
    Map<String,Object> m = (Map<String, Object>) o;
    for (Map.Entry<String,Object> entry : m.entrySet()) {
      String key = entry.getKey();
      Object value = entry.getValue();

      if ("processEmpty".equals(key)) {
        facet.processEmpty = getBoolean(m, "processEmpty", false);
        continue;
      }

      // "my_prices" : { "range" : { "field":...
      // key="my_prices", value={"range":..

      Object parsedValue = parseFacetOrStat(key, value);

      // TODO: have parseFacetOrStat directly add instead of return?
      if (parsedValue instanceof FacetRequest) {
        facet.addSubFacet(key, (FacetRequest)parsedValue);
      } else if (parsedValue instanceof AggValueSource) {
        facet.addStat(key, (AggValueSource)parsedValue);
      } else {
        throw err("Unknown facet type key=" + key + " class=" + (parsedValue == null ? "null" : parsedValue.getClass().getName()));
      }
    }
  } else {
    // facet : my_field?
    throw err("Expected map for facet/stat");
  }
}
 
Example #17
Source File: FacetParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public Object parseFacetOrStat(String key, Object o) throws SyntaxError {

    if (o instanceof String) {
      return parseStringFacetOrStat(key, (String)o);
    }

    if (!(o instanceof Map)) {
      throw err("expected Map but got " + o);
    }

    // The type can be in a one element map, or inside the args as the "type" field
    // { "query" : "foo:bar" }
    // { "range" : { "field":... } }
    // { "type"  : range, field : myfield, ... }
    @SuppressWarnings({"unchecked"})
    Map<String,Object> m = (Map<String,Object>)o;
    String type;
    Object args;

    if (m.size() == 1) {
      Map.Entry<String,Object> entry = m.entrySet().iterator().next();
      type = entry.getKey();
      args = entry.getValue();
      // throw err("expected facet/stat type name, like {range:{... but got " + m);
    } else {
      // type should be inside the map as a parameter
      Object typeObj = m.get("type");
      if (!(typeObj instanceof String)) {
        throw err("expected facet/stat type name, like {type:range, field:price, ...} but got " + typeObj);
      }
      type = (String)typeObj;
      args = m;
    }

    return parseFacetOrStat(key, type, args);
  }
 
Example #18
Source File: EdismaxQueryConverter.java    From solr-researcher with Apache License 2.0 5 votes vote down vote up
@Override
public List<Clause> convert(String query, SolrQueryRequest req) {
  try {
    Map<String, Float> queryFields = DisMaxQParser.parseQueryFields(req.getSchema(), req.getParams());
    return splitIntoClauses(query, queryFields.keySet(), false);
  } catch (SyntaxError e) {
    throw new RuntimeException();
  }
}
 
Example #19
Source File: FacetParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Parses simple strings like "avg(x)" in the context of optional local params (may be null) */
private AggValueSource parseStatWithParams(String key, SolrParams localparams, String stat) throws SyntaxError {
  SolrQueryRequest req = getSolrRequest();
  FunctionQParser parser = new FunctionQParser(stat, localparams, req.getParams(), req);
  AggValueSource agg = parser.parseAgg(FunctionQParser.FLAG_DEFAULT);
  return agg;
}
 
Example #20
Source File: ParseUtility.java    From semantic-knowledge-graph with Apache License 2.0 5 votes vote down vote up
public static Query parseQueryString(String qString, SolrQueryRequest req) {
    try {
        QParser parser = QParser.getParser(qString, req.getParams().get("defType"), req);
        return parser.getQuery();
    } catch (SyntaxError e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                "Syntax error in query: " + qString + ".");
    }
}
 
Example #21
Source File: GeoDistValueSourceParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** make a MultiValueSource from two non MultiValueSources */
private VectorValueSource makeMV(List<ValueSource> sources, List<ValueSource> orig) throws SyntaxError {
  ValueSource vs1 = sources.get(0);
  ValueSource vs2 = sources.get(1);

  if (vs1 instanceof MultiValueSource || vs2 instanceof MultiValueSource) {
    throw new SyntaxError("geodist - invalid parameters:" + orig);
  }
  return  new VectorValueSource(sources);
}
 
Example #22
Source File: VectorQParserPlugin.java    From solr-vector-scoring with Apache License 2.0 5 votes vote down vote up
@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
	return new QParser(qstr, localParams, params, req) {
		@Override
		public Query parse() throws SyntaxError {
			String field = localParams.get(QueryParsing.F);
			String vector = localParams.get("vector");
			boolean cosine = localParams.getBool("cosine", true);

			if (field == null) {
				throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'f' not specified");
			}

			if (vector == null) {
				throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "vector missing");
			}

			Query subQuery = subQuery(localParams.get(QueryParsing.V), null).getQuery();

			FieldType ft = req.getCore().getLatestSchema().getFieldType(field);
			if(ft != null) {
				VectorQuery q = new VectorQuery(subQuery);
				q.setQueryString(localParams.toLocalParamsString()); 
				query = q;
			}
		

			if (query == null) {
				throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Query is null");
			}

			return new VectorScoreQuery(query, vector, field, cosine);

		}
	};
}
 
Example #23
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 #24
Source File: BJQParserTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testFiltersCache() throws SyntaxError, IOException {
  final String [] elFilterQuery = new String[] {"q", "{!filters param=$child.fq v=$gchq}",
      "child.fq", "childparent_s:e",
      "child.fq", "child_s:l",
      "gchq", "child_s:[* TO *]"};
  assertQ("precondition: single doc match", 
       req(elFilterQuery), elChild);
  final Query query;
  try(final SolrQueryRequest req = req(elFilterQuery)) {
    QParser parser = QParser.getParser(req.getParams().get("q"), null, req);
    query = parser.getQuery();
    final TopDocs topDocs = req.getSearcher().search(query, 10);
    assertEquals(1, topDocs.totalHits.value);
  }
  assertU(adoc("id", "12275", 
      "child_s", "l", "childparent_s", "e"));
  assertU(commit());

  assertQ("here we rely on autowarming for cathing cache leak",  //cache=false
        req(elFilterQuery), "//*[@numFound='2']");

  try(final SolrQueryRequest req = req()) {
      final int count = req.getSearcher().count(query);
      assertEquals("expecting new doc is visible to old query", 2, count);
  }
}
 
Example #25
Source File: IntervalFacets.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private BytesRef getLimitFromString(SchemaField schemaField, StringBuilder builder) throws SyntaxError {
  String value = builder.toString().trim();
  if (value.length() == 0) {
    throw new SyntaxError("Empty interval limit");
  }
  return getLimitFromString(schemaField, value);
}
 
Example #26
Source File: FacetRangeProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the range string from the map and Returns {@link Range}
 *
 * @param range map containing the interval
 * @return {@link Range}
 */
private Range getRangeByOldFormat(Map<String, Object> range) {
  String key = getString(range, "key", false);
  String rangeStr = getString(range, "range", true);
  try {
    return parseRangeFromString(key, rangeStr);
  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }
}
 
Example #27
Source File: IntervalFacets.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor that accepts un-parsed intervals using "interval faceting" syntax. See {@link IntervalFacets} for syntax.
 * Intervals don't need to be in order.
 */
public IntervalFacets(SchemaField schemaField, SolrIndexSearcher searcher, DocSet docs, String[] intervals, SolrParams params) throws SyntaxError, IOException {
  this.schemaField = schemaField;
  this.searcher = searcher;
  this.docs = docs;
  this.intervals = getSortedIntervals(intervals, params);
  doCount();
}
 
Example #28
Source File: MtasJoinQParser.java    From mtas with Apache License 2.0 5 votes vote down vote up
@Override
public Query parse() throws SyntaxError {
  if (id == null) {
    throw new SyntaxError("no " + MTAS_JOIN_QPARSER_COLLECTION);
  } else if (fields == null) {
    throw new SyntaxError("no " + MTAS_JOIN_QPARSER_FIELD);
  } else {

    BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();

    MtasSolrCollectionCache mtasSolrJoinCache = null;
    for (PluginHolder<SearchComponent> item : req.getCore()
        .getSearchComponents().getRegistry().values()) {
      if (item.get() instanceof MtasSolrSearchComponent) {
        mtasSolrJoinCache = ((MtasSolrSearchComponent) item.get())
            .getCollectionCache();
      }
    }
    if (mtasSolrJoinCache != null) {
      Automaton automaton;
      try {
        automaton = mtasSolrJoinCache.getAutomatonById(id);
        if (automaton != null) {
          for (String field : fields) {
            booleanQueryBuilder.add(
                new AutomatonQuery(new Term(field), automaton), Occur.SHOULD);
          }
        } else {
          throw new IOException("no data for collection '" + id + "'");
        }
      } catch (IOException e) {
        throw new SyntaxError(
            "could not construct automaton: " + e.getMessage(), e);
      }
      return booleanQueryBuilder.build();
    } else {
      throw new SyntaxError("no MtasSolrSearchComponent found");
    }
  }
}
 
Example #29
Source File: RangeFacetProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Macro for getting the numDocs of range over docs
 *
 * @see org.apache.solr.search.SolrIndexSearcher#numDocs
 * @see org.apache.lucene.search.TermRangeQuery
 */
protected int rangeCount(DocSet subset, RangeFacetRequest rfr, RangeFacetRequest.FacetRange fr) throws IOException, SyntaxError {
  SchemaField schemaField = rfr.getSchemaField();
  Query rangeQ = schemaField.getType().getRangeQuery(null, schemaField, fr.lower, fr.upper, fr.includeLower, fr.includeUpper);
  if (rfr.isGroupFacet()) {
    return getGroupedFacetQueryCount(rangeQ, subset);
  } else {
    return searcher.numDocs(rangeQ, subset);
  }
}
 
Example #30
Source File: GeoDistValueSourceParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private MultiValueSource parsePoint(FunctionQParser fp) throws SyntaxError {
  String ptStr = fp.getParam(SpatialParams.POINT);
  if (ptStr == null) return null;
  Point point = SpatialUtils.parsePointSolrException(ptStr, SpatialContext.GEO);
  //assume Lat Lon order
  return new VectorValueSource(
      Arrays.<ValueSource>asList(new DoubleConstValueSource(point.getY()), new DoubleConstValueSource(point.getX())));
}