Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 19 files changed
  • 0 commit comments
  • 2 contributors
View
2 conf.xml.tmpl
@@ -421,7 +421,7 @@
this index in the database core. These will be removed
once the redesign has been completed.
-->
- <module id="ft-legacy-index" class="org.exist.fulltext.FTIndex"/>
+ <!--module id="ft-legacy-index" class="org.exist.fulltext.FTIndex"/-->
<!--
The following module is not really an index (though it sits
View
4 test/src/org/exist/LocalTestSuite.java
@@ -1,7 +1,6 @@
package org.exist;
import org.exist.collections.triggers.AllTriggerTests;
-import org.exist.fulltext.AllFulltextTests;
import org.exist.xmldb.XmldbLocalTests;
import org.exist.xquery.AllXqueryTests;
import org.exist.xquery.OptimizerTest;
@@ -17,8 +16,7 @@
// AllXupdateTests.class,
AllXqueryTests.class,
OptimizerTest.class,
- AllTriggerTests.class,
- AllFulltextTests.class
+ AllTriggerTests.class
})
public class LocalTestSuite {
}
View
16 test/src/org/exist/fulltext/AllFulltextTests.java
@@ -1,16 +0,0 @@
-package org.exist.fulltext;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- FTIndexTest.class,
- FtQueryTest.class,
- FTMatchListenerTest.class
-})
-public class AllFulltextTests {
- //TODO: rewrite to use others indexes (FT will be removed)
-}
View
927 test/src/org/exist/fulltext/FTIndexTest.java
@@ -1,927 +0,0 @@
-package org.exist.fulltext;
-
-import org.exist.TestUtils;
-import org.exist.collections.Collection;
-import org.exist.collections.CollectionConfigurationManager;
-import org.exist.collections.IndexInfo;
-import org.exist.dom.DefaultDocumentSet;
-import org.exist.dom.DocumentSet;
-import org.exist.dom.MutableDocumentSet;
-import org.exist.dom.QName;
-import org.exist.security.PermissionDeniedException;
-import org.exist.security.xacml.AccessContext;
-import org.exist.storage.BrokerPool;
-import org.exist.storage.DBBroker;
-import org.exist.storage.ElementValue;
-import org.exist.storage.txn.TransactionManager;
-import org.exist.storage.txn.Txn;
-import org.exist.test.TestConstants;
-import org.exist.util.Configuration;
-import org.exist.util.ConfigurationHelper;
-import org.exist.util.Occurrences;
-import org.exist.xmldb.XmldbURI;
-import org.exist.xquery.XQuery;
-import org.exist.xquery.value.Sequence;
-import org.exist.xupdate.Modification;
-import org.exist.xupdate.XUpdateProcessor;
-import org.junit.*;
-import static org.junit.Assert.*;
-import org.xml.sax.InputSource;
-
-import java.io.File;
-import java.io.StringReader;
-
-/**
- * Low-level tests for fulltext index configuration and index updates.
- */
-public class FTIndexTest {
-
- public final static String XML =
- "<content>" +
- "<figure>" +
- "<title>Location of equiment items on aircraft</title>" +
- "<img src='foo.jpg'/>" +
- "<img src='baz.jpg'/>" +
- "</figure>" +
- "<figure>" +
- "<title>Hydraulic Power<b>System</b></title>" +
- "<p>paragraphs with <span>mix</span><span>ed</span> content are <span>danger</span>ous.</p>" +
- "</figure>" +
- "</content>";
-
- private static String XML1 =
- "<test>" +
- " <item id='1' attr='attribute'><description>Chair</description></item>" +
- " <item id='2'><description>Table</description><price>892.25</price></item>" +
- " <item id='3'><description>Cabinet</description><price>1525.00</price></item>" +
- "</test>";
-
- private static String COLLECTION_CONFIG1 =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\">" +
- " <include path=\"/content/figure/title\"/>" +
- " <create qname=\"p\" content=\"mixed\"/>" +
- " <create qname=\"content\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
-
- private static String COLLECTION_CONFIG2 =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\">" +
- " <create qname=\"item\"/>" +
- " <create qname=\"description\"/>" +
- " <create qname=\"price\"/>" +
- " <create qname=\"@attr\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
-
- private static String COLLECTION_CONFIG3 =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\">" +
- " <include path=\"/content/figure/title\" content=\"mixed\"/>" +
- " <include path=\"/content//p\" content=\"mixed\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
-
- private static String XUPDATE_START =
- "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">";
-
- private static String XUPDATE_END =
- "</xu:modifications>";
-
- private static BrokerPool pool;
- private static Collection root;
- private static final QName[] QNDESC = new QName[]{ new QName("description", "", "") };
- private static final QName[] QNPRICE = new QName[]{ new QName("price", "", "") };
- private static final QName[] QNITEM = new QName[]{ new QName("item", "", "") };
-
- @Test
- public void mixedIndexes() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG3, XML, "mixedIndexes.xml");
- DBBroker broker = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
-
- Occurrences[] occur = checkIndex(docs, broker, null, "hydraulic", 1);
- assertEquals("hydraulic", occur[0].getTerm());
-
- checkIndex(docs, broker, null, "system", 0);
- occur = checkIndex(docs, broker, null, "powersystem", 1);
- assertEquals("powersystem", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, null, "mix", 1);
- assertEquals("mixed", occur[0].getTerm());
- checkIndex(docs, broker, null, "ed", 0);
- occur = checkIndex(docs, broker, null, "mixed", 1);
- assertEquals("mixed", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, null, "danger", 1);
- assertEquals("dangerous", occur[0].getTerm());
- occur = checkIndex(docs, broker, null, "dangerous", 1);
- assertEquals("dangerous", occur[0].getTerm());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- @Test
- public void mixedQNameIndexes() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG1, XML, "mixedIndexes.xml");
- DBBroker broker = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
-
- Occurrences[] occur = checkIndex(docs, broker, null, "aircraft", 1);
- assertEquals("aircraft", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, null, "system", 1);
- assertEquals("system", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, null, "power", 1);
- assertEquals("power", occur[0].getTerm());
-
- QName qn[] = { new QName("p", "", "") };
- occur = checkIndex(docs, broker, qn, "mixed", 1);
- assertEquals("mixed", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, qn, "dangerous", 1);
- assertEquals("dangerous", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, qn, "content", 1);
- assertEquals("content", occur[0].getTerm());
-
- qn[0] = new QName("content", "", "");
- occur = checkIndex(docs, broker, qn, "aircraft", 1);
- assertEquals("aircraft", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, qn, "hydraulic", 1);
- assertEquals("hydraulic", occur[0].getTerm());
-
- // not a mixed-content index
- checkIndex(docs, broker, qn, "dangerous", 0);
- occur = checkIndex(docs, broker, qn, "danger", 1);
- assertEquals("danger", occur[0].getTerm());
-
- occur = checkIndex(docs, broker, qn, "power", 1);
- assertEquals("power", occur[0].getTerm());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- @Test
- public void dropDocument() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG1, XML, "dropDocument.xml");
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
- transact = pool.getTransactionManager();
- assertNotNull(transact);
- transaction = transact.beginTransaction();
- assertNotNull(transaction);
-
- System.out.println("Removing document dropDocument.xml");
- root.removeXMLResource(transaction, broker, XmldbURI.create("dropDocument.xml"));
- transact.commit(transaction);
-
- checkIndex(docs, broker, null, null, 0);
-
- QName qn[] = { new QName("p", "", "") };
- checkIndex(docs, broker, qn, null, 0);
-
- qn[0] = new QName("content", "", "");
- checkIndex(docs, broker, qn, null, 0);
-
- checkIndex(docs, broker, null, null, 0);
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- @Test
- public void reindex() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG1, XML, "dropDocument.xml");
- DBBroker broker = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
-
- broker.reindexCollection(TestConstants.TEST_COLLECTION_URI);
-
- Occurrences[] occur = broker.getTextEngine().scanIndexTerms(docs, docs.docsToNodeSet(), "o", "ox");
- printOccurrences("o, ox", occur);
- assertEquals(2, occur.length);
- assertEquals("of", occur[0].getTerm());
- assertEquals("on", occur[1].getTerm());
-
- occur = checkIndex(docs, broker, null, "power", 1);
- assertEquals("power", occur[0].getTerm());
-
- QName qn[] = { new QName("p", "", "") };
- checkIndex(docs, broker, qn, "mixed", 1);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- /**
- * Remove nodes from different levels of the tree and check if the index is
- * correctly updated.
- */
- @Test
- public void xupdateRemove() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG2, XML1, "xupdate.xml");
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- transact = pool.getTransactionManager();
- transaction = transact.beginTransaction();
-
- Occurrences occur[] = checkIndex(docs, broker, QNDESC, "chair", 1);
- assertEquals("chair", occur[0].getTerm());
- checkIndex(docs, broker, QNITEM, null, 5);
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//item[description &= 'chair']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- seq = xquery.execute("//item[@id='2']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
-
- XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
- assertNotNull(proc);
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- String xupdate =
- XUPDATE_START +
- " <xu:remove select=\"//item[@id='2']/price\"/>" +
- XUPDATE_END;
- Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNPRICE, null, 1);
- checkIndex(docs, broker, QNITEM, null, 4);
- checkIndex(docs, broker, QNPRICE, "892", 0);
- checkIndex(docs, broker, QNITEM, "892", 0);
- Occurrences o[] = checkIndex(docs, broker, QNDESC, "table", 1);
- assertEquals("table", o[0].getTerm());
- o = checkIndex(docs, broker, QNDESC, "cabinet", 1);
- assertEquals("cabinet", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "table", 1);
- assertEquals("table", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "cabinet", 1);
- assertEquals("cabinet", o[0].getTerm());
-
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:remove select=\"//item[@id='3']/description/text()\"/>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNDESC, null, 2);
- checkIndex(docs, broker, QNITEM, null, 3);
- checkIndex(docs, broker, QNDESC, "cabinet", 0);
- checkIndex(docs, broker, QNITEM, "cabinet", 0);
- o = checkIndex(docs, broker, QNPRICE, "1525.00", 1);
- assertEquals("1525.00", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "1525.00", 1);
- assertEquals("1525.00", o[0].getTerm());
-
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:remove select=\"//item[@id='1']/@attr\"/>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- QName qnattr[] = { new QName("attr", "", "") };
- qnattr[0].setNameType(ElementValue.ATTRIBUTE);
- checkIndex(docs, broker, qnattr, null, 0);
-
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:remove select=\"//item[@id='1']\"/>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- o = checkIndex(docs, broker, QNDESC, null, 1);
- assertEquals("table", o[0].getTerm());
- checkIndex(docs, broker, QNDESC, "chair", 0);
- checkIndex(docs, broker, QNITEM, null, 2);
- assertEquals("table", o[0].getTerm());
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- if (pool != null) {
- pool.release(broker);
- }
- }
- }
-
- /**
- * Remove nodes from different levels of the tree and check if the index is
- * correctly updated.
- */
- @Test
- public void xupdateInsert() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG2, XML1, "xupdate.xml");
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- transact = pool.getTransactionManager();
- transaction = transact.beginTransaction();
-
- Occurrences occur[] = checkIndex(docs, broker, QNDESC, "chair", 1);
- assertEquals("chair", occur[0].getTerm());
- checkIndex(docs, broker, QNITEM, null, 5);
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//item[description &= 'chair']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
-
- // Append to root node
- XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
- assertNotNull(proc);
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- String xupdate =
- XUPDATE_START +
- " <xu:append select=\"/test\">" +
- " <item id='4'><description>Armchair</description><price>340</price></item>" +
- " </xu:append>" +
- XUPDATE_END;
- Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNPRICE, null, 3);
- checkIndex(docs, broker, QNDESC, null, 4);
- checkIndex(docs, broker, QNITEM, null, 7);
- Occurrences o[] = checkIndex(docs, broker, QNPRICE, "340", 1);
- assertEquals("340", o[0].getTerm());
- o = checkIndex(docs, broker, QNDESC, "armchair", 1);
- assertEquals("armchair", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "340", 1);
- assertEquals("340", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "armchair", 1);
- assertEquals("armchair", o[0].getTerm());
-
- // Insert before top element
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:insert-before select=\"//item[@id = '1']\">" +
- " <item id='0'><description>Wheelchair</description><price>1230</price></item>" +
- " </xu:insert-before>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNPRICE, null, 4);
- checkIndex(docs, broker, QNDESC, null, 5);
- checkIndex(docs, broker, QNITEM, null, 9);
- o = checkIndex(docs, broker, QNPRICE, "1230", 1);
- assertEquals("1230", o[0].getTerm());
- o = checkIndex(docs, broker, QNDESC, "wheelchair", 1);
- assertEquals("wheelchair", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "1230", 1);
- assertEquals("1230", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "wheelchair", 1);
- assertEquals("wheelchair", o[0].getTerm());
-
- // Insert after element
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:insert-after select=\"//item[@id = '1']\">" +
- " <item id='1.1'><description>refrigerator</description><price>777</price></item>" +
- " </xu:insert-after>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNPRICE, null, 5);
- checkIndex(docs, broker, QNDESC, null, 6);
- checkIndex(docs, broker, QNITEM, null, 11);
- o = checkIndex(docs, broker, QNPRICE, "777", 1);
- assertEquals("777", o[0].getTerm());
- o = checkIndex(docs, broker, QNDESC, "refrigerator", 1);
- assertEquals("refrigerator", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "777", 1);
- assertEquals("777", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "refrigerator", 1);
- assertEquals("refrigerator", o[0].getTerm());
-
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:insert-after select=\"//item[@id = '1']/description\">" +
- " <price>999</price>" +
- " </xu:insert-after>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNPRICE, null, 6);
- checkIndex(docs, broker, QNITEM, null, 12);
- o = checkIndex(docs, broker, QNPRICE, "999", 1);
- assertEquals("999", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "999", 1);
- assertEquals("999", o[0].getTerm());
-
- // Insert before nested element
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:insert-before select=\"//item[@id = '1']/description\">" +
- " <price>888</price>" +
- " </xu:insert-before>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNPRICE, null, 7);
- checkIndex(docs, broker, QNITEM, null, 13);
- o = checkIndex(docs, broker, QNPRICE, "999", 1);
- assertEquals("999", o[0].getTerm());
- o = checkIndex(docs, broker, QNPRICE, "888", 1);
- assertEquals("888", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "999", 1);
- assertEquals("999", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "888", 1);
- assertEquals("888", o[0].getTerm());
-
- // Overwrite attribute
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:append select=\"//item[@id = '1']\">" +
- " <xu:attribute name=\"attr\">abc</xu:attribute>" +
- " </xu:append>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- QName qnattr[] = { new QName("attr", "", "") };
- qnattr[0].setNameType(ElementValue.ATTRIBUTE);
- o = checkIndex(docs, broker, qnattr, null, 1);
- assertEquals("abc", o[0].getTerm());
- checkIndex(docs, broker, qnattr, "attribute", 0);
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- if (pool != null) {
- pool.release(broker);
- }
- }
- }
-
- @Test
- public void xupdateUpdate() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG2, XML1, "xupdate.xml");
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- transact = pool.getTransactionManager();
- transaction = transact.beginTransaction();
-
- Occurrences occur[] = checkIndex(docs, broker, QNDESC, "chair", 1);
- assertEquals("chair", occur[0].getTerm());
- checkIndex(docs, broker, QNITEM, null, 5);
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//item[description &= 'chair']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
-
- // Update element content
- XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
- assertNotNull(proc);
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- String xupdate =
- XUPDATE_START +
- " <xu:update select=\"//item[@id = '1']/description\">wardrobe</xu:update>" +
- XUPDATE_END;
- Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNDESC, null, 3);
- checkIndex(docs, broker, QNITEM, null, 5);
- checkIndex(docs, broker, QNDESC, "chair", 0);
- checkIndex(docs, broker, QNITEM, "chair", 0);
- Occurrences o[] = checkIndex(docs, broker, QNDESC, "wardrobe", 1);
- assertEquals("wardrobe", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "wardrobe", 1);
- assertEquals("wardrobe", o[0].getTerm());
-
- // Update text node
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:update select=\"//item[@id = '1']/description/text()\">Wheelchair</xu:update>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNDESC, null, 3);
- checkIndex(docs, broker, QNITEM, null, 5);
- checkIndex(docs, broker, QNDESC, "wardrobe", 0);
- checkIndex(docs, broker, QNITEM, "wardrobe", 0);
- o = checkIndex(docs, broker, QNDESC, "wheelchair", 1);
- assertEquals("wheelchair", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "wheelchair", 1);
- assertEquals("wheelchair", o[0].getTerm());
-
- // Update attribute value
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:update select=\"//item[@id = '1']/@attr\">abc</xu:update>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- QName qnattr[] = { new QName("attr", "", "") };
- qnattr[0].setNameType(ElementValue.ATTRIBUTE);
- o = checkIndex(docs, broker, qnattr, null, 1);
- assertEquals("abc", o[0].getTerm());
- checkIndex(docs, broker, qnattr, "attribute", 0);
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- if (pool != null) {
- pool.release(broker);
- }
- }
- }
-
- @Test
- public void xupdateReplace() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG2, XML1, "xupdate.xml");
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- transact = pool.getTransactionManager();
- transaction = transact.beginTransaction();
-
- Occurrences occur[] = checkIndex(docs, broker, QNDESC, "chair", 1);
- assertEquals("chair", occur[0].getTerm());
- checkIndex(docs, broker, QNITEM, null, 5);
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//item[description &= 'chair']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
-
- XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
- assertNotNull(proc);
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- String xupdate =
- XUPDATE_START +
- " <xu:replace select=\"//item[@id = '1']\">" +
- " <item id='4'><description>Wheelchair</description><price>809.50</price></item>" +
- " </xu:replace>" +
- XUPDATE_END;
- Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNDESC, null, 3);
- checkIndex(docs, broker, QNPRICE, null, 3);
- checkIndex(docs, broker, QNITEM, null, 6);
- checkIndex(docs, broker, QNDESC, "chair", 0);
- checkIndex(docs, broker, QNITEM, "chair", 0);
- Occurrences o[] = checkIndex(docs, broker, QNDESC, "wheelchair", 1);
- assertEquals("wheelchair", o[0].getTerm());
- o = checkIndex(docs, broker, QNPRICE, "809.50", 1);
- assertEquals("809.50", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "wheelchair", 1);
- assertEquals("wheelchair", o[0].getTerm());
- o = checkIndex(docs, broker, QNITEM, "809.50", 1);
- assertEquals("809.50", o[0].getTerm());
-
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- xupdate =
- XUPDATE_START +
- " <xu:replace select=\"//item[@id = '4']/description\">" +
- " <description>Armchair</description>" +
- " </xu:replace>" +
- XUPDATE_END;
- modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNDESC, null, 3);
- checkIndex(docs, broker, QNITEM, null, 6);
- checkIndex(docs, broker, QNDESC, "wheelchair", 0);
- o = checkIndex(docs, broker, QNDESC, "armchair", 1);
- assertEquals("armchair", o[0].getTerm());
- checkIndex(docs, broker, QNITEM, "wheelchair", 0);
- o = checkIndex(docs, broker, QNITEM, "armchair", 1);
- assertEquals("armchair", o[0].getTerm());
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- if (pool != null) {
- pool.release(broker);
- }
- }
- }
-
- @Test
- public void xupdateRename() {
- DocumentSet docs = configureAndStore(COLLECTION_CONFIG2, XML1, "xupdate.xml");
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- transact = pool.getTransactionManager();
- transaction = transact.beginTransaction();
-
- Occurrences occur[] = checkIndex(docs, broker, QNDESC, "chair", 1);
- assertEquals("chair", occur[0].getTerm());
- checkIndex(docs, broker, QNITEM, null, 5);
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//item[description &= 'chair']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
-
- XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
- assertNotNull(proc);
- proc.setBroker(broker);
- proc.setDocumentSet(docs);
- String xupdate =
- XUPDATE_START +
- " <xu:rename select=\"//item[@id='2']\">renamed</xu:rename>" +
- XUPDATE_END;
- Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
- assertNotNull(modifications);
- modifications[0].process(transaction);
- proc.reset();
-
- checkIndex(docs, broker, QNDESC, null, 3);
- checkIndex(docs, broker, QNPRICE, null, 2);
- checkIndex(docs, broker, QNITEM, null, 3);
- Occurrences o[] = checkIndex(docs, broker, QNDESC, "table", 1);
- assertEquals("table", o[0].getTerm());
- checkIndex(docs, broker, QNITEM, "table", 0);
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- if (pool != null) {
- pool.release(broker);
- }
- }
- }
-
- private Occurrences[] checkIndex(DocumentSet docs, DBBroker broker, QName[] qn, String term, int expected) throws PermissionDeniedException {
- Occurrences[] occur;
- if (qn == null)
- occur = broker.getTextEngine().scanIndexTerms(docs, docs.docsToNodeSet(), term, null);
- else
- occur = broker.getTextEngine().scanIndexTerms(docs, docs.docsToNodeSet(), qn, term, null);
- printOccurrences(term, occur);
- assertEquals(expected, occur.length);
- return occur;
- }
-
- private void printOccurrences(String msg, Occurrences[] occur) {
- StringBuilder buf = new StringBuilder();
- if (msg != null)
- buf.append(msg).append(": ");
- for (int i = 0; i < occur.length; i++) {
- Occurrences occurrences = occur[i];
- if (i > 0)
- buf.append(", ");
- buf.append(occurrences.getTerm()).append(":\t").append(occurrences.getOccurrences());
- }
- System.out.println(buf.toString());
- }
-
- private DocumentSet configureAndStore(String configuration, String data, String docName) {
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- MutableDocumentSet docs = new DefaultDocumentSet();
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
- transact = pool.getTransactionManager();
- assertNotNull(transact);
- transaction = transact.beginTransaction();
- assertNotNull(transaction);
-
- if (configuration != null) {
- CollectionConfigurationManager mgr = pool.getConfigurationManager();
- mgr.addConfiguration(transaction, broker, root, configuration);
- }
-
- IndexInfo info = root.validateXMLResource(transaction, broker, XmldbURI.create(docName), data);
- assertNotNull(info);
- root.store(transaction, broker, info, data, false);
-
- docs.add(info.getDocument());
- transact.commit(transaction);
- } catch (Exception e) {
- e.printStackTrace();
- transact.abort(transaction);
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- return docs;
- }
-
- @Before
- public void setup() {
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
- transact = pool.getTransactionManager();
- assertNotNull(transact);
- transaction = transact.beginTransaction();
- assertNotNull(transaction);
- System.out.println("Transaction started ...");
-
- root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
- assertNotNull(root);
- broker.saveCollection(transaction, root);
-
- transact.commit(transaction);
- } catch (Exception e) {
- e.printStackTrace();
- transact.abort(transaction);
- fail(e.getMessage());
- } finally {
- if (pool != null)
- pool.release(broker);
- }
- }
-
- @After
- public void cleanup() {
- BrokerPool pool = null;
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- pool = BrokerPool.getInstance();
- assertNotNull(pool);
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
- transact = pool.getTransactionManager();
- assertNotNull(transact);
- transaction = transact.beginTransaction();
- assertNotNull(transaction);
-
- Collection config = broker.getOrCreateCollection(transaction,
- XmldbURI.create(XmldbURI.CONFIG_COLLECTION + "/db"));
- assertNotNull(config);
- broker.removeCollection(transaction, config);
-
- assertNotNull(root);
- broker.removeCollection(transaction, root);
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- if (pool != null) pool.release(broker);
- }
- }
-
- @BeforeClass
- public static void startDB() {
- try {
- File confFile = ConfigurationHelper.lookup("conf.xml");
- Configuration config = new Configuration(confFile.getAbsolutePath());
- BrokerPool.configure(1, 5, config);
- pool = BrokerPool.getInstance();
- assertNotNull(pool);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @AfterClass
- public static void stopDB() {
- TestUtils.cleanupDB();
- BrokerPool.stopAll(false);
- pool = null;
- root = null;
- }
-}
View
361 test/src/org/exist/fulltext/FTMatchListenerTest.java
@@ -1,361 +0,0 @@
-package org.exist.fulltext;
-
-import org.custommonkey.xmlunit.NamespaceContext;
-import org.custommonkey.xmlunit.SimpleNamespaceContext;
-import org.custommonkey.xmlunit.XMLAssert;
-import org.custommonkey.xmlunit.XMLUnit;
-import org.exist.TestUtils;
-import org.exist.collections.Collection;
-import org.exist.collections.CollectionConfigurationManager;
-import org.exist.collections.IndexInfo;
-import org.exist.security.xacml.AccessContext;
-import org.exist.storage.BrokerPool;
-import org.exist.storage.DBBroker;
-import org.exist.storage.serializers.EXistOutputKeys;
-import org.exist.storage.serializers.Serializer;
-import org.exist.storage.txn.TransactionManager;
-import org.exist.storage.txn.Txn;
-import org.exist.test.TestConstants;
-import org.exist.util.Configuration;
-import org.exist.util.ConfigurationHelper;
-import org.exist.xmldb.XmldbURI;
-import org.exist.xquery.XPathException;
-import org.exist.xquery.XQuery;
-import org.exist.xquery.value.NodeValue;
-import org.exist.xquery.value.Sequence;
-import org.junit.AfterClass;
-import static org.junit.Assert.*;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.xml.sax.SAXException;
-
-import javax.xml.transform.OutputKeys;
-import java.io.File;
-import java.util.HashMap;
-import java.util.Properties;
-
-public class FTMatchListenerTest {
-
- private static String XML =
- "<root>" +
- " <para>some paragraph with <hi>mixed</hi> content.</para>" +
- " <para>another paragraph with <note><hi>nested</hi> inner</note> elements.</para>" +
- " <para>a third paragraph with <term>term</term>.</para>" +
- " <para>double match double match</para>" +
- "</root>";
-
- private static String CONF1 =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\">" +
- " <include path=\"//para\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
-
- private static String CONF2 =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\">" +
- " <create qname=\"para\"/>" +
- " <create qname=\"term\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
-
- private static String MATCH_START = "<exist:match xmlns:exist=\"http://exist.sourceforge.net/NS/exist\">";
- private static String MATCH_END = "</exist:match>";
-
- private static BrokerPool pool;
-
- /**
- * Test match highlighting for index configured by path, e.g.
- * &lt;include path="//a/b"/&gt;.
- */
- @Test
- public void indexByPath() {
- DBBroker broker = null;
- try {
- configureAndStore(CONF1);
-
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//para[. &= 'mixed']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- String result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>some paragraph with <hi>" + MATCH_START + "mixed" +
- MATCH_END + "</hi> content.</para>", result);
-
- seq = xquery.execute("//para[hi &= 'mixed']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>some paragraph with <hi>" + MATCH_START + "mixed" +
- MATCH_END + "</hi> content.</para>", result);
-
- seq = xquery.execute("//para[. &= 'another']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>" + MATCH_START + "another" + MATCH_END + " paragraph with <note><hi>nested</hi> " +
- "inner</note> elements.</para>", result);
-
- seq = xquery.execute("//para[. &= 'nested inner']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>another paragraph with <note><hi>" + MATCH_START + "nested" +
- MATCH_END + "</hi> " + MATCH_START +
- "inner" + MATCH_END + "</note> elements.</para>", result);
-
- seq = xquery.execute("//para[. &= 'nested inner elements']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>another paragraph with <note><hi>" + MATCH_START + "nested" +
- MATCH_END + "</hi> " + MATCH_START +
- "inner" + MATCH_END + "</note> " + MATCH_START + "elements" + MATCH_END + ".</para>", result);
-
- seq = xquery.execute(
- "for $para in //para[. &= 'nested inner elements'] return\n" +
- " <hit>{$para}</hit>", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<hit><para>another paragraph with <note><hi>" + MATCH_START + "nested" +
- MATCH_END + "</hi> " + MATCH_START +
- "inner" + MATCH_END + "</note> " + MATCH_START + "elements" + MATCH_END + ".</para></hit>", result);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- @Test
- public void ancestorAxis() {
- DBBroker broker = null;
- try {
- configureAndStore(CONF1);
-
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//hi[. &= 'mixed']/parent::para", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- String result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertXpathEvaluatesTo("1", "count(//exist:match)", result);
-
- seq = xquery.execute("//hi[. &= 'mixed']/..", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertXpathEvaluatesTo("1", "count(//exist:match)", result);
-
- seq = xquery.execute("//hi[. &= 'nested']/ancestor::para", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
-
- seq = xquery.execute("//hi[. &= 'nested']/ancestor::*[2]", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertXpathEvaluatesTo("1", "count(//exist:match)", result);
-
- String query =
- "let $results := for $m in //para[. &= 'mixed']/hi order by $m return $m/parent::para " +
- "return $results";
- seq = xquery.execute(query, null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertXpathEvaluatesTo("1", "count(//exist:match)", result);
-
- query =
- "let $results := for $m in //hi[. &= 'nested'] return $m/ancestor::para " +
- "return $results";
- seq = xquery.execute(query, null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertXpathEvaluatesTo("1", "count(//exist:match)", result);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- /**
- * Test match highlighting for index configured by QName, e.g.
- * &lt;create qname="a"/&gt;.
- */
- @Test
- public void indexByQName() {
- DBBroker broker = null;
- try {
- configureAndStore(CONF2);
-
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
-
- XQuery xquery = broker.getXQueryService();
- assertNotNull(xquery);
- Sequence seq = xquery.execute("//para[. &= 'mixed']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- String result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>some paragraph with <hi>" + MATCH_START + "mixed" +
- MATCH_END + "</hi> content.</para>", result);
-
- seq = xquery.execute("//para[. &= 'nested inner elements']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>another paragraph with <note><hi>" + MATCH_START + "nested" +
- MATCH_END + "</hi> " + MATCH_START +
- "inner" + MATCH_END + "</note> " + MATCH_START + "elements" + MATCH_END + ".</para>", result);
-
- seq = xquery.execute("//para[term &= 'term']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>a third paragraph with <term>" + MATCH_START + "term" + MATCH_END +
- "</term>.</para>", result);
-
- seq = xquery.execute("//para[. &= 'double match']", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<para>" + MATCH_START + "double" + MATCH_END + " " +
- MATCH_START + "match" + MATCH_END + " " + MATCH_START + "double" + MATCH_END + " " +
- MATCH_START + "match" + MATCH_END + "</para>", result);
-
- seq = xquery.execute(
- "for $para in //para[. &= 'double match'] return\n" +
- " <hit>{$para}</hit>", null, AccessContext.TEST);
- assertNotNull(seq);
- assertEquals(1, seq.getItemCount());
- result = queryResult2String(broker, seq);
- System.out.println("RESULT: " + result);
- XMLAssert.assertEquals("<hit><para>" + MATCH_START + "double" + MATCH_END + " " +
- MATCH_START + "match" + MATCH_END + " " + MATCH_START + "double" + MATCH_END + " " +
- MATCH_START + "match" + MATCH_END + "</para></hit>", result);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- @BeforeClass
- public static void startDB() {
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- File confFile = ConfigurationHelper.lookup("conf.xml");
- Configuration config = new Configuration(confFile.getAbsolutePath());
- BrokerPool.configure(1, 5, config);
- pool = BrokerPool.getInstance();
- assertNotNull(pool);
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
- transact = pool.getTransactionManager();
- assertNotNull(transact);
- transaction = transact.beginTransaction();
- assertNotNull(transaction);
- System.out.println("Transaction started ...");
-
- Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
- assertNotNull(root);
- broker.saveCollection(transaction, root);
-
- transact.commit(transaction);
- } catch (Exception e) {
- if (transact != null)
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- if (pool != null)
- pool.release(broker);
- }
- HashMap<String, String> m = new HashMap<String, String>();
- m.put("exist", "http://exist.sourceforge.net/NS/exist");
- NamespaceContext ctx = new SimpleNamespaceContext(m);
- XMLUnit.setXpathNamespaceContext(ctx);
- }
-
- @AfterClass
- public static void closeDB() {
- TestUtils.cleanupDB();
- BrokerPool.stopAll(false);
- pool = null;
- }
-
- private void configureAndStore(String config) {
- DBBroker broker = null;
- TransactionManager transact = null;
- Txn transaction = null;
- try {
- broker = pool.get(pool.getSecurityManager().getSystemSubject());
- assertNotNull(broker);
- transact = pool.getTransactionManager();
- assertNotNull(transact);
- transaction = transact.beginTransaction();
- assertNotNull(transaction);
-
- Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
- assertNotNull(root);
- CollectionConfigurationManager mgr = pool.getConfigurationManager();
- mgr.addConfiguration(transaction, broker, root, config);
-
- IndexInfo info = root.validateXMLResource(transaction, broker, XmldbURI.create("test_matches.xml"), XML);
- assertNotNull(info);
- root.store(transaction, broker, info, XML, false);
-
- transact.commit(transaction);
- } catch (Exception e) {
- transact.abort(transaction);
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- pool.release(broker);
- }
- }
-
- private String queryResult2String(DBBroker broker, Sequence seq) throws SAXException, XPathException {
- Properties props = new Properties();
- props.setProperty(OutputKeys.INDENT, "no");
- props.setProperty(EXistOutputKeys.HIGHLIGHT_MATCHES, "elements");
- Serializer serializer = broker.getSerializer();
- serializer.reset();
- serializer.setProperties(props);
- return serializer.serialize((NodeValue) seq.itemAt(0));
- }
-}
View
647 test/src/org/exist/fulltext/FtQueryTest.java
@@ -1,647 +0,0 @@
-/*
- * eXist Open Source Native XML Database
- * Copyright (C) 2001-2007 The eXist Project
- * http://exist-db.org
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $Id$
- */
-package org.exist.fulltext;
-
-import java.io.File;
-
-import junit.textui.TestRunner;
-
-import org.custommonkey.xmlunit.XMLTestCase;
-import org.exist.EXistException;
-import org.exist.storage.BrokerPool;
-import org.exist.util.Configuration;
-import org.exist.util.DatabaseConfigurationException;
-import org.exist.xmldb.DatabaseInstanceManager;
-import org.exist.xmldb.IndexQueryService;
-import org.exist.xmldb.XQueryService;
-import org.exist.xmldb.XmldbURI;
-import org.exist.xquery.FunctionFactory;
-import org.xmldb.api.DatabaseManager;
-import org.xmldb.api.base.Collection;
-import org.xmldb.api.base.Database;
-import org.xmldb.api.base.Resource;
-import org.xmldb.api.base.ResourceIterator;
-import org.xmldb.api.base.ResourceSet;
-import org.xmldb.api.base.XMLDBException;
-import org.xmldb.api.modules.CollectionManagementService;
-import org.xmldb.api.modules.XMLResource;
-
-public class FtQueryTest extends XMLTestCase {
-
- private static String COLLECTION_CONFIG1 =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"all\">" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
-
- private final static String TEST_XML =
- "<test-doc>" +
- "<test-elem id=\"1\" attribute1=\"test some text\"/>" +
- "<test-elem id=\"2\" attribute2=\"test some text\"/>" +
- "<test-elem id=\"3\" attribute1=\"test some text\"/>" +
- "<test-elem id=\"4\" attribute3=\"test some text\"/>" +
- "</test-doc>";
-
- private final static String QNAME_XML =
- "<root>" +
- " <test>" +
- " <node id=\"1\">First node</node>" +
- " <node id=\"2\">Second node</node>" +
- " </test>" +
- "</root>";
-
- private final static String NESTED_XML =
- "<root>\n" +
- " <nested><s>un</s>even</nested>\n" +
- " <nested>un<s>suitable</s></nested>\n" +
- " <nested><s>in</s><s>ap</s><s>pro</s><s>pri</s><s>ate</s></nested>\n" +
- "</root>";
-
- private final static String MATCH_COUNT =
- "<doc> term term <level1>term term</level1><level1>term<level2>term</level2></level1></doc>";
-
- private final static String FILES[] = { "hamlet.xml", "macbeth.xml", "r_and_j.xml" };
- static File existDir;
- static {
- String existHome = System.getProperty("exist.home");
- existDir = existHome==null ? new File(".") : new File(existHome);
- }
- private final static File SHAKES_DIR = new File(existDir,"samples" + File.separator + "shakespeare");
- private final static File MODS_DIR = new File(existDir,"samples" + File.separator + "mods");
-
- private static final String TEST_COLLECTION_NAME = "testft";
- private static final String TEST_COLLECTION_PATH = XmldbURI.ROOT_COLLECTION + "/" + TEST_COLLECTION_NAME;
-
- private Database database;
- private Collection testCollection;
-
- public void testFtOperators() {
- try {
- System.out.println("----- testFtOperators -----");
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- ResourceSet result = service.query("//SPEECH[LINE &= 'love']");
- assertEquals(160, result.getSize());
- result = service.query("//SPEECH[LINE &= 'thou']");
- assertEquals(290, result.getSize());
- result = service.query("//SPEECH[LINE &= 'thou']");
- assertEquals(290, result.getSize());
- result = service.query("//SPEECH[LINE &= 'fenny snake']/LINE[1]");
- assertEquals(1, result.getSize());
- assertXMLEqual(result.getResource(0).getContent().toString(), "<LINE>Fillet of a fenny snake,</LINE>");
- //assertXMLEqual(result.getResource(0).getContent().toString(), "<LINE>Fillet of a <exist:match xmlns:exist='http://exist.sourceforge.net/NS/exist'>fenny</exist:match> <exist:match xmlns:exist='http://exist.sourceforge.net/NS/exist'>snake</exist:match>,</LINE>");
- result = service.query("//SPEECH[LINE &= 'god*']");
- assertEquals(79, result.getSize());
- result = service.query("//SPEECH[LINE &= 'god in heaven']");
- assertEquals(2, result.getSize());
- result = service.query("//SPEECH[SPEAKER &= 'Nurse']");
- assertEquals(90, result.getSize());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testFtMatchFunctions() {
- try {
- System.out.println("----- testFtOperators -----");
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- ResourceSet result = service.query("//SPEECH[text:match-all(LINE, 'love', 'w')]");
- assertEquals(160, result.getSize());
- result = service.query("//SPEECH[text:match-all(LINE, 'love')]");
- assertEquals(190, result.getSize());
- result = service.query("//SPEECH[text:match-all(LINE, 'love', 'w')]");
- assertEquals(160, result.getSize());
-
- result = service.query("//SPEECH[text:match-all(LINE, 'fenny', 'snake')]/LINE[1]");
- assertEquals(1, result.getSize());
- assertXMLEqual(result.getResource(0).getContent().toString(), "<LINE>Fillet of a fenny snake,</LINE>");
- //assertXMLEqual(result.getResource(0).getContent().toString(), "<LINE>Fillet of a <exist:match xmlns:exist='http://exist.sourceforge.net/NS/exist'>fenny</exist:match> <exist:match xmlns:exist='http://exist.sourceforge.net/NS/exist'>snake</exist:match>,</LINE>");
-
- result = service.query("//SPEECH[text:match-all(LINE, ('fenny', 'snake'))]/LINE[1]");
- assertEquals(1, result.getSize());
- assertXMLEqual(result.getResource(0).getContent().toString(), "<LINE>Fillet of a fenny snake,</LINE>");
- //assertXMLEqual(result.getResource(0).getContent().toString(), "<LINE>Fillet of a <exist:match xmlns:exist='http://exist.sourceforge.net/NS/exist'>fenny</exist:match> <exist:match xmlns:exist='http://exist.sourceforge.net/NS/exist'>snake</exist:match>,</LINE>");
- result = service.query("//SPEECH[text:match-all(LINE, 'god.*')]");
- assertEquals(79, result.getSize());
-
- result = service.query("//SPEECH[LINE &= 'god in heaven']");
- assertEquals(2, result.getSize());
- result = service.query("//SPEECH[SPEAKER &= 'Nurse']");
- assertEquals(90, result.getSize());
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testFtScan() {
- try {
- System.out.println("----- testFtScan -----");
- String queryBody =
- "declare namespace f=\'http://exist-db.org/xquery/test\';\n" +
- "import module namespace t=\'http://exist-db.org/xquery/text\';\n" +
- "\n" +
- "declare function f:term-callback($term as xs:string, $data as xs:int+)\n" +
- "as element()+ {\n" +
- " <item>\n" +
- " <term>{$term}</term>\n" +
- " <frequency>{$data[1]}</frequency>\n" +
- " </item>\n" +
- "};\n" +
- "\n";
-
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- String query = queryBody + "t:index-terms(collection('" + TEST_COLLECTION_PATH + "'), \'is\', util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
- ResourceSet result = service.query(query);
- assertEquals(6, result.getSize());
-
- query = queryBody + "t:index-terms(collection('" + TEST_COLLECTION_PATH + "')//LINE, \'is\', util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
- result = service.query(query);
- assertEquals(6, result.getSize());
- } catch (XMLDBException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testFtUpdate() {
- try {
- System.out.println("----- testFtUpdate -----");
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- service.query(
- "update insert <SPEAKER>First Witch</SPEAKER> preceding //SPEECH[LINE &= 'fenny snake']/SPEAKER"
- );
- ResourceSet result = service.query("//SPEECH[LINE &= 'fenny snake']/SPEAKER");
- assertEquals(2, result.getSize());
- result = service.query("//SPEECH[LINE &= 'fenny snake' and SPEAKER &= 'first']");
- assertEquals(1, result.getSize());
-
- service.query(
- "update delete //SPEECH[LINE &= 'fenny snake']/SPEAKER[2]"
- );
- result = service.query("//SPEECH[LINE &= 'fenny snake' and SPEAKER &= 'first']");
- assertEquals(1, result.getSize());
- } catch (XMLDBException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testFtConfiguration() {
- System.out.println("----- testFtConfiguration -----");
- try {
- // check attributes="false"
- String config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"all\" attributes=\"false\" alphanum=\"true\">" +
- " <include path=\"//test-elem/@attribute1\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
- IndexQueryService idxConf = (IndexQueryService)
- testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(config);
-
- XMLResource doc =
- (XMLResource) testCollection.createResource(
- "test-attributes.xml", "XMLResource");
- doc.setContent(TEST_XML);
- testCollection.storeResource(doc);
-
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- String query = "//test-elem[@* &= 'some text']";
- ResourceSet result = service.query(query);
- assertEquals(2, result.getSize());
-
- // check attributes="true"
- config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"all\" attributes=\"true\" alphanum=\"true\">" +
- " <exclude path=\"//test-elem/@attribute2\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
- idxConf.configureCollection(config);
- idxConf.reindexCollection();
-
- result = service.query(query);
- assertEquals(3, result.getSize());
- } catch(Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testMixedConfiguration() {
- System.out.println("----- testMixedConfiguration -----");
- try {
- String config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">\n" +
- " <index>\n" +
- " <fulltext default=\"all\" attributes=\"no\">\n" +
- " <include path=\"//nested\" content=\"mixed\"/>\n" +
- " </fulltext>\n" +
- " </index>\n" +
- "</collection>";
-
- IndexQueryService idxConf = (IndexQueryService)
- testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(config);
-
- XMLResource doc =
- (XMLResource) testCollection.createResource(
- "test-mixed.xml", "XMLResource");
- doc.setContent(NESTED_XML);
- testCollection.storeResource(doc);
-
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- String query = "//nested[. &= 'inappropriate']";
- ResourceSet result = service.query(query);
- assertEquals(1, result.getSize());
-
- query = "//nested[. &= 'pro']";
- result = service.query(query);
- assertEquals(1, result.getSize());
-
- query = "//nested[. &= 'unsuitable']";
- result = service.query(query);
- assertEquals(1, result.getSize());
-
- query = "//nested[. &= 'uneven']";
- result = service.query(query);
- assertEquals(1, result.getSize());
-
- query = "//nested[. &= 'suitable']";
- result = service.query(query);
- assertEquals(1, result.getSize());
- } catch(Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testQNameConfiguration() {
- System.out.println("----- testFtConfiguration -----");
- try {
- String config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\" attributes=\"false\">" +
- " <include path=\"//node\"/>" +
- " <create qname=\"node\"/>" +
- " <create qname=\"@id\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
- IndexQueryService idxConf = (IndexQueryService)
- testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(config);
-
- XMLResource doc =
- (XMLResource) testCollection.createResource("test-qname.xml", "XMLResource");
- doc.setContent(QNAME_XML);
- testCollection.storeResource(doc);
-
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- doQuery(service, "//node[@id &= '1']", 1);
- doQuery(service, "//test[node &= 'Second node']", 1);
- doQuery(service, "//node[. &= 'node']", 2);
-
- doQuery(service, "update insert <node id='3'>Third node</node> following //test/node[last()]", 0);
- doQuery(service, "//node[@id &= '3']", 1);
- doQuery(service, "//test[node &= 'Third node']", 1);
- doQuery(service, "//node[. &= 'Third node']", 1);
- doQuery(service, "//node[. &= 'node']", 3);
-
- doQuery(service, "update insert <node id='4'>Fourth <nested>node</nested></node> following //test/node[last()]", 0);
- doQuery(service, "//node[@id &= '4']", 1);
- doQuery(service, "//test[node &= 'Fourth node']", 1);
- doQuery(service, "//node[. &= 'Fourth node']", 1);
- doQuery(service, "//node[. &= 'node']", 4);
-
- doQuery(service, "update delete //node[@id = '1']", 0);
- doQuery(service, "//node[@id &= '1']", 0);
- doQuery(service, "//test[node &= 'First node']", 0);
- doQuery(service, "//node[. &= 'First node']", 0);
- doQuery(service, "//node[@id &= '2']", 1);
- doQuery(service, "//test[node &= 'Second node']", 1);
- doQuery(service, "//node[. &= 'Second node']", 1);
-
- doQuery(service,
- "for $i in 1 to 100 return" +
- " update insert <node id='i{$i}'>Inserted node</node> preceding //test/node[1]", 0);
-
- doQuery(service, "//node[@id &= 'i1']", 1);
- doQuery(service, "//node[. &= 'Inserted']", 100);
- doQuery(service, "//test[node &= 'Inserted']", 1);
-
- doQuery(service, "//test[* &= 'Inserted node']", 1);
- doQuery(service, "//test[. &= 'Inserted node']", 1);
- doQuery(service, "//test[node() &= 'Second node']", 1);
- doQuery(service, "//node[text() &= 'Second node']", 1);
- doQuery(service, "//node[text() &= 'Inserted node']", 100);
- } catch(Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testFtQNameScan() {
- try {
- System.out.println("----- testFtQNameScan -----");
- String config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\" attributes=\"false\">" +
- " <create qname=\"node\"/>" +
- " <create qname=\"@id\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
- IndexQueryService idxConf = (IndexQueryService)
- testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(config);
-
- XMLResource doc =
- (XMLResource) testCollection.createResource("test-qname.xml", "XMLResource");
- doc.setContent(QNAME_XML);
- testCollection.storeResource(doc);
-
- XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
- doQuery(service, "//node", 2);
-
- String queryBody =
- "declare namespace f=\'http://exist-db.org/xquery/test\';\n" +
- "import module namespace t=\'http://exist-db.org/xquery/text\';\n" +
- "\n" +
- "declare function f:term-callback($term as xs:string, $data as xs:int+)\n" +
- "as element()+ {\n" +
- " <item>\n" +
- " <term>{$term}</term>\n" +
- " <frequency>{$data[1]}</frequency>\n" +
- " </item>\n" +
- "};\n" +
- "\n";
-
- String query = queryBody + "t:index-terms(collection('" + TEST_COLLECTION_PATH + "')//node, (), util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
- ResourceSet result = service.query(query);
- for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
- Resource resource = i.nextResource();
- System.out.println(resource.getContent());
- }
- assertEquals(8, result.getSize());
-
- query = queryBody + "t:index-terms(collection('" + TEST_COLLECTION_PATH + "')//node, " +
- "xs:QName('node'), (), util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
- result = service.query(query);
- for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
- Resource resource = i.nextResource();
- System.out.println(resource.getContent());
- }
- assertEquals(3, result.getSize());
-
- query = "import module namespace t=\'http://exist-db.org/xquery/text\';\n" +
- "t:fuzzy-index-terms('node')";
- result = service.query(query);
- for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
- Resource resource = i.nextResource();
- System.out.println(resource.getContent());
- }
- assertEquals(1, result.getSize());
- } catch (XMLDBException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testReindex() {
- try {
- String config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\" attributes=\"false\">" +
- " <include path=\"//node\"/>" +
- " <create qname=\"node\"/>" +
- " <create qname=\"@id\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
- IndexQueryService idxConf = (IndexQueryService)
- testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(config);
-
- XMLResource doc =
- (XMLResource) testCollection.createResource("test-qname.xml", "XMLResource");
- doc.setContent(QNAME_XML);
- testCollection.storeResource(doc);
-
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- doQuery(service, "update insert <node id='3'>Third node</node> following //test/node[last()]", 0);
- doQuery(service, "//node[@id &= '3']", 1);
- doQuery(service, "//test[node &= 'Third node']", 1);
- doQuery(service, "//node[. &= 'Third node']", 1);
- doQuery(service, "//node[. &= 'node']", 3);
-
- IndexQueryService mgmt = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
- mgmt.reindexCollection();
-
- doQuery(service, "//node[@id &= '1']", 1);
- doQuery(service, "//test[node &= 'Second node']", 1);
- doQuery(service, "//node[. &= 'Second node']", 1);
- doQuery(service, "//node[. &= 'node']", 3);
- doQuery(service, "//node[@id &= '3']", 1);
- doQuery(service, "//test[node &= 'Third node']", 1);
- doQuery(service, "//node[. &= 'Third node']", 1);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public void testMatchCount() {
- System.out.println("----- testMatchCount -----");
- try {
- String config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\" attributes=\"false\">" +
- " <include path=\"/doc\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
- IndexQueryService idxConf = (IndexQueryService)
- testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(config);
-
- XMLResource doc =
- (XMLResource) testCollection.createResource(
- "test-match-count.xml", "XMLResource");
- doc.setContent(MATCH_COUNT);
- testCollection.storeResource(doc);
-
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- String query = "for $d in /doc[. &= 'term'] " +
- "return (text:match-count($d), " +
- "for $l in $d/level1 return text:match-count($l))";
- ResourceSet result = service.query(query);
- assertEquals(3, result.getSize());
- assertEquals("6", result.getResource(0).getContent().toString());
- assertEquals("2", result.getResource(1).getContent().toString());
- assertEquals("2", result.getResource(2).getContent().toString());
- } catch(Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- //It looks like matches are not copied along all axes
- public void bugtestMatchCount() {
- System.out.println("----- testMatchCount -----");
- try {
- String config =
- "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" +
- " <index>" +
- " <fulltext default=\"none\" attributes=\"false\">" +
- " <include path=\"/doc\"/>" +
- " </fulltext>" +
- " </index>" +
- "</collection>";
- IndexQueryService idxConf = (IndexQueryService)
- testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(config);
-
- XMLResource doc =
- (XMLResource) testCollection.createResource(
- "test-match-count.xml", "XMLResource");
- doc.setContent(MATCH_COUNT);
- testCollection.storeResource(doc);
-
- XQueryService service = (XQueryService)
- testCollection.getService("XQueryService", "1.0");
- String query = "for $d in /doc[. &= 'term'] " +
- "return text:match-count($d/level1[1]/..)";
- ResourceSet result = service.query(query);
- assertEquals(1, result.getSize());
- assertEquals("2", result.getResource(0).getContent().toString());
-
- query = "for $node in /doc//*[. &= 'term'] " +
- "return concat(local-name($node), '(', text:match-count($node), ')')" ;
- result = service.query(query);
- assertEquals(4, result.getSize());
- assertEquals("doc(6)", result.getResource(0).getContent().toString());
- assertEquals("level1(2)", result.getResource(1).getContent().toString());
- assertEquals("level1(2)", result.getResource(2).getContent().toString());
- assertEquals("level2(1)", result.getResource(3).getContent().toString());
- } catch(Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- private void doQuery(XQueryService service, String query, int expected) throws XMLDBException {
- ResourceSet result = service.query(query);
- assertEquals(expected, result.getSize());
- }
-
- protected void setUp() {
- try {
-
- //Since we use the deprecated fn:match-all() function, we have to be sure is is enabled
- Configuration config = new Configuration();
- config.setProperty(FunctionFactory.PROPERTY_DISABLE_DEPRECATED_FUNCTIONS, new Boolean(false));
- BrokerPool.configure(1, 5, config);
-
- // initialize driver
- Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
- database = (Database) cl.newInstance();
- database.setProperty("create-database", "true");
- DatabaseManager.registerDatabase(database);
-
- Collection root =
- DatabaseManager.getCollection(XmldbURI.LOCAL_DB, "admin", "");
-
- CollectionManagementService service =
- (CollectionManagementService) root.getService(
- "CollectionManagementService",
- "1.0");
- testCollection = service.createCollection(TEST_COLLECTION_NAME);
- assertNotNull(testCollection);
-
- IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
- idxConf.configureCollection(COLLECTION_CONFIG1);
-
- for (int i = 0; i < FILES.length; i++) {
- XMLResource doc =
- (XMLResource) testCollection.createResource(
- FILES[i], "XMLResource" );
- doc.setContent(new File(SHAKES_DIR, FILES[i]));
- testCollection.storeResource(doc);
- assertNotNull(testCollection.getResource(FILES[i]));
- }
-
- } catch (ClassNotFoundException e) {
- } catch (InstantiationException e) {
- } catch (IllegalAccessException e) {
- } catch (DatabaseConfigurationException e) {