use of org.exist.xquery.XQuery in project exist by eXist-db.
the class IndexerTest3 method store_and_retrieve_suppress_type.
private String store_and_retrieve_suppress_type(final String type, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
store_suppress_type(type, typeXml);
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final StringWriter out = new StringWriter()) {
final XQuery xquery = pool.getXQueryService();
final Sequence result = xquery.execute(broker, typeXquery, null);
final Properties props = new Properties();
props.setProperty(OutputKeys.INDENT, "no");
final SAXSerializer serializer = new SAXSerializer(out, props);
serializer.startDocument();
for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
next.toSAX(broker, serializer, props);
}
serializer.endDocument();
return out.toString();
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class LuceneMatchListenerTest method inlineMatchNodes_whenIndenting.
@Test
public void inlineMatchNodes_whenIndenting() throws EXistException, PermissionDeniedException, XPathException, SAXException, CollectionConfigurationException, LockException, IOException {
configureAndStore(CONF5, XML2);
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
final String query = "declare namespace tei=\"http://www.tei-c.org/ns/1.0\";" + "//tei:p[.//tei:w[ft:query(., <query><bool><term>дознајем</term></bool></query>)]] ! util:expand(.)";
final Sequence seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
final String result = queryResult2String(broker, seq, true);
final String expected = "<p xmlns=\"http://www.tei-c.org/ns/1.0\">\n" + " <s type=\"combo\">\n" + " <w lemma=\"из\">из</w>\n" + " <w>новина</w>\n" + " <w lemma=\"и\">и</w>\n" + " <w lemma=\"од\">од</w>\n" + " <lb/>\n" + " <pb n=\"32\"/>\n" + " <w>других</w>\n" + " <w lemma=\"човек\">људи</w>\n" + " <w>" + MATCH_START + "дознајем" + MATCH_END + "</w>, <w xml:id=\"VSK.P13.t1.p4.w205\" lemma=\"ма\">ма</w>\n" + " <w>се</w>\n" + " <w lemma=\"не\">не</w>\n" + " <w>прорезује</w>\n" + " <w>право</w>\n" + " <w lemma=\"по\">по</w>\n" + " <w>имућству</w>, <w xml:id=\"VSK.P13.t1.p4.w219\" lemma=\"те\">те</w>\n" + " <w>се</w>\n" + " <w>на</w>\n" + " <w lemma=\"то\">то</w>\n" + " <w>видим</w>\n" + " <w>многи</w>\n" + " <w>љуте</w>.</s>\n" + "</p>";
XMLAssert.assertEquals(expected, result);
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class LuceneMatchListenerTest method matchInAncestor.
@Test
public void matchInAncestor() throws EXistException, PermissionDeniedException, XPathException, SAXException, IOException, XpathException, LockException, CollectionConfigurationException {
configureAndStore(CONF1, XML);
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
Sequence seq = xquery.execute(broker, "//para[ft:query(., 'mixed')]/hi", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
String result = queryResult2String(broker, seq);
XMLAssert.assertXpathEvaluatesTo("1", "count(//exist:match)", result);
seq = xquery.execute(broker, "//para[ft:query(., 'nested')]/note", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq);
XMLAssert.assertXpathEvaluatesTo("1", "count(//hi/exist:match)", result);
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class SerializeAttrMatchesTest method expandAttr.
@Test
public void expandAttr() throws CollectionConfigurationException, LockException, IOException, SAXException, PermissionDeniedException, EXistException, XPathException {
configureAndStore(COLLECTION_CONFIG, XML, "test1.xml");
// query and expand
final String query = "for $hit in collection(\"" + TestConstants.TEST_COLLECTION_URI.toString() + "\")//w[ft:query(@lemma, <query><regex>књиг.*</regex></query>)]\n" + "return util:expand($hit, \"highlight-matches=both\")";
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = pool.getXQueryService();
final Sequence seq = xquery.execute(broker, query, null);
assertEquals(1, seq.getItemCount());
final Item item = seq.itemAt(0);
assertTrue(item instanceof ElementImpl);
assertEquals("lemma", ((ElementImpl) item).getAttribute("exist:matches"));
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class LuceneIndexTest method MultiTermQueryRewriteMethod.
@Test
public void MultiTermQueryRewriteMethod() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException, XPathException {
configureAndStore(COLLECTION_CONFIG8, XML9, "test.xml");
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
Sequence seq = xquery.execute(broker, "declare namespace tei=\"http://www.tei-c.org/ns/1.0\";" + " for $expr in (\"au*\", \"ha*\", \"ma*\", \"za*\", \"ya*\", \"ra*\", \"qa*\")" + " let $query := <query><wildcard>{$expr}</wildcard></query>" + " return for $hit in //tei:p[ft:query(., $query)]" + " return util:expand($hit)//exist:match", null);
assertNotNull(seq);
assertEquals(10, seq.getItemCount());
assertEquals("aus", seq.itemAt(0).getStringValue());
seq = xquery.execute(broker, "declare namespace tei=\"http://www.tei-c.org/ns/1.0\";" + " for $expr in (\"ha*\", \"ma*\")" + " let $query := <query><wildcard>{$expr}</wildcard></query>" + " return for $hit in //tei:p[ft:query(., $query)]" + " return util:expand($hit)//exist:match", null);
assertNotNull(seq);
assertEquals(2, seq.getItemCount());
assertEquals("haus", seq.itemAt(0).getStringValue());
}
}
Aggregations