@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(tq); }
@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(ntq); }
@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(nbq); }
@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(npq); }
@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(twq); }
public static LuceneProxyNodeQuery dq(final NodeQuery nq) { return new LuceneProxyNodeQuery(nq); }
@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(nmq); }
@Override public Query build(final QueryNode queryNode) throws QueryNodeException { final TopLevelQueryNode topNode = (TopLevelQueryNode) queryNode; final QueryNode child = topNode.getChildren().get(0); final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); if (child instanceof BooleanQueryNode) { // no need to wrap the query object into a lucene proxy query return (Query) obj; } else { return new LuceneProxyNodeQuery((NodeQuery) obj); } }
@Override public Query rewrite(final IndexReader reader) throws IOException { final Query rewroteQuery = nodeQuery.rewrite(reader); if (nodeQuery == rewroteQuery) { return this; } final LuceneProxyNodeQuery q = new LuceneProxyNodeQuery((NodeQuery) rewroteQuery); q.setBoost(nodeQuery.getBoost()); return q; }
/** * Wraps a {@link NodeQuery} into a {@link LuceneProxyNodeQuery}. * This method is applied on each clause of a {@link BooleanQuery}. */ private Query wrap(final Query q) throws QueryNodeException { if (q instanceof BooleanQuery) { for (final BooleanClause clause: ((BooleanQuery) q).clauses()) { final Query cq = clause.getQuery(); clause.setQuery(this.wrap(cq)); } return q; } else if (q instanceof NodeQuery) { return new LuceneProxyNodeQuery((NodeQuery) q); } else { throw new QueryNodeException(new Error("Expected a BooleanQuery or a NodeQuery: got '" + q.getClass().getCanonicalName() + "'")); } }
@Test public void testWildcardQuery2() throws Exception { final NodeQuery q1 = new NodeWildcardQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "st*e.ca?as")); this._assertSirenQuery(new LuceneProxyNodeQuery(q1), "st*e.ca?as"); }
@Test public void testRegexQueries() throws Exception { final Query reg = new LuceneProxyNodeQuery( new NodeRegexpQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "s*e")) ); this._assertSirenQuery(reg, "/s*e/"); }
@Test public void testFuzzyQuery2() throws Exception { final NodeQuery q1 = new NodeFuzzyQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "michel")); this._assertSirenQuery(new LuceneProxyNodeQuery(q1), "michel~"); final TwigQuery q2 = new TwigQuery(1); q2.addChild(q1, NodeBooleanClause.Occur.MUST); this._assertSirenQuery(new LuceneProxyNodeQuery(q2), "* : michel~"); final int numEdits = FuzzyQuery.floatToEdits(0.8f, "michel".codePointCount(0, "michel".length())); final NodeQuery q3 = new NodeFuzzyQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "michel"), numEdits); this._assertSirenQuery(new LuceneProxyNodeQuery(q3), "michel~0.8"); // first tilde is escaped, not the second one final NodeQuery q4 = new NodeFuzzyQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "http://sw.deri.org/~aida")); this._assertSirenQuery(new LuceneProxyNodeQuery(q4), "'http://sw.deri.org/~aida'~"); }
@Test public void testPrefixQuery() throws Exception { final Query ntq = new LuceneProxyNodeQuery( new NodePrefixQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "lit")) ); this._assertSirenQuery(ntq, "lit*"); final TwigQuery twq = new TwigQuery(1); twq.addChild(new NodePrefixQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "lit")), NodeBooleanClause.Occur.MUST); this._assertSirenQuery(new LuceneProxyNodeQuery(twq), "* : lit*"); }
@Test public void testQNameInDatatype() throws Exception { final String qnames = "./src/test/resources/conf/qnames"; final HashMap<ConfigurationKey, Object> config = new HashMap<ConfigurationKey, Object>(); config.put(KeywordConfigurationKeys.QNAMES, this.loadQNamesFile(qnames)); final Map<String, Analyzer> dts = new HashMap<String, Analyzer>(); dts.put(XSDDatatype.XSD_LONG, new LongNumericAnalyzer(4)); config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, dts); final NodeNumericRangeQuery q = NodeNumericRangeQuery.newLongRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 50l, 60l, true, false); q.setDatatype(XSDDatatype.XSD_LONG); this._assertSirenQuery(config, new LuceneProxyNodeQuery(q), "xsd:long([50 TO 60})"); }
/** * Test for float. * <p> * Numeric ranges get processed with {@link NodeNumericRangeQueryNodeProcessor}. * Single numeric values are processed with {@link NodeNumericQueryNodeProcessor}. */ @Test public void testNumericQuery4() throws Exception { final HashMap<ConfigurationKey, Object> config = new HashMap<ConfigurationKey, Object>(); final Map<String, Analyzer> datatypes = new HashMap<String, Analyzer>(); datatypes.put("float", new FloatNumericAnalyzer(4)); config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, datatypes); final NodePrimitiveQuery q = NodeNumericRangeQuery .newFloatRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 50.5f, 1000.34f, true, true); q.setDatatype("float"); this._assertSirenQuery(config, new LuceneProxyNodeQuery(q), "float([50.5 TO 1000.34])"); }
@Override public org.apache.lucene.search.BooleanQuery toQuery(final boolean proxy) throws QueryNodeException { final org.apache.lucene.search.BooleanQuery query = new org.apache.lucene.search.BooleanQuery(true); // convert clauses for (final QueryClause clause : clauses) { // wrap node query into a lucene proxy query final Query q = new LuceneProxyNodeQuery((org.sindice.siren.search.node.NodeQuery) clause.getQuery().toQuery(false)); query.add(q, clause.getBooleanOccur()); } // add boost if (this.hasBoost()) { query.setBoost(this.getBoost()); } return query; }
@Test(expected=AssertionError.class) public void testNumericDatatypeWrongPrecision() throws Exception { final KeywordQueryParser parser = new KeywordQueryParser(); // Set the default datatypes final Map<String, Analyzer> datatypes = new HashMap<String, Analyzer>(); datatypes.put("int", new IntNumericAnalyzer(4)); parser.setDatatypeAnalyzers(datatypes); final NodeQuery rangeWrong = NodeNumericRangeQuery.newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 42, 12, 21, true, true); assertEquals(new LuceneProxyNodeQuery(rangeWrong), parser.parse("int([12 TO 21])", SirenTestCase.DEFAULT_TEST_FIELD)); }
@Override public Query toQuery(final boolean proxy) throws QueryNodeException { final org.sindice.siren.search.node.NodeQuery query = (org.sindice.siren.search.node.NodeQuery) parser.parse(booleanExpression, ""); if (this.hasLevel()) { query.setLevelConstraint(this.getLevel()); } if (this.hasRange()) { query.setNodeConstraint(this.getLowerBound(), this.getUpperBound()); } if (this.hasBoost()) { query.setBoost(this.getBoost()); } // should we wrap the query into a lucene proxy if (proxy) { return new LuceneProxyNodeQuery(query); } return query; }
@Test public void testBoostQuery() throws Exception { final BooleanQuery q = new BooleanQuery(); q.add(ntq("c").getLuceneProxyQuery(), BooleanClause.Occur.MUST); final NodeQuery nq = ntq("b").getNodeQuery(); nq.setBoost(2); q.add(new LuceneProxyNodeQuery(nq), BooleanClause.Occur.MUST); this._assertSirenQuery(q, "c b^2"); }