@Override protected NodeBooleanQuery getTopLevelQuery() { return new NodeBooleanQuery(); }
@Override protected NodeBooleanQuery getTopLevelQuery() { return new NodeBooleanQuery(); }
@Override protected NodeBooleanQuery getTopLevelQuery() { return new NodeBooleanQuery(); }
@Override protected NodeBooleanQuery getTopLevelQuery() { return new NodeBooleanQuery(); }
@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();
public NodeBooleanQuery build(final QueryNode queryNode) throws QueryNodeException { // validates node if (!(queryNode instanceof MatchNoDocsQueryNode)) { throw new QueryNodeException(new MessageImpl( QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode .toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass() .getName())); } 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); } } }
@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); }
@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); }
/** * Tests Wildcard queries with an asterisk. */ public void testAsterisk() throws IOException { this.addDocuments("<metal>", "<metals>"); final NodePrimitiveQuery query1 = new NodeTermQuery(new Term(DEFAULT_TEST_FIELD, "metal")); final NodePrimitiveQuery query2 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "metal*")); final NodePrimitiveQuery query3 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "m*tal")); final NodePrimitiveQuery query4 = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "m*tal*")); final NodePrimitiveQuery 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 NodePrimitiveQuery 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); }
dtAnalyzers.put(XSDDatatype.XSD_STRING, new WhitespaceAnalyzer(LuceneTestCase.TEST_VERSION_CURRENT)); config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, dtAnalyzers); final NodeBooleanQuery complex = new NodeBooleanQuery(); complex.add(new NodeRegexpQuery(new Term(df, "[a-z]\\/[123]")), NodeBooleanClause.Occur.MUST); complex.add(new NodeTermQuery(new Term(df, "/etc/init.d/")), Occur.MUST); final NodeBooleanQuery two = new NodeBooleanQuery(); two.add(new NodeRegexpQuery(new Term(df, "foo")), Occur.SHOULD); two.add(new NodeRegexpQuery(new Term(df, "bar")), Occur.SHOULD);
@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); }