List of usage examples for org.apache.solr.search SolrConstantScoreQuery SolrConstantScoreQuery
public SolrConstantScoreQuery(Filter filter)
From source file:CartesianTierQParserPlugin.java
License:Apache License
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { return new QParser(qstr, localParams, params, req) { public Query parse() throws ParseException { final Double x = localParams.getDouble("x"); final Double y = localParams.getDouble("y"); final String fieldPrefix = localParams.get("prefix", tierPrefix); final Double distance = localParams.getDouble("dist"); //GSI: kind of funky passing in an empty string, but AFAICT, it is safe b/c we don't want to assume tier prefix stuff CartesianPolyFilterBuilder cpfb = new CartesianPolyFilterBuilder(fieldPrefix); //Get the box based on this point and our distance final Shape shape = cpfb.getBoxShape(x, y, distance); final List<Double> boxIds = shape.getArea(); //Sort them, so they are in order, which will be faster for termdocs in the tier filter Collections.sort(boxIds); //Get the field type so we can properly encode the data IndexSchema schema = req.getSchema(); FieldType ft = schema.getFieldTypeNoEx(shape.getTierId()); //Create the Filter and wrap it in a constant score query Filter filter = new TierFilter(shape.getTierId(), ft, boxIds); return new SolrConstantScoreQuery(filter); }/* w ww.j a v a2s . c o m*/ }; }
From source file:com.ifactory.press.db.solr.search.ScoringParentQParser.java
License:Apache License
@Override public Query parse() throws SyntaxError { if (localParams == null) { throw new SyntaxError("join query parser must be invoked using localParams"); }/*w w w . j a va 2 s . c o m*/ String filter = localParams.get(getParentFilterLocalParamName()); QParser parentParser = subQuery(filter, null); Query parentQ = parentParser.getQuery(); String queryText = localParams.get(QueryParsing.V); // there is no child query, return parent filter from cache if (queryText == null || queryText.length() == 0) { SolrConstantScoreQuery wrapped = new SolrConstantScoreQuery(getFilter(parentQ)); wrapped.setCache(false); return wrapped; } QParser childrenParser = subQuery(queryText, null); Query childrenQuery = childrenParser.getQuery(); return createQuery(parentQ, childrenQuery); }
From source file:solr2155.solr.schema.GeoHashField.java
License:Apache License
public Query createSpatialQuery(QParser parser, SpatialOptions options) { double[] point = new double[0]; try {// www .j a v a 2 s . co m point = DistanceUtils.parsePointDouble(null, options.pointStr, 2); } catch (InvalidGeoException e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } PointDistanceGeom pDistGeo = new PointDistanceGeom(point[0], point[1], options.distance, options.radius); Geometry2D shape = pDistGeo; if (options.bbox) { shape = pDistGeo.getEnclosingBox1(); Geometry2D shape2 = pDistGeo.getEnclosingBox2(); if (shape2 != null) shape = new MultiGeom(Arrays.asList(shape, shape2)); } return new SolrConstantScoreQuery( new GeoHashPrefixFilter(options.field.getName(), shape, gridReferenceSystem)); }
From source file:solr2155.solr.search.SpatialGeoHashFilterQParser.java
License:Apache License
@Override public Query parse() throws ParseException { final String SFIELD = "sfield"; String field = localParams.get(SFIELD); if (field == null) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, SFIELD + " is not properly specified" + " in local params"); SchemaField schemaField = req.getSchema().getField(field); final FieldType fieldType = schemaField.getType(); if (!(fieldType instanceof GeoHashField)) throw new ParseException("Queried field " + field + " must be a GeoHashField but got " + fieldType); GeoHashField geoHashField = (GeoHashField) fieldType; final Geometry2D geoShape; String polygonArg = getParam("polygon");//ex: "5,2,33,55,22,3" String boxArg = getParam("box"); String pointArg = getParam("point"); String radiusArg = getParam("radius");//in some places we call this "distance" String geometryArg = getParam("geometry"); int args = (polygonArg == null ? 0 : 1) + (boxArg == null ? 0 : 1) + (pointArg == null && radiusArg == null ? 0 : 1) + (geometryArg == null ? 0 : 1); if (args > 1) throw new ParseException("Conflicting geo params in " + params); if (polygonArg != null) { geoShape = parsePolygon(polygonArg); } else if (boxArg != null) { geoShape = parseBox(boxArg);/* ww w .ja v a 2s . c om*/ } else if (pointArg != null) { geoShape = parsePointRadius(pointArg, radiusArg); } else if (geometryArg != null) { geoShape = parseGeometry(geometryArg); } else { throw new ParseException("Couldn't find a geo param in " + params); } return new SolrConstantScoreQuery( new GeoHashPrefixFilter(field, geoShape, geoHashField.getGridReferenceSystem())); }