public NodeQuery build(final QueryNode queryNode) throws QueryNodeException { final PrefixWildcardQueryNode wildcardNode = (PrefixWildcardQueryNode) queryNode; final String text = wildcardNode.getText().subSequence(0, wildcardNode.getText().length() - 1).toString(); final NodePrefixQuery q = new NodePrefixQuery(new Term(wildcardNode.getFieldAsString(), text)); // assign the datatype. We must always have a datatype assigned. q.setDatatype((String) queryNode.getTag(DatatypeQueryNode.DATATYPE_TAGID)); final MultiNodeTermQuery.RewriteMethod method = (MultiNodeTermQuery.RewriteMethod)queryNode.getTag(MultiNodeTermRewriteMethodProcessor.TAG_ID); if (method != null) { q.setRewriteMethod(method); } // if it is tagged as a span query if (wildcardNode.getTag(QueryTypeProcessor.QUERYTYPE_TAG) == QueryTypeProcessor.SPAN_QUERYTYPE) { return new MultiTermSpanQuery<>(q); } else { return q; } }
public void testPrefixQuery() throws Exception { this.addDocument("</computers>"); this.addDocument("</computers/mac>"); this.addDocument("</computers/windows>"); NodePrefixQuery query = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "/computers")); ScoreDoc[] hits = searcher.search(dq(query), null, 1000).scoreDocs; assertEquals("All documents in /computers category and below", 3, hits.length); query = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "/computers/mac")); hits = searcher.search(dq(query), null, 1000).scoreDocs; assertEquals("One in /computers/mac", 1, hits.length); query = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "/computers")); query.setNodeConstraint(1); hits = searcher.search(dq(query), null, 1000).scoreDocs; assertEquals("No documents in /computers category and below in node 1", 0, hits.length); query = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "/computers")); query.setNodeConstraint(0); hits = searcher.search(dq(query), null, 1000).scoreDocs; assertEquals("All documents in /computers category and below in node 0", 3, hits.length); }
@Test public void testPrefixQuery() throws Exception { NodePrefixQuery prefix = new NodePrefixQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "lit")); prefix.setDatatype("http://www.w3.org/2001/XMLSchema#string"); final Query ntq = new LuceneProxyNodeQuery(prefix); this._assertSirenQuery(ntq, "lit*"); final TwigQuery twq = new TwigQuery(1); prefix = new NodePrefixQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "lit")); prefix.setDatatype("http://www.w3.org/2001/XMLSchema#string"); twq.addChild(prefix, NodeBooleanClause.Occur.MUST); this._assertSirenQuery(new LuceneProxyNodeQuery(twq), "* : lit*"); }
@Test public void testPrefixQuery() throws Exception { ConciseKeywordQueryParser parser = new ConciseKeywordQueryParser(); parser.setAttribute("aaa"); NodePrefixQuery q = new NodePrefixQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "aaa:lit")); q.setDatatype("http://www.w3.org/2001/XMLSchema#string"); assertEquals(q, parser.parse("lit*", SirenTestCase.DEFAULT_TEST_FIELD)); // with no attribute defined parser = new ConciseKeywordQueryParser(); q = new NodePrefixQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "lit")); q.setDatatype("http://www.w3.org/2001/XMLSchema#string"); assertEquals(q, parser.parse("lit*", SirenTestCase.DEFAULT_TEST_FIELD)); }
assertEquals(0, searcher.search(query, 10).totalHits); NodePrefixQuery prfxNoSuch = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "noSuch")); SpanQuery spanPrfxNoSuch = new MultiTermSpanQuery<NodePrefixQuery>(prfxNoSuch);
assertEquals(1, searcher.search(query, 10).totalHits); NodePrefixQuery prfxNoSuch = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "noSuch")); SpanQuery spanPrfxNoSuch = new MultiTermSpanQuery<NodePrefixQuery>(prfxNoSuch); notNear = new NotSpanQuery(term, spanPrfxNoSuch, 1, 1);
assertEquals(1, searcher.search(query, 10).totalHits); NodePrefixQuery prfxNoSuch = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "noSuch")); SpanQuery spanPrfxNoSuch = new MultiTermSpanQuery<NodePrefixQuery>(prfxNoSuch); near = new OrSpanQuery(new SpanQuery[] { term, spanPrfxNoSuch });
assertTrue(wq.getTermsEnum(terms) instanceof PrefixTermsEnum); final MultiNodeTermQuery expected = new NodePrefixQuery(new Term(DEFAULT_TEST_FIELD, "prefix")); wq.setRewriteMethod(MultiNodeTermQuery.SCORING_BOOLEAN_QUERY_REWRITE); wq.setBoost(0.1F);