/** * Create a new node query with the specified boolean expression * <p> * The boolean expression must follow the syntax of the * {@link com.sindicetech.siren.qparser.keyword.ExtendedKeywordQueryParser}. */ public NodeQuery newNode(final String booleanExpression) throws QueryNodeException { final NodeQuery node = new NodeQuery(mapper, parser); node.setBooleanExpression(booleanExpression); return node; }
/** * Create a new twig query with empty root */ public TwigQuery newTwig() { return new TwigQuery(mapper, parser); }
@Override public ConciseTwigQuery newTwig(final String booleanExpression) throws QueryNodeException { final ConciseTwigQuery twig = new ConciseTwigQuery(mapper, (ConciseKeywordQueryParser) parser); twig.setRoot(booleanExpression); return twig; }
/** * A query that shows how to use range query on geo-location data (double) */ private SolrQuery getGeoQuery() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("ChargeDeviceLocation") .with(b.newNode("xsd:double([52 TO 53])").setAttribute("Latitude")) .with(b.newNode("xsd:double([-2 TO 2])").setAttribute("Longitude")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); return query; }
@Test public void testBooleanSpanWithTwig() throws QueryNodeException { final QueryBuilder build = new QueryBuilder(); final TwigQuery twig = build.newTwig() .with(build.newBoolean() .with(build.newTwig("aa") .with(build.newNode("aaa"))) .with(build.newTwig("bb") .with(build.newNode("bbb"))) .setInOrder(false)); assertParser(twig); }
@Test public void testBooleanWithMultipleClauses() throws QueryNodeException { final QueryBuilder build = new QueryBuilder(); final AbstractBooleanQuery bool = build.newBoolean() .with(build.newNode("aaa")) .without(build.newNode("bbb")) .optional(build.newTwig("ccc").with(build.newNode("ddd"))); assertParser(bool); }
@Test public void testBooleanSpanWithNode() throws QueryNodeException { final QueryBuilder build = new QueryBuilder(); final TwigQuery twig = build.newTwig() .with(build.newBoolean() .with(build.newNode("aaa")) .with(build.newNode("bbb")) .setSlop(1)); assertParser(twig); }
private BooleanSpanQuery toBooleanSpanQuery() throws QueryNodeException { int slop = this.hasSlop() ? this.getSlop() : BooleanQueryNodeBuilder.DEFAULT_SLOP; boolean inOrder = this.hasInOrder() ? this.getInOrder() : BooleanQueryNodeBuilder.DEFAULT_INORDER; final BooleanSpanQuery query = new BooleanSpanQuery(slop, inOrder); // convert clauses for (final QueryClause clause : clauses) { final SpanQuery q = new NodeSpanQuery((com.sindicetech.siren.search.node.NodeQuery) clause.getQuery().toQuery(false)); query.add(q, clause.getNodeBooleanOccur()); } return query; }
/** * Create a new twig query with the specified boolean expression as root query * <p> * The boolean expression must follow the syntax of the * {@link com.sindicetech.siren.qparser.keyword.ExtendedKeywordQueryParser}. */ public TwigQuery newTwig(final String booleanExpression) throws QueryNodeException { final TwigQuery twig = new TwigQuery(mapper, parser); twig.setRoot(booleanExpression); return twig; }
/** * Create a new node query with the specified boolean expression * <p> * The boolean expression must follow the syntax of the * {@link com.sindicetech.siren.qparser.keyword.ExtendedKeywordQueryParser}. */ @Override public ConciseNodeQuery newNode(final String booleanExpression) throws QueryNodeException { final ConciseNodeQuery node = new ConciseNodeQuery(mapper, (ConciseKeywordQueryParser) parser); node.setBooleanExpression(booleanExpression); return node; }
@Override public TwigQuery setRange(final int lowerBound, final int upperBound) { return (TwigQuery) super.setRange(lowerBound, upperBound); }
@Override public NodeQuery setBoost(final float boost) { return (NodeQuery) super.setBoost(boost); }
/** * Create a new boolean query. */ public AbstractBooleanQuery newBoolean() { return new BooleanQuery(mapper); }
/** * A query that shows how to use a custom datatype (uri) */ private SolrQuery getWebsiteQuery() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("DeviceOwner") .with(b.newNode("uri(www.sourcelondon.net)").setAttribute("Website")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); return query; }
@Override public NodeQuery setRange(final int lowerBound, final int upperBound) { return (NodeQuery) super.setRange(lowerBound, upperBound); }
@Override public TwigQuery setBoost(final float boost) { return (TwigQuery) super.setBoost(boost); }
/** * A query that shows how to use the nested query parameter to use Solr's * query parsers on Solr's fields. */ private SolrQuery getNestedQuery() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("DeviceOwner") .with(b.newNode("uri(www.sourcelondon.net)").setAttribute("Website")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); query.setParam("nested", "{!lucene} ChargeDeviceName:university"); return query; }
/** * A query that shows how to combine SIREn query with the Solr's facet feature * on a Solr field. */ private SolrQuery getDeviceControllerFacet() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("Connector") .with(b.newNode("xsd:long([32 TO *])").setAttribute("RatedOutputCurrent")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); query.addFacetField("DeviceController.OrganisationName"); return query; }
/** * See #15 */ @Test public void testTwigWithSetAndUnsetAttribute() throws QueryNodeException { final ConciseQueryBuilder build = new ConciseQueryBuilder(); final TwigQuery twig = build.newTwig("funding") .with(build.newNode("a").setAttribute("round")) .with(build.newNode("2006")); assertParser(twig); }
@Test public void testSimpleConciseTreeQuery() throws IOException, SolrServerException, QueryNodeException { this.addJsonString("1", "concise", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); query.setQuery(b.newTwig("aaa").with(b.newNode("ccc").setAttribute("bbb")).toString()); query.setRequestHandler("tree"); query.set("qf", "concise"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length); }