@Override public Query rewrite(IndexReader reader) throws IOException { return new NodeBooleanQuery(); } }
/** Constructs an empty boolean span query. */ public BooleanSpanQuery(final int slop, final boolean inOrder) { this.nodeBooleanQuery = new NodeBooleanQuery(); this.slop = slop; this.inOrder = inOrder; }
@Override public Query rewrite(final IndexReader reader) throws IOException { if (terms.isEmpty()) { final NodeBooleanQuery bq = new NodeBooleanQuery(); bq.setBoost(this.getBoost()); return bq; } else if (terms.size() == 1) { final NodeTermQuery tq = new NodeTermQuery(terms.get(0)); tq.setBoost(this.getBoost()); return tq; } else { return super.rewrite(reader); } }
final NodeBooleanQueryNode booleanNode = (NodeBooleanQueryNode) queryNode; final List<QueryNode> children = booleanNode.getChildren(); final NodeBooleanQuery bq = new NodeBooleanQuery();
@Override public Query build(final QueryNode queryNode) throws QueryNodeException { if (conf.has(ConciseKeywordQueryConfigHandler.ConciseKeywordConfigurationKeys.ATTRIBUTE)) { final String attribute = conf.get(ConciseKeywordQueryConfigHandler.ConciseKeywordConfigurationKeys.ATTRIBUTE); final String field = conf.get(ConciseKeywordQueryConfigHandler.ConciseKeywordConfigurationKeys.FIELD); // create the node term query NodeTermQuery ntq = new NodeTermQuery(new Term(field, ConciseNodeBuilderUtil.prepend(builder, attribute, ""))); // assign the datatype. We must always have a datatype assigned. String datatype = DatatypeProcessor.getDefaultDatatype(this.conf); ntq.setDatatype(datatype); return ntq; } else { return new NodeBooleanQuery(); } }
private NodeBooleanQueryBuilder(final BooleanBag[] clauses) { nbq = new NodeBooleanQuery(); for (final BooleanBag bag : clauses) { for (final NodeBooleanClause clause : bag.toNodeBooleanClauses()) { nbq.add(clause); } } }
@Override protected NodeBooleanQuery getTopLevelQuery(final NodeQuery query) { NodeBooleanQuery q = new NodeBooleanQuery(); // set level and node constraints q.setLevelConstraint(query.getLevelConstraint()); q.setNodeConstraint(query.getNodeConstraint()[0], query.getNodeConstraint()[1]); // set ancestor q.setAncestorPointer(query.ancestor); return q; }
@Test public void testEquality() throws Exception { final NodeBooleanQuery bq1 = new NodeBooleanQuery(); bq1.add(new NodeTermQuery(new Term("field", "value1")), NodeBooleanClause.Occur.SHOULD); bq1.add(new NodeTermQuery(new Term("field", "value2")), NodeBooleanClause.Occur.SHOULD); final NodeBooleanQuery bq2 = new NodeBooleanQuery(); bq2.add(new NodeTermQuery(new Term("field", "value1")), NodeBooleanClause.Occur.SHOULD); bq2.add(new NodeTermQuery(new Term("field", "value2")), NodeBooleanClause.Occur.SHOULD); assertEquals(bq2, bq1); }
@Override protected NodeBooleanQuery getTopLevelQuery(final NodeQuery query) { NodeBooleanQuery q = new NodeBooleanQuery(); // set level and node constraints q.setLevelConstraint(query.getLevelConstraint()); q.setNodeConstraint(query.getNodeConstraint()[0], query.getNodeConstraint()[1]); // set ancestor q.setAncestorPointer(query.ancestor); return q; }
@Override protected NodeBooleanQuery getTopLevelQuery(final NodeQuery query) { NodeBooleanQuery q = new NodeBooleanQuery(); // set level and node constraints q.setLevelConstraint(query.getLevelConstraint()); q.setNodeConstraint(query.getNodeConstraint()[0], query.getNodeConstraint()[1]); // set ancestor q.setAncestorPointer(query.ancestor); return q; }
@Override protected NodeBooleanQuery getTopLevelQuery(final NodeQuery query) { NodeBooleanQuery q = new NodeBooleanQuery(); // set level and node constraints q.setLevelConstraint(query.getLevelConstraint()); q.setNodeConstraint(query.getNodeConstraint()[0], query.getNodeConstraint()[1]); // set ancestor q.setAncestorPointer(query.ancestor); return q; }
@Test public void testSetAncestor() { final NodeTermQuery ntq = new NodeTermQuery(new Term("field", "value")); final NodeBooleanQuery bq1 = new NodeBooleanQuery(); bq1.add(ntq, Occur.MUST); final NodeBooleanQuery bq2 = new NodeBooleanQuery(); bq1.setAncestorPointer(bq2); assertSame(bq2, bq1.ancestor); // node queries in node boolean clauses must have been updated assertSame(bq2, ntq.ancestor); final NodeTermQuery ntq2 = new NodeTermQuery(new Term("field", "value")); bq1.add(ntq2, Occur.MUST); // new clause must have been updated assertSame(bq2, ntq2.ancestor); }
/** * Checks that an emtpy node boolean query is returning a null scorer (== no match) */ @Test public void testEmptyBoolean() throws Exception { this.addDocuments( "\"aaa bbb\" \"aaa ccc\" . ", "\"aaa\" \"aaa bbb\" . " ); assertNull(this.getScorer(new NodeBooleanQuery())); }
@Test public void testBooleanAndTermQuery() throws ProjectionException { NodeBooleanQuery bq = new NodeBooleanQuery(); NodePhraseQuery pq = new NodePhraseQuery(); pq.add(new Term("summary", "Whisky")); pq.add(new Term("summary", "Big")); bq.add(pq, Occur.MUST); assertEquals(json, extractor.extractAsString(json, bq)); }
@Test public void testEmptyNodeTermQueryWithNoAttribute() throws Exception { ConciseKeywordQueryParser parser = new ConciseKeywordQueryParser(); final NodeBooleanQuery q = new NodeBooleanQuery(); assertEquals(q, parser.parse("", SirenTestCase.DEFAULT_TEST_FIELD)); }
/** * Tests Wildcard queries with an asterisk. */ public void testAsterisk() throws IOException { this.addDocuments("<metal>", "<metals>"); final NodeQuery query1 = new NodeTermQuery(new Term(DEFAULT_TEST_FIELD, "metal")); final NodeQuery query2 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "metal*")); final NodeQuery query3 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "m*tal")); final NodeQuery query4 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "m*tal*")); final NodeQuery query5 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "m*tals")); final NodeBooleanQuery query6 = new NodeBooleanQuery(); query6.add(query5, NodeBooleanClause.Occur.SHOULD); final NodeBooleanQuery query7 = new NodeBooleanQuery(); query7.add(query3, NodeBooleanClause.Occur.SHOULD); query7.add(query5, NodeBooleanClause.Occur.SHOULD); // Queries do not automatically lower-case search terms: final NodeQuery query8 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "M*tal*")); this.assertMatches(searcher, query1, 1); this.assertMatches(searcher, query2, 2); this.assertMatches(searcher, query3, 1); this.assertMatches(searcher, query4, 2); this.assertMatches(searcher, query5, 1); this.assertMatches(searcher, query6, 1); this.assertMatches(searcher, query7, 2); this.assertMatches(searcher, query8, 0); this.assertMatches(searcher, new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "*tall")), 0); this.assertMatches(searcher, new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "*tal")), 1); this.assertMatches(searcher, new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "*tal*")), 2); }
@Test public void testSetLevelConstraint() { final NodeTermQuery ntq = new NodeTermQuery(new Term("field", "value")); final NodeBooleanQuery bq = new NodeBooleanQuery(); bq.add(ntq, Occur.MUST); bq.setLevelConstraint(3); assertEquals(3, bq.getLevelConstraint()); // node queries in node boolean clauses must have been updated assertEquals(3, ntq.getLevelConstraint()); final NodeTermQuery ntq2 = new NodeTermQuery(new Term("field", "value")); bq.add(ntq2, Occur.MUST); // new clause must have been updated assertEquals(3, ntq2.getLevelConstraint()); }
@Test public void testSetNodeConstraint() { final NodeTermQuery ntq = new NodeTermQuery(new Term("field", "value")); final NodeBooleanQuery bq = new NodeBooleanQuery(); bq.add(ntq, Occur.MUST); bq.setNodeConstraint(2,6); assertEquals(2, bq.lowerBound); assertEquals(6, bq.upperBound); // node queries in node boolean clauses must have been updated assertEquals(2, ntq.lowerBound); assertEquals(6, ntq.upperBound); final NodeTermQuery ntq2 = new NodeTermQuery(new Term("field", "value")); bq.add(ntq2, Occur.MUST); // new clause must have been updated assertEquals(2, ntq2.lowerBound); assertEquals(6, ntq2.upperBound); }
config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, dtAnalyzers); final NodeBooleanQuery complex = new NodeBooleanQuery(); NodeRegexpQuery nestedRegexp = new NodeRegexpQuery(new Term(df, "[a-z]\\/[123]")); nestedRegexp.setDatatype("http://www.w3.org/2001/XMLSchema#string"); final NodeBooleanQuery two = new NodeBooleanQuery(); re = new NodeRegexpQuery(new Term(df, "foo")); re.setDatatype("http://www.w3.org/2001/XMLSchema#string");