Author: natalia Date: Wed Aug 29 19:51:50 2007 New Revision: 571021 URL: http://svn.apache.org/viewvc?rev=571021&view=rev Log: Text query command
Added: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java (with props) Modified: xml/xindice/trunk/config/commands.xml Modified: xml/xindice/trunk/config/commands.xml URL: http://svn.apache.org/viewvc/xml/xindice/trunk/config/commands.xml?rev=571021&r1=571020&r2=571021&view=diff ============================================================================== --- xml/xindice/trunk/config/commands.xml (original) +++ xml/xindice/trunk/config/commands.xml Wed Aug 29 19:51:50 2007 @@ -118,6 +118,11 @@ class="org.apache.xindice.tools.command.XPathQuery" helpclass="document" description="Queries a Collection using XPath" /> + <command switch="text" + name="text_query" + class="org.apache.xindice.tools.command.TextQuery" + helpclass="document" + description="Queries a Collection using text query" /> <command switch="xupdate" name="xupdate_query" class="org.apache.xindice.tools.command.XUpdate" Added: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java?rev=571021&view=auto ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java (added) +++ xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java Wed Aug 29 19:51:50 2007 @@ -0,0 +1,83 @@ +/* + * 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.tools.command; + +import org.apache.xindice.tools.XMLTools; +import org.apache.xindice.client.TextQueryService; +import org.xmldb.api.base.Collection; +import org.xmldb.api.base.ResourceIterator; +import org.xmldb.api.base.ResourceSet; +import org.xmldb.api.modules.XMLResource; +import org.xmldb.api.DatabaseManager; + +import java.util.Hashtable; + +/** + * TextQuery is designed to enable the user to query a Collection for + * Documents that match Lucene query. + * + * @version $Revision$, $Date$ + */ +public class TextQuery extends Command { + + public boolean execute(Hashtable table) throws Exception { + if (table.get(XMLTools.COLLECTION) == null) { + System.out.println("ERROR : Collection name and switch required"); + return false; + } + + if ("".equals(table.get(XMLTools.QUERY))) { + System.out.println("ERROR : Query and switch required"); + return false; + } + + + Collection col = null; + try { + String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION), + (String) table.get(XMLTools.LOCAL)); + String querystring = (String) table.get(XMLTools.QUERY); + + col = DatabaseManager.getCollection(colstring); + + if (col == null) { + System.out.println("ERROR : Collection not found!"); + return false; + } + + TextQueryService service = (TextQueryService) col.getService("TextQueryService", "1.0"); + + ResourceSet resultSet = service.query(querystring); + ResourceIterator results = resultSet.getIterator(); + + while (results.hasMoreResources()) { + XMLResource resource = (XMLResource) results.nextResource(); + String documentstr = (String) resource.getContent(); + System.out.println(documentstr); + } + } finally { + if (col != null) { + col.close(); + } + } + + return true; + } +} Propchange: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xml/xindice/trunk/java/src/org/apache/xindice/tools/command/TextQuery.java ------------------------------------------------------------------------------ svn:keywords = Id Revision Author Date