Author: thomas.heute(a)jboss.com
Date: 2007-02-12 10:01:24 -0500 (Mon, 12 Feb 2007)
New Revision: 6212
Added:
trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestSearch.java
trunk/portal-search/src/resources/portal-search-war/WEB-INF/web.xml
trunk/search/src/main/org/jboss/portal/search/test/ConverterTest.java
Modified:
trunk/cms/build.xml
trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/SearchCommand.java
trunk/cms/src/resources/test/jcr/fs-repository.xml
trunk/cms/src/resources/test/jcr/repository.xml
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/searchResults.jsp
trunk/portal-search/.project
trunk/portal-search/build.xml
trunk/search/src/main/org/jboss/portal/search/QueryConverter.java
trunk/search/src/main/org/jboss/portal/search/federated/jcr/JCRQueryConverter.java
Log:
- Adding test cases
- Adding language property key CMS_SEARCHNORESULT
- Renaming portal-search project -> core-search
Modified: trunk/cms/build.xml
===================================================================
--- trunk/cms/build.xml 2007-02-11 21:18:06 UTC (rev 6211)
+++ trunk/cms/build.xml 2007-02-12 15:01:24 UTC (rev 6212)
@@ -391,13 +391,13 @@
</x-sysproperty>
<x-test>
<!-- general cms setup related tests -->
- <test todir="${test.reports}"
name="org.jboss.portal.test.cms.JackrabbitTestCase"/>
+ <!--test todir="${test.reports}"
name="org.jboss.portal.test.cms.JackrabbitTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.TestRepositoryBootStrap"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.TestRegEx"/>
- <test todir="${test.reports}"
name="org.jboss.portal.test.cms.TestRepositoryUtil"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.cms.TestRepositoryUtil"/-->
<!-- cms file command tests -->
- <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileCreate"/>
+ <!--test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileCreate"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileUpdate"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileArchiveUpload"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileGet"/>
@@ -405,14 +405,15 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileGetList"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileCopy"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileCreateFailed"/>
- <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileDelete"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileDelete"/-->
+ <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestSearch"/>
<!-- cms folder command tests -->
- <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFolderCopy"/>
+ <!--test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFolderCopy"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFolderCreate"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFolderDelete"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFolderGet"/>
- <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFolderUpdate"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFolderUpdate"/-->
<!-- cms fine grained security related tests -->
<!--test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestSecureFileGet"/-->
@@ -442,6 +443,7 @@
<path refid="cglib.cglib.classpath"/>
<path refid="jboss.portal-common.classpath"/>
<path refid="jboss.portal-test.classpath"/>
+ <path refid="jboss.portal-search.classpath"/>
<path refid="jboss.portal-server.classpath"/>
<path refid="jboss.portal-jems.classpath"/>
<pathelement location="${build.lib}/portal-cms-lib.jar"/>
@@ -451,6 +453,7 @@
<pathelement location="${jboss.portal-test.root}/etc"/>
<!-- jbosscachepersistence manager integration -->
<path refid="jackrabbit.jackrabbit.classpath"/>
+ <path refid="nekohtml.nekohtml.classpath"/>
<path refid="jboss.cache.classpath"/>
<path refid="jgroups.jgroups.classpath"/>
<!-- fine grained security integration -->
Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/SearchCommand.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/SearchCommand.java 2007-02-11
21:18:06 UTC (rev 6211)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/command/SearchCommand.java 2007-02-12
15:01:24 UTC (rev 6212)
@@ -65,21 +65,26 @@
try
{
queryManager = workspace.getQueryManager();
- javax.jcr.query.Query jcrQuery =
queryManager.createQuery(JCRQueryConverter.convert(query), javax.jcr.query.Query.XPATH);
- QueryResult queryResult=jcrQuery.execute();
- NodeIterator nodeIterator = queryResult.getNodes();
+ String queryString = JCRQueryConverter.convert(query);
- while (nodeIterator.hasNext())
+ if (! "".equals(queryString))
{
- Node node;
- node = nodeIterator.nextNode().getParent();
- File file = new FileImpl();
- file.setBasePath(node.getPath());
-
file.setCreationDate(node.getProperty("jcr:created").getDate().getTime());
-
file.setLastModified(node.getProperty("jcr:lastModified").getDate().getTime());
- file.setName(node.getName());
- files.add(file);
- }
+ javax.jcr.query.Query jcrQuery = queryManager.createQuery(queryString,
javax.jcr.query.Query.XPATH);
+ QueryResult queryResult=jcrQuery.execute();
+ NodeIterator nodeIterator = queryResult.getNodes();
+
+ while (nodeIterator.hasNext())
+ {
+ Node node;
+ node = nodeIterator.nextNode().getParent();
+ File file = new FileImpl();
+ file.setBasePath(node.getPath());
+
file.setCreationDate(node.getProperty("jcr:created").getDate().getTime());
+
file.setLastModified(node.getProperty("jcr:lastModified").getDate().getTime());
+ file.setName(node.getName());
+ files.add(file);
+ }
+ }
}
catch (Exception e)
{
Added: trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestSearch.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestSearch.java
(rev 0)
+++ trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestSearch.java 2007-02-12
15:01:24 UTC (rev 6212)
@@ -0,0 +1,68 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.cms.commands;
+
+import junit.framework.TestSuite;
+import org.jboss.portal.cms.CMSException;
+import org.jboss.portal.cms.Command;
+import org.jboss.portal.cms.impl.ContentImpl;
+import org.jboss.portal.cms.impl.FileImpl;
+import org.jboss.portal.cms.model.Content;
+import org.jboss.portal.cms.model.File;
+import org.jboss.portal.search.query.Query;
+import org.jboss.portal.search.query.impl.KeywordQueryTerm;
+
+import java.util.List;
+import java.util.Locale;
+
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ */
+public class TestSearch extends AbstractCommandTestCase
+{
+
+ public TestSearch()
+ {
+ }
+
+ public static TestSuite suite() throws Exception
+ {
+ return createTestSuite(TestSearch.class);
+ }
+
+ /** Tests retrieval of the version labeled LIVE. */
+ public void testFileGet() throws CMSException
+ {
+ Query query = new Query();
+ query.addOptionalTerm(new KeywordQueryTerm("risks"));
+ Command searchCMD = service.getCommandFactory().createSearchCommand(query);
+ List list = (List)service.execute(searchCMD);
+
+ File file = (File)list.get(0);
+ assertEquals("/default/private/license.html", file.getBasePath());
+ file = (File)list.get(1);
+ assertEquals("/default/support.html", file.getBasePath());
+ }
+
+}
Modified: trunk/cms/src/resources/test/jcr/fs-repository.xml
===================================================================
--- trunk/cms/src/resources/test/jcr/fs-repository.xml 2007-02-11 21:18:06 UTC (rev 6211)
+++ trunk/cms/src/resources/test/jcr/fs-repository.xml 2007-02-12 15:01:24 UTC (rev 6212)
@@ -39,18 +39,27 @@
<FileSystem
class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
<param name="path" value="${wsp.home}s"/>
</FileSystem>
- <SearchIndex
class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${wsp.home}/index"/>
- <param name="useCompoundFile" value="true"/>
- <param name="minMergeDocs" value="100"/>
- <param name="volatileIdleTime" value="3"/>
- <param name="maxMergeDocs" value="100000"/>
- <param name="mergeFactor" value="10"/>
- <param name="bufferSize" value="10"/>
- <param name="cacheSize" value="1000"/>
- <param name="forceConsistencyCheck" value="false"/>
- <param name="autoRepair" value="true"/>
- </SearchIndex>
+ <SearchIndex
class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path"
value="${wsp.home}/index"/>
+ <param name="textFilterClasses" value="
+ org.apache.jackrabbit.core.query.MsExcelTextFilter,
+ org.apache.jackrabbit.core.query.MsPowerPointTextFilter,
+ org.apache.jackrabbit.core.query.MsWordTextFilter,
+ org.apache.jackrabbit.core.query.PdfTextFilter,
+ org.apache.jackrabbit.core.query.HTMLTextFilter,
+ org.apache.jackrabbit.core.query.XMLTextFilter,
+ org.apache.jackrabbit.core.query.RTFTextFilter,
+ org.apache.jackrabbit.core.query.OpenOfficeTextFilter" />
+ <param name="useCompoundFile" value="true"/>
+ <param name="minMergeDocs" value="100"/>
+ <param name="volatileIdleTime" value="3"/>
+ <param name="maxMergeDocs" value="100000"/>
+ <param name="mergeFactor" value="10"/>
+ <param name="bufferSize" value="10"/>
+ <param name="cacheSize" value="1000"/>
+ <param name="forceConsistencyCheck"
value="false"/>
+ <param name="autoRepair" value="true"/>
+ </SearchIndex>
</Workspace>
<Versioning rootPath="${rep.home}/versions">
<PersistenceManager
class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager"/>
Modified: trunk/cms/src/resources/test/jcr/repository.xml
===================================================================
--- trunk/cms/src/resources/test/jcr/repository.xml 2007-02-11 21:18:06 UTC (rev 6211)
+++ trunk/cms/src/resources/test/jcr/repository.xml 2007-02-12 15:01:24 UTC (rev 6212)
@@ -75,18 +75,27 @@
<!-- XMLPersistenceManager: uses FileSystem for storage -->
<!--<PersistenceManager
class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager"/>-->
- <!--SearchIndex
class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${wsp.home}/index"/>
- <param name="useCompoundFile" value="true"/>
- <param name="minMergeDocs" value="100"/>
- <param name="volatileIdleTime" value="3"/>
- <param name="maxMergeDocs" value="100000"/>
- <param name="mergeFactor" value="10"/>
- <param name="bufferSize" value="10"/>
- <param name="cacheSize" value="1000"/>
- <param name="forceConsistencyCheck" value="false"/>
- <param name="autoRepair" value="true"/>
- </SearchIndex-->
+ <SearchIndex
class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path"
value="${wsp.home}/index"/>
+ <param name="textFilterClasses" value="
+ org.apache.jackrabbit.core.query.MsExcelTextFilter,
+ org.apache.jackrabbit.core.query.MsPowerPointTextFilter,
+ org.apache.jackrabbit.core.query.MsWordTextFilter,
+ org.apache.jackrabbit.core.query.PdfTextFilter,
+ org.apache.jackrabbit.core.query.HTMLTextFilter,
+ org.apache.jackrabbit.core.query.XMLTextFilter,
+ org.apache.jackrabbit.core.query.RTFTextFilter,
+ org.apache.jackrabbit.core.query.OpenOfficeTextFilter" />
+ <param name="useCompoundFile" value="true"/>
+ <param name="minMergeDocs" value="100"/>
+ <param name="volatileIdleTime" value="3"/>
+ <param name="maxMergeDocs" value="100000"/>
+ <param name="mergeFactor" value="10"/>
+ <param name="bufferSize" value="10"/>
+ <param name="cacheSize" value="1000"/>
+ <param name="forceConsistencyCheck"
value="false"/>
+ <param name="autoRepair" value="true"/>
+ </SearchIndex>
</Workspace>
<Versioning rootPath="${rep.home}/versions">
<!--
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
---
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2007-02-11
21:18:06 UTC (rev 6211)
+++
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2007-02-12
15:01:24 UTC (rev 6212)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
@@ -96,6 +97,7 @@
private MembershipModule membershipModule;
private ApprovePublish approvePublish;
private AuthorizationManager authorizationManager;
+
public void init() throws PortletException
{
@@ -309,10 +311,19 @@
String textQuery = rReq.getParameter("search");
Query query = QueryConverter.convert(textQuery);
- Command searchCommand =
CMSService.getCommandFactory().createSearchCommand(query);
-
- List files = (List)CMSService.execute(searchCommand);
+ List files;
+ try
+ {
+ Command searchCommand =
CMSService.getCommandFactory().createSearchCommand(query);
+ files = (List)CMSService.execute(searchCommand);
+ }
+ catch (CMSException e)
+ {
+ e.printStackTrace();
+ files = new ArrayList();
+ }
rReq.setAttribute("files", files);
+ rReq.setAttribute("textQuery", textQuery);
javax.portlet.PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(CMSAdminConstants.CMS_JSP_PATH +
"/searchResults.jsp");
prd.include(rReq, rRes);
Modified: trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
===================================================================
---
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2007-02-11
21:18:06 UTC (rev 6211)
+++
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2007-02-12
15:01:24 UTC (rev 6212)
@@ -36,6 +36,7 @@
TITLE_SECURECONFIRM=Secure Node
CMS_SEARCH=Search
+CMS_SEARCHNORESULT=No result for this search
CMS_MENU=Action Menu
CMS_ACTION=Action
CMS_NAME=Name
Modified:
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties
===================================================================
---
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties 2007-02-11
21:18:06 UTC (rev 6211)
+++
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties 2007-02-12
15:01:24 UTC (rev 6212)
@@ -23,14 +23,15 @@
# CMS ADMIN PORTLET
TITLE_HEAD=Administration CMS
-TITLE_BROWSE=Navigation repertoires
+TITLE_BROWSE=Navigation r\u00E9pertoires
TITLE_DELETECONFIRM=Confirmer la suppression
-TITLE_CREATECOLLCONFIRM=Confirmer la creation de repertoire
+TITLE_CREATECOLLCONFIRM=Confirmer la cr\u00E9ation de r\u00E9pertoire
TITLE_COPYCONFIRM=Confirmer la copie de fichier
-TITLE_MOVECONFIRM=Confirmer le deplacement de fichier
-TITLE_VIEWFILE=Voir les proprietes du fichier
+TITLE_MOVECONFIRM=Confirmer le d\u00E9placement de fichier
+TITLE_VIEWFILE=Voir les propri\u00E9t\u00E9s du fichier
TITLE_EDIT=Editer le fichier
-TITLE_CREATE=Creer le fichier
+TITLE_CREATE=Cr\u00E9er le fichier
TITLE_UPLOAD=Charger le fichier
TITLE_SECURECONFIRM=S\u00E9curiser le noeud
CMS_SEARCH=Chercher
+CMS_SEARCHNORESULT=Aucun r\u00E9sultat pour cette recherche
\ No newline at end of file
Modified:
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/searchResults.jsp
===================================================================
---
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/searchResults.jsp 2007-02-11
21:18:06 UTC (rev 6211)
+++
trunk/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/searchResults.jsp 2007-02-12
15:01:24 UTC (rev 6212)
@@ -11,7 +11,23 @@
<portlet:defineObjects/>
-<table>
+<div align="right">
+
+<form method="post" action="<portlet:actionURL>
+ <portlet:param name="op" value="<%=
CMSAdminConstants.OP_DOSEARCH %>"/>
+ </portlet:actionURL>">
+ <input type="text"
+ size="15"
+ maxlength="80"
+ name="search"
+ class="portlet-form-input-field"
+ value="<%=
request.getAttribute("textQuery") %>"
+ />
+ <input type="submit" name="search"
value="${n:i18n("CMS_SEARCH")}"
class="portlet-form-button"/>
+</form>
+</div>
+
+
<%
List files = (List)request.getAttribute("files");
String createDate = "";
@@ -19,6 +35,9 @@
if (files.size() > 0)
{
+%>
+<table>
+<%
for (int i = 0; i < files.size(); i++)
{
File file = (File)files.get(i);
@@ -74,7 +93,14 @@
</tr>
<%
}
+%>
+</table>
+<%
}
+ else
+ {
+%>
+ <h2>${n:i18n("CMS_SEARCHNORESULT")}</h2>
+<%
+ }
%>
-</table>
-</form>
Modified: trunk/portal-search/.project
===================================================================
--- trunk/portal-search/.project 2007-02-11 21:18:06 UTC (rev 6211)
+++ trunk/portal-search/.project 2007-02-12 15:01:24 UTC (rev 6212)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>portal-search</name>
+ <name>core-search</name>
<comment></comment>
<projects>
</projects>
Modified: trunk/portal-search/build.xml
===================================================================
--- trunk/portal-search/build.xml 2007-02-11 21:18:06 UTC (rev 6211)
+++ trunk/portal-search/build.xml 2007-02-12 15:01:24 UTC (rev 6212)
@@ -219,8 +219,8 @@
<mkdir dir="${build.lib}"/>
- <!-- portal-jbp-search-lib.jar -->
- <jar jarfile="${build.lib}/portal-jbp-search-lib.jar">
+ <!-- portal-core-search-lib.jar -->
+ <jar jarfile="${build.lib}/portal-core-search-lib.jar">
<fileset dir="${build.classes}">
</fileset>
</jar>
@@ -231,7 +231,7 @@
<fileset dir="${build.resources}/portal-search-sar"/>
</copy>
<copy todir="${build.resources}/portal-search/lib">
- <fileset dir="${build.lib}"
includes="portal-jbp-search-lib.jar"/>
+ <fileset dir="${build.lib}"
includes="portal-core-search-lib.jar"/>
<fileset dir="${jboss.portal-search.root}/lib"
includes="portal-search-lib.jar"/>
</copy>
Added: trunk/portal-search/src/resources/portal-search-war/WEB-INF/web.xml
===================================================================
--- trunk/portal-search/src/resources/portal-search-war/WEB-INF/web.xml
(rev 0)
+++ trunk/portal-search/src/resources/portal-search-war/WEB-INF/web.xml 2007-02-12
15:01:24 UTC (rev 6212)
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+</web-app>
Property changes on: trunk/portal-search/src/resources/portal-search-war/WEB-INF/web.xml
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/search/src/main/org/jboss/portal/search/QueryConverter.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/QueryConverter.java 2007-02-11 21:18:06
UTC (rev 6211)
+++ trunk/search/src/main/org/jboss/portal/search/QueryConverter.java 2007-02-12 15:01:24
UTC (rev 6212)
@@ -32,7 +32,12 @@
public class QueryConverter
{
- // TODO: implemement this
+ // TODO: implemement this with something more sofisticated using JavaCC
+ // and a simple grammar probably
+ /**
+ * Convert a string into a Query object
+ * @return Query object for the text string
+ */
public static Query convert(String textQuery)
{
Query query = new Query();
Modified:
trunk/search/src/main/org/jboss/portal/search/federated/jcr/JCRQueryConverter.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/federated/jcr/JCRQueryConverter.java 2007-02-11
21:18:06 UTC (rev 6211)
+++
trunk/search/src/main/org/jboss/portal/search/federated/jcr/JCRQueryConverter.java 2007-02-12
15:01:24 UTC (rev 6212)
@@ -35,22 +35,25 @@
public class JCRQueryConverter
{
- //TODO, just for testing, would only work with at least one KeywordQueryTerm and
nothing else
+ //TODO, just for testing, would only work with one or more optional KeywordQueryTerm
and nothing else
public static String convert(Query query)
{
StringBuffer result = new StringBuffer();
List optional = query.getOptionalTerms();
- Iterator it = optional.iterator();
- result.append("//*[");
+ if (optional.size() != 0)
+ {
+ Iterator it = optional.iterator();
+ result.append("//*[");
- result.append("jcr:contains(., '" +
((KeywordQueryTerm)it.next()).getKeyWord() + "')");
+ result.append("jcr:contains(., '" +
((KeywordQueryTerm)it.next()).getKeyWord() + "')");
- while(it.hasNext())
- {
- result.append("or jcr:contains(., '" +
((KeywordQueryTerm)it.next()).getKeyWord() + "')");
+ while(it.hasNext())
+ {
+ result.append("or jcr:contains(., '" +
((KeywordQueryTerm)it.next()).getKeyWord() + "')");
+ }
+ result.append("]");
}
- result.append("]");
return result.toString();
}
Added: trunk/search/src/main/org/jboss/portal/search/test/ConverterTest.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/test/ConverterTest.java
(rev 0)
+++ trunk/search/src/main/org/jboss/portal/search/test/ConverterTest.java 2007-02-12
15:01:24 UTC (rev 6212)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.test;
+
+import org.jboss.portal.search.QueryConverter;
+import org.jboss.portal.search.query.Query;
+import org.jboss.portal.search.query.impl.KeywordQueryTerm;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ConverterTest extends TestCase
+{
+
+ public void testOptionalKeyword()
+ {
+ Query query = QueryConverter.convert("test");
+ KeywordQueryTerm term = (KeywordQueryTerm)query.getOptionalTerms().get(0);
+ assertEquals("test", term.getKeyWord());
+ }
+
+
+}