Author: natalia Date: Thu Aug 16 17:35:14 2007 New Revision: 566891 URL: http://svn.apache.org/viewvc?view=rev&rev=566891 Log: New service for executing text searches
Added: xml/xindice/trunk/java/src/org/apache/xindice/client/TextQueryService.java (with props) xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/services/TextQueryServiceImpl.java (with props) xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/TextQueryTest.java (with props) Modified: xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/IntegrationTests.java Added: xml/xindice/trunk/java/src/org/apache/xindice/client/TextQueryService.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/client/TextQueryService.java?view=auto&rev=566891 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/client/TextQueryService.java (added) +++ xml/xindice/trunk/java/src/org/apache/xindice/client/TextQueryService.java Thu Aug 16 17:35:14 2007 @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.xindice.client; + +import org.xmldb.api.base.Service; +import org.xmldb.api.base.ResourceSet; +import org.xmldb.api.base.XMLDBException; + +/** + * TextQueryService allows using full text search against a collection. The + * context collection must have LuceneIndexer in order to execute a search. + * + * @version $Revision$, $Date$ + */ +public interface TextQueryService extends Service { + ResourceSet query(String string) throws XMLDBException; + ResourceSet queryResource(String string, String string1) throws XMLDBException; +} Propchange: xml/xindice/trunk/java/src/org/apache/xindice/client/TextQueryService.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xml/xindice/trunk/java/src/org/apache/xindice/client/TextQueryService.java ------------------------------------------------------------------------------ svn:keywords = Id Revision Author Date Modified: xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java?view=diff&rev=566891&r1=566890&r2=566891 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java Thu Aug 16 17:35:14 2007 @@ -23,6 +23,7 @@ import org.apache.xindice.client.xmldb.resources.BinaryResourceImpl; import org.apache.xindice.client.xmldb.services.CollectionManagementServiceImpl; import org.apache.xindice.client.xmldb.services.MetaService; +import org.apache.xindice.client.xmldb.services.TextQueryServiceImpl; import org.apache.xindice.client.xmldb.services.XPathQueryServiceImpl; import org.apache.xindice.client.xmldb.services.XUpdateQueryServiceImpl; import org.apache.xindice.core.FaultCodes; @@ -81,22 +82,21 @@ // Register all services supported by this collection implementation. final XPathQueryServiceImpl xpath = new XPathQueryServiceImpl(); - xpath.setCollection(this); // xpath.setSymbolDeserializer(syms); registerService(xpath); final XUpdateQueryServiceImpl xupdate = new XUpdateQueryServiceImpl(); - xupdate.setCollection(this); registerService(xupdate); + final TextQueryServiceImpl text = new TextQueryServiceImpl(); + registerService(text); + // TODO if (this.col.isMetaEnabled()) { final MetaService meta = new MetaService(); - meta.setCollection(this); registerService(meta); try { final CollectionManagementServiceImpl manager = new CollectionManagementServiceImpl(); - manager.setCollection(this); registerService(manager); // CollectionManagementServiceImpl provides both standard access as a @@ -152,9 +152,7 @@ public org.xmldb.api.base.Service getService(String name, String version) throws XMLDBException { checkOpen(); - Service result = (Service) services.get(name + version); - - return result; + return (Service) services.get(name + version); } /** Added: xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/services/TextQueryServiceImpl.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/services/TextQueryServiceImpl.java?view=auto&rev=566891 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/services/TextQueryServiceImpl.java (added) +++ xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/services/TextQueryServiceImpl.java Thu Aug 16 17:35:14 2007 @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.xindice.client.xmldb.services; + +import org.apache.xindice.client.TextQueryService; + +/** + * XML:DB TextQueryService implementation that uses XML-RPC communication + * with server + * + * @version $Revision$, $Date$ + */ +public class TextQueryServiceImpl extends QueryService implements TextQueryService { + + /** + * Creates new TextQueryService + */ + public TextQueryServiceImpl() { + super(); + queryLang = "Text"; + } +} Propchange: xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/services/TextQueryServiceImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/services/TextQueryServiceImpl.java ------------------------------------------------------------------------------ svn:keywords = Id Revision Author Date Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/IntegrationTests.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/IntegrationTests.java?view=diff&rev=566891&r1=566890&r2=566891 ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/IntegrationTests.java (original) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/IntegrationTests.java Thu Aug 16 17:35:14 2007 @@ -27,6 +27,7 @@ import org.apache.xindice.integration.client.services.MetaTest; import org.apache.xindice.integration.client.services.XPathQueryTest; import org.apache.xindice.integration.client.services.XUpdateQueryTest; +import org.apache.xindice.integration.client.services.TextQueryTest; import junit.framework.TestSuite; @@ -43,6 +44,7 @@ suite.addTestSuite(DocumentTest.class); suite.addTestSuite(XUpdateQueryTest.class); suite.addTestSuite(XPathQueryTest.class); + suite.addTestSuite(TextQueryTest.class); suite.addTestSuite(MetaTest.class); suite.addTestSuite(IndexedSearchTest.class); suite.addTestSuite(BinaryResourceTest.class); Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/TextQueryTest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/TextQueryTest.java?view=auto&rev=566891 ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/TextQueryTest.java (added) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/TextQueryTest.java Thu Aug 16 17:35:14 2007 @@ -0,0 +1,290 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id$ + */ + +package org.apache.xindice.integration.client.services; + +import org.apache.xindice.integration.client.AbstractXmlDbClientTest; +import org.apache.xindice.client.TextQueryService; +import org.apache.xindice.xml.TextWriter; +import org.xmldb.api.base.Collection; +import org.xmldb.api.base.ResourceSet; +import org.xmldb.api.modules.XMLResource; +import org.custommonkey.xmlunit.XMLAssert; +import org.w3c.dom.Node; + +import java.util.HashSet; + +/** + * Tests for TextService + * @version $Revision$, $Date$ + */ +public class TextQueryTest extends AbstractXmlDbClientTest { + + private TextQueryService textService; + + public void setUp() throws Exception { + super.setUp(); + + Collection col = client.getCollection(TEST_COLLECTION_PATH); + textService = (TextQueryService) col.getService("TextQueryService", "1.0"); + + String doc1 = + "<?xml version='1.0'?>" + + "<section>\n" + + " <title>What Is Xindice</title>\n" + + " <p>\n" + + " The Xindice Core server is a database server designed from the\n" + + " ground up to store XML data. The\n" + + " Xindice server is what is termed by\n" + + " the\n" + + " <link href=\"http://xmldb-org.sourceforge.net/\">XML:DB Initiative</link>\n" + + " as a Native XML Database. You could also refer to it as a\n" + + " seamless XML database which might be an easier to understand\n" + + " description.\n" + + " </p>\n" + + " <p>\n" + + " What this means is that to the largest extent possible you work\n" + + " with XML tools and technologies when working with the data in the\n" + + " server. All data that goes into and out of the server is XML. The\n" + + " query language used is XPath and the programming APIs support DOM\n" + + " and SAX. All things that should be familiar to a developer used\n" + + " to using XML in their applications. When working with XML data and\n" + + " Xindice there is no mapping between different data models. You simply\n" + + " design your data as XML and store it as XML.\n" + + " </p>\n" + + "</section>"; + String doc2 = + "<?xml version='1.0'?>" + + "<section>\n" + + " <title>Current Status</title>\n" + + " <p>\n" + + " Native XML database technology is a very new area and Xindice is very\n" + + " much a project still in development.\n" + + " The server currently supports storing well formed XML documents.\n" + + " This means it does not have any schema that constrains what\n" + + " can be placed into a document collection. This makes Xindice a\n" + + " semi-structured database and provides tremendous\n" + + " flexiblity in how you store your data, but, also means you give up\n" + + " some common database functionality such as data\n" + + " types.\n" + + " In its current state Xindice is already a powerful tool for managing\n" + + " XML data. However, there is still much that needs to be done.\n" + + " Feedback and contributions are actively encouraged.\n" + + " </p>\n" + + "</section>"; + String doc3 = + "<?xml version='1.0'?>" + + "<section>\n" + + " <title>Feature Summary</title>\n" + + " <p>\n" + + " <strong>Document Collections</strong>: Documents are stored in\n" + + " collections that can be queried as a whole. You can create\n" + + " collections that contain just documents of the same type or you\n" + + " can create a collection to store all your documents together.\n" + + " The database doesn't care.\n" + + " </p>\n" + + " <p>\n" + + " <strong>Command Line Management Tools</strong>: To aid the administrator\n" + + " Xindice provides a full suite of command line driven management tools.\n" + + " Just about everything you can do through the XML:DB API can also be\n" + + " done from the command line.\n" + + " </p>\n" + + "</section>"; + String doc4 = + "<?xml version='1.0'?>" + + "<section>\n" + + " <title>Introducing the Command Line Tools</title>\n" + + " <p>\n" + + " The Xindice server includes a command line program named\n" + + " <code>xindice</code> that allows you to manage the\n" + + " data stored in the server.\n" + + " A complete list of available commands and more\n" + + " detail about each command can be found in the\n" + + " <link href=\"guide-tools.html\">Command Line Tools Reference Guide</link>.\n" + + " </p>\n" + + "</section>"; + String doc5 = + "<?xml version='1.0'?>" + + " <section>\n" + + " <title>Retrieving Documents</title>\n" + + " <p>\n" + + " Documents can be retrieved from the database using the ID that\n" + + " they were inserted under.\n" + + " </p>\n" + + " </section>"; + String doc6 = + "<?xml version='1.0'?>" + + " <section>\n" + + " <title>Deleting Documents</title>\n" + + " <p>\n" + + " The document identified by the key fx102 will be removed from the\n" + + " collection /db/data/products.\n" + + " </p>\n" + + " </section>"; + + String config = + "<index name='text' class='org.apache.xindice.core.indexer.LuceneIndexer'> " + + "<pattern pattern='title' alias='title'/>" + + "<pattern pattern='p' alias='text'/>" + + "</index>"; + this.client.createIndexer(TEST_COLLECTION_PATH, config); + this.client.insertDocument(TEST_COLLECTION_PATH, "doc1", doc1); + this.client.insertDocument(TEST_COLLECTION_PATH, "doc2", doc2); + this.client.insertDocument(TEST_COLLECTION_PATH, "doc3", doc3); + this.client.insertDocument(TEST_COLLECTION_PATH, "doc4", doc4); + this.client.insertDocument(TEST_COLLECTION_PATH, "doc5", doc5); + this.client.insertDocument(TEST_COLLECTION_PATH, "doc6", doc6); + } + + public void tearDown() throws Exception { + this.client.removeDocument(TEST_COLLECTION_PATH, "doc1"); + this.client.removeDocument(TEST_COLLECTION_PATH, "doc2"); + this.client.removeDocument(TEST_COLLECTION_PATH, "doc3"); + this.client.removeDocument(TEST_COLLECTION_PATH, "doc4"); + this.client.removeDocument(TEST_COLLECTION_PATH, "doc5"); + this.client.removeDocument(TEST_COLLECTION_PATH, "doc6"); + + super.tearDown(); + } + + public void testTermQuery() throws Exception { + String query = "text:xml"; + + ResourceSet resultSet = textService.query(query); + assertEquals(3, resultSet.getSize()); + + HashSet actual = new HashSet(); + actual.add(((XMLResource) resultSet.getResource(0)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(1)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(2)).getDocumentId()); + + HashSet expected = new HashSet(); + expected.add("doc1"); + expected.add("doc2"); + expected.add("doc3"); + assertEquals(expected, actual); + } + + public void testPhraseQuery() throws Exception { + String query = "text:\"command line\""; + + ResourceSet resultSet = textService.query(query); + assertEquals(2, resultSet.getSize()); + + HashSet actual = new HashSet(); + actual.add(((XMLResource) resultSet.getResource(0)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(1)).getDocumentId()); + + HashSet expected = new HashSet(); + expected.add("doc3"); + expected.add("doc4"); + assertEquals(expected, actual); + } + + public void testAndQuery() throws Exception { + // By default indexer uses SimpleAnalyzer that does not stem words, + // so query has to exact + String query = "title:documents AND text:removed"; + + ResourceSet resultSet = textService.query(query); + assertEquals(1, resultSet.getSize()); + + String key = ((XMLResource) resultSet.getResource(0)).getDocumentId(); + assertEquals("doc6", key); + } + + public void testOrQuery() throws Exception { + String query = "text:server OR text:database"; + + ResourceSet resultSet = textService.query(query); + assertEquals(5, resultSet.getSize()); + + HashSet actual = new HashSet(); + actual.add(((XMLResource) resultSet.getResource(0)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(1)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(2)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(3)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(4)).getDocumentId()); + + HashSet expected = new HashSet(); + expected.add("doc1"); + expected.add("doc2"); + expected.add("doc3"); + expected.add("doc4"); + expected.add("doc5"); + assertEquals(expected, actual); + } + + public void testWildcardQuery() throws Exception { + String query = "text:program*"; + + ResourceSet resultSet = textService.query(query); + assertEquals(2, resultSet.getSize()); + + HashSet actual = new HashSet(); + actual.add(((XMLResource) resultSet.getResource(0)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(1)).getDocumentId()); + + HashSet expected = new HashSet(); + expected.add("doc1"); + expected.add("doc4"); + assertEquals(expected, actual); + } + + public void testProximityQuery() throws Exception { + String query = "text:\"xindice database\"~5"; + + ResourceSet resultSet = textService.query(query); + assertEquals(2, resultSet.getSize()); + + HashSet actual = new HashSet(); + actual.add(((XMLResource) resultSet.getResource(0)).getDocumentId()); + actual.add(((XMLResource) resultSet.getResource(1)).getDocumentId()); + + HashSet expected = new HashSet(); + expected.add("doc1"); + expected.add("doc2"); + assertEquals(expected, actual); + } + + public void testResultDoc() throws Exception { + String query = "title:\"deleting documents\""; + + ResourceSet resultSet = textService.query(query); + assertEquals(1, resultSet.getSize()); + + XMLResource resource = (XMLResource) resultSet.getResource(0); + + assertEquals("doc6", resource.getDocumentId()); + + Node node = resource.getContentAsDOM(); + + // modify the document to add source node information + String doc = + "<?xml version='1.0'?>" + + " <section xmlns:src='http://xml.apache.org/xindice/Query' src:col='/db/testing/current' src:key='doc6'>\n" + + " <title>Deleting Documents</title>\n" + + " <p>\n" + + " The document identified by the key fx102 will be removed from the\n" + + " collection /db/data/products.\n" + + " </p>\n" + + " </section>"; + XMLAssert.assertXMLEqual(doc, TextWriter.toString(node)); + } +} Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/TextQueryTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/TextQueryTest.java ------------------------------------------------------------------------------ svn:keywords = Id Revision Author Date