public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException { Sequence querySeq = getArgument(1).eval(contextSequence); if (querySeq.isEmpty()) { return Sequence.EMPTY_SEQUENCE; } String query = querySeq.itemAt(0).getStringValue(); String[] terms = getSearchTerms(query); NodeSet hits[] = new NodeSet[terms.length]; NodeSet contextSet = contextSequence.toNodeSet(); for (int k = 0; k < terms.length; k++) { hits[k] = context .getBroker() .getTextEngine() .getNodesContaining( context, contextSet.getDocumentSet(), null, NodeSet.DESCENDANT, null, terms[k], DBBroker.MATCH_EXACT); hits[k] = getArgument(0).eval(hits[k]).toNodeSet(); } NodeSet result = hits[0]; for (int k = 1; k < hits.length; k++) { if (hits[k] != null) result = result.deepIntersection(hits[k]); } if (LOG.isDebugEnabled()) LOG.debug("FOUND: " + result.getLength()); return result; }
@Test public void selectAncestorDescendant_2() throws XPathException, SAXException, PermissionDeniedException { Sequence outerSet = executeQuery(broker, "//SCENE/TITLE[fn:contains(., 'closet')]/ancestor::SCENE", 1, null); NodeSet result = ((AbstractNodeSet) outerSet) .selectAncestorDescendant(outerSet.toNodeSet(), NodeSet.DESCENDANT, true, -1, true); assertEquals(1, result.getLength()); }
@Test public void childSelector() throws XPathException { NodeSelector selector = new ChildSelector(seqSpeech.toNodeSet(), -1); NameTest test = new NameTest(Type.ELEMENT, new QName("LINE", "")); NodeSet set = broker .getStructuralIndex() .findElementsByTagName( ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector); assertEquals(9492, set.getLength()); }
@Test public void ancestorSelector() throws XPathException { NodeSelector selector = new AncestorSelector(seqSpeech.toNodeSet(), -1, false, true); NameTest test = new NameTest(Type.ELEMENT, new QName("ACT", "")); NodeSet set = broker .getStructuralIndex() .findElementsByTagName( ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector); assertEquals(15, set.getLength()); }
@Test public void descendantOrSelfSelector() throws XPathException { NodeSelector selector = new DescendantOrSelfSelector(seqSpeech.toNodeSet(), -1); NameTest test = new NameTest(Type.ELEMENT, new QName("SPEECH", "")); NodeSet set = broker .getStructuralIndex() .findElementsByTagName( ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector); assertEquals(2628, set.getLength()); }
@Test public void extArrayNodeSet_selectParentChild_3() throws XPathException, SAXException, PermissionDeniedException { Sequence nestedSet = executeQuery(broker, "//section[@n = ('1.1', '1.1.1', '1.2')]", 3, null); NameTest test = new NameTest(Type.ELEMENT, new QName("para", "")); NodeSet children = broker .getStructuralIndex() .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null); NodeSet result = children.selectParentChild(nestedSet.toNodeSet(), NodeSet.DESCENDANT); assertEquals(4, result.getLength()); }
@Test public void selectAncestors() throws XPathException, SAXException, PermissionDeniedException { NameTest test = new NameTest(Type.ELEMENT, new QName("SCENE", "")); NodeSet scenes = broker .getStructuralIndex() .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null); Sequence largeSet = executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH", 187, null); NodeSet result = ((AbstractNodeSet) scenes).selectAncestors(largeSet.toNodeSet(), false, -1); assertEquals(49, result.getLength()); }
@Test public void descendantSelector() throws XPathException, SAXException, PermissionDeniedException { Sequence seq = executeQuery(broker, "//SCENE", 72, null); NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", "")); NodeSelector selector = new DescendantSelector(seq.toNodeSet(), -1); NodeSet set = broker .getStructuralIndex() .findElementsByTagName( ElementValue.ELEMENT, seq.getDocumentSet(), test.getName(), selector); assertEquals(2639, set.getLength()); }
@Test public void selectParentChild_2() throws XPathException, SAXException, PermissionDeniedException { NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", "")); NodeSet speakers = broker .getStructuralIndex() .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null); Sequence largeSet = executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH", 187, null); NodeSet result = NodeSetHelper.selectParentChild(speakers, largeSet.toNodeSet(), NodeSet.DESCENDANT, -1); assertEquals(187, result.getLength()); }
@Test public void selectAncestorDescendant() throws XPathException, SAXException, PermissionDeniedException { NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", "")); NodeSet speakers = broker .getStructuralIndex() .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null); Sequence outerSet = executeQuery(broker, "//SCENE/TITLE[fn:contains(., 'closet')]/ancestor::SCENE", 1, null); NodeSet result = speakers.selectAncestorDescendant( outerSet.toNodeSet(), NodeSet.DESCENDANT, false, -1, true); assertEquals(56, result.getLength()); }
@Test public void selectParentChild() throws XPathException, SAXException, PermissionDeniedException { NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", "")); NodeSet speakers = broker .getStructuralIndex() .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null); Sequence smallSet = executeQuery( broker, "//SPEECH/LINE[fn:contains(., 'perturbed spirit')]/ancestor::SPEECH", 1, null); NodeSet result = NodeSetHelper.selectParentChild(speakers, smallSet.toNodeSet(), NodeSet.DESCENDANT, -1); assertEquals(1, result.getLength()); String value = serialize(broker, result.itemAt(0)); assertEquals(value, "<SPEAKER>HAMLET</SPEAKER>"); }