You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2008/03/25 23:47:50 UTC

svn commit: r641060 - in /lenya/trunk/src/modules/lucene: ./ config/cocoon-xconf/ java/src/org/apache/cocoon/transformation/ java/src/org/apache/lenya/modules/lucene/ resources/i18n/ xslt/

Author: andreas
Date: Tue Mar 25 15:47:45 2008
New Revision: 641060

URL: http://svn.apache.org/viewvc?rev=641060&view=rev
Log:
Removing obsolete UuidToUrlTransformer from lucene module, adding image search to demonstrate meta data search capabilities.

Added:
    lenya/trunk/src/modules/lucene/config/cocoon-xconf/imageQueryString-module.xconf
    lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/ImageQueryStringModule.java
    lenya/trunk/src/modules/lucene/xslt/imageTitles.xsl
Removed:
    lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/transformation/UuidToUrlTransformer.java
Modified:
    lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/QueryStringModule.java
    lenya/trunk/src/modules/lucene/resources/i18n/cmsui.xml
    lenya/trunk/src/modules/lucene/resources/i18n/cmsui_de.xml
    lenya/trunk/src/modules/lucene/sitemap.xmap
    lenya/trunk/src/modules/lucene/xslt/search2html.xsl

Added: lenya/trunk/src/modules/lucene/config/cocoon-xconf/imageQueryString-module.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/config/cocoon-xconf/imageQueryString-module.xconf?rev=641060&view=auto
==============================================================================
--- lenya/trunk/src/modules/lucene/config/cocoon-xconf/imageQueryString-module.xconf (added)
+++ lenya/trunk/src/modules/lucene/config/cocoon-xconf/imageQueryString-module.xconf Tue Mar 25 15:47:45 2008
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  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: doctypes.xconf 164635 2005-04-25 20:01:43Z tschlabach $ -->
+
+<xconf xpath="/cocoon/input-modules" unless="/cocoon/input-modules/component-instance[@name = 'imageQueryString']">
+
+  <component-instance logger="core.modules.input.imageQueryString" name="imageQueryString"
+    class="org.apache.lenya.modules.lucene.ImageQueryStringModule"/>
+  
+</xconf>

Added: lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/ImageQueryStringModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/ImageQueryStringModule.java?rev=641060&view=auto
==============================================================================
--- lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/ImageQueryStringModule.java (added)
+++ lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/ImageQueryStringModule.java Tue Mar 25 15:47:45 2008
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.lenya.modules.lucene;
+
+import org.apache.lenya.cms.metadata.MetaDataRegistry;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.TermQuery;
+
+/**
+ * Same as {@link QueryStringModule}, but searches only for images.
+ */
+public class ImageQueryStringModule extends QueryStringModule {
+    
+    protected static final String DOCUMENT_METADATA_NAMESPACE = "http://apache.org/lenya/metadata/document/1.0";
+
+    protected BooleanQuery getQuery(String searchTerm) {
+        BooleanQuery query = super.getQuery(searchTerm);
+        
+        MetaDataRegistry registry = null;
+        MetaDataFieldRegistry fieldRegistry = null;
+        try {
+            registry = (MetaDataRegistry) this.manager.lookup(MetaDataRegistry.ROLE);
+            fieldRegistry = (MetaDataFieldRegistry) this.manager.lookup(MetaDataFieldRegistry.ROLE);
+            
+            String typeField = fieldRegistry.getFieldName(DOCUMENT_METADATA_NAMESPACE, "resourceType");
+            Term typeTerm = getTerm(typeField, "resource");
+            query.add(new TermQuery(typeTerm), true, false);
+            
+            String mimeTypeField = fieldRegistry.getFieldName(DOCUMENT_METADATA_NAMESPACE, "mimeType");
+            Term mimeTypeTerm = getTerm(mimeTypeField, "image*");
+            query.add(new TermQuery(mimeTypeTerm), true, false);
+            
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (registry != null) {
+                this.manager.release(registry);
+            }
+            if (fieldRegistry != null) {
+                this.manager.release(fieldRegistry);
+            }
+        }
+        return query;
+    }
+
+
+}

Modified: lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/QueryStringModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/QueryStringModule.java?rev=641060&r1=641059&r2=641060&view=diff
==============================================================================
--- lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/QueryStringModule.java (original)
+++ lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/QueryStringModule.java Tue Mar 25 15:47:45 2008
@@ -31,6 +31,10 @@
 import org.apache.lenya.cms.metadata.Element;
 import org.apache.lenya.cms.metadata.ElementSet;
 import org.apache.lenya.cms.metadata.MetaDataRegistry;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
 
 /**
  * Creates a Lucene query string from a <em>queryString</em> request parameter
@@ -44,7 +48,7 @@
     protected static final char[] ESCAPED_CHARACTERS = { '+', '-', '&', '|', '!', '(', ')', '{',
         '}', '[', ']', '^', '"', '~', '*', '?', ':', '\\' };
 
-    private ServiceManager manager;
+    protected ServiceManager manager;
 
     public Object getAttribute(String name, Configuration modeConf, Map objectModel)
             throws ConfigurationException {
@@ -64,11 +68,21 @@
         if (searchTerm == null || searchTerm.trim().equals("")) {
             return "";
         }
+        
+        if (searchTerm.indexOf(' ') > -1) {
+            searchTerm = "(" + searchTerm + ")";
+        }
+
+        BooleanQuery query = getQuery(searchTerm);
+        return query.toString();
+    }
 
-        StringBuffer queryString = new StringBuffer();
+    protected BooleanQuery getQuery(String searchTerm) {
+        BooleanQuery query = new BooleanQuery();
 
         for (int i = 0; i < DEFAULT_FIELDS.length; i++) {
-            appendTerm(queryString, DEFAULT_FIELDS[i], searchTerm);
+            TermQuery termQuery = new TermQuery(getTerm(DEFAULT_FIELDS[i], searchTerm));
+            query.add(termQuery, false, false);
         }
 
         MetaDataRegistry registry = null;
@@ -83,7 +97,8 @@
                 for (int e = 0; e < elements.length; e++) {
                     if (elements[e].isSearchable()) {
                         String field = fieldRegistry.getFieldName(namespaces[n], elements[e].getName());
-                        appendTerm(queryString, field, searchTerm);
+                        TermQuery termQuery = new TermQuery(getTerm(field, searchTerm));
+                        query.add(termQuery, false, false);
                     }
                 }
             }
@@ -97,7 +112,7 @@
                 this.manager.release(fieldRegistry);
             }
         }
-        return queryString.toString();
+        return query;
     }
 
     protected boolean shallEscape(char c) {
@@ -123,16 +138,8 @@
         return builder.toString();
     }
     
-    protected void appendTerm(StringBuffer queryString, String field, String searchTerm) {
-        if (queryString.length() > 0) {
-            queryString.append(" OR ");
-        }
-        String term = getTerm(field, searchTerm);
-        queryString.append(term);
-    }
-
-    protected String getTerm(String field, String searchTerm) {
-        return escape(field) + ":" + searchTerm;
+    protected Term getTerm(String field, String value) {
+        return new Term(escape(field), value);
     }
 
     public void service(ServiceManager manager) throws ServiceException {

Modified: lenya/trunk/src/modules/lucene/resources/i18n/cmsui.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/resources/i18n/cmsui.xml?rev=641060&r1=641059&r2=641060&view=diff
==============================================================================
--- lenya/trunk/src/modules/lucene/resources/i18n/cmsui.xml (original)
+++ lenya/trunk/src/modules/lucene/resources/i18n/cmsui.xml Tue Mar 25 15:47:45 2008
@@ -34,6 +34,9 @@
   
   <message key="New Search Page">New Search Page</message>
   <message key="Re-Index Site">Re-Index Site</message>
-  <message key="re-index site?">Do you want to re-index all documents of this publication in the current area?</message>
+  <message key="re-index site?">Do you want to re-index all documents of this publication in the current area?</message>
+  
+  <message key="documents">Documents</message>
+  <message key="images">Images</message>
   
 </catalogue>

Modified: lenya/trunk/src/modules/lucene/resources/i18n/cmsui_de.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/resources/i18n/cmsui_de.xml?rev=641060&r1=641059&r2=641060&view=diff
==============================================================================
--- lenya/trunk/src/modules/lucene/resources/i18n/cmsui_de.xml (original)
+++ lenya/trunk/src/modules/lucene/resources/i18n/cmsui_de.xml Tue Mar 25 15:47:45 2008
@@ -37,5 +37,9 @@
   <message key="re-index site?">
     Wollen Sie alle Dokumente dieser Publikation in der aktuellen Area neu indexieren?
   </message>
+
+  <message key="documents">Dokumente</message>
+  <message key="images">Bilder</message>
+
 </catalogue>
 

Modified: lenya/trunk/src/modules/lucene/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/sitemap.xmap?rev=641060&r1=641059&r2=641060&view=diff
==============================================================================
--- lenya/trunk/src/modules/lucene/sitemap.xmap (original)
+++ lenya/trunk/src/modules/lucene/sitemap.xmap Tue Mar 25 15:47:45 2008
@@ -29,7 +29,6 @@
         <notify user="lenya"/>
       </map:transformer>
       <map:transformer name="cinclude" src="org.apache.cocoon.transformation.CIncludeTransformer"/>
-      <map:transformer name="uuid2url" src="org.apache.cocoon.transformation.UuidToUrlTransformer"/>
     </map:transformers>
 
   </map:components>
@@ -91,17 +90,28 @@
         <map:serialize type="xml"/>
       </map:match>
       
-      <!-- {1:pub}/{2:area}/{3:queryString} -->
-      <map:match pattern="search-generator/*/*/*">
-        <map:generate type="search">
-          <map:parameter name="index" value="{index-path:{1}-{2}}"/>
-          <map:parameter name="query" value="{queryString:queryString}"/>
-        </map:generate>
+      <!-- {1:pub}/{2:area} -->
+      <map:match pattern="search-generator/*/*">
+        <map:select type="parameter">
+          <map:parameter name="parameter-selector-test" value="{request-param:type}"/>
+          <map:when test="images">
+            <map:generate type="search">
+              <map:parameter name="index" value="{index-path:{1}-{2}}"/>
+              <map:parameter name="query" value="{imageQueryString:queryString}"/>
+            </map:generate>
+          </map:when>
+          <map:otherwise>
+            <map:generate type="search">
+              <map:parameter name="index" value="{index-path:{1}-{2}}"/>
+              <map:parameter name="query" value="{queryString:queryString}"/>
+            </map:generate>
+          </map:otherwise>
+        </map:select>
         <map:serialize type="xml"/>
       </map:match>
       
       <map:match pattern="search.xml">
-        <map:generate src="cocoon:/search-generator/{page-envelope:publication-id}/{page-envelope:area}/{request-param:queryString}"/>
+        <map:generate src="cocoon:/search-generator/{page-envelope:publication-id}/{page-envelope:area}"/>
         <map:transform src="fallback://lenya/modules/lucene/xslt/search2html.xsl">
           <map:parameter name="url" value="{page-envelope:document-url}"/>
           <map:parameter name="area" value="{page-envelope:area}"/>
@@ -109,13 +119,14 @@
           <map:parameter name="root" value="/{page-envelope:publication-id}/{page-envelope:area}"/>
           <map:parameter name="use-request-parameters" value="true"/>
           <map:parameter name="queryString" value="{request-param:queryString}"/>
+          <map:parameter name="type" value="{request-param:type}"/>
         </map:transform>
         <map:transform type="metaData">
           <map:parameter name="pubid" value="{page-envelope:publication-id}"/>
           <map:parameter name="area" value="{page-envelope:area}"/>
         </map:transform>
+        <map:transform src="fallback://lenya/modules/lucene/xslt/imageTitles.xsl"/>
         <map:transform type="cinclude"/>
-        <map:transform type="uuid2url"/>
         <map:serialize type="xml"/>
       </map:match>
       

Added: lenya/trunk/src/modules/lucene/xslt/imageTitles.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/xslt/imageTitles.xsl?rev=641060&view=auto
==============================================================================
--- lenya/trunk/src/modules/lucene/xslt/imageTitles.xsl (added)
+++ lenya/trunk/src/modules/lucene/xslt/imageTitles.xsl Tue Mar 25 15:47:45 2008
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+  xmlns:xhtml="http://www.w3.org/1999/xhtml">
+  
+  
+  <xsl:template match="xhtml:img[. != '']">
+    <xsl:copy>
+      <xsl:copy-of select="@*"/>
+      <xsl:attribute name="alt"><xsl:value-of select="."/></xsl:attribute>
+    </xsl:copy>
+  </xsl:template>
+  
+  
+  <xsl:template match="@*|node()" priority="-1">
+    <xsl:copy>
+      <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+  </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file

Modified: lenya/trunk/src/modules/lucene/xslt/search2html.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/xslt/search2html.xsl?rev=641060&r1=641059&r2=641060&view=diff
==============================================================================
--- lenya/trunk/src/modules/lucene/xslt/search2html.xsl (original)
+++ lenya/trunk/src/modules/lucene/xslt/search2html.xsl Tue Mar 25 15:47:45 2008
@@ -33,6 +33,16 @@
   <xsl:param name="root"/>
   <xsl:param name="lenya.usecase"/>
   <xsl:param name="queryString"/>
+  <xsl:param name="type"/>
+  
+  <xsl:variable name="selectedType">
+    <xsl:choose>
+      <xsl:when test="$type = 'images' or $type = 'documents'">
+        <xsl:value-of select="$type"/>
+      </xsl:when>
+      <xsl:otherwise>documents</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   
   <xsl:variable name="usecaseParam">
     <xsl:if test="$lenya.usecase != ''">
@@ -46,12 +56,36 @@
     <div id="body">
       <h1><i18n:text>Search</i18n:text></h1>
       <form class="search-results-form" action="" method="get">
-        <input name="queryString" type="text" style="width: 400px" value="{$queryString}"
-        />&#160;<input type="submit" name="submit" value="Search" i18n:attr="value"/>
+        <p>
+          <input name="queryString" type="text" style="width: 400px" value="{$queryString}"
+          />&#160;<input type="submit" name="submit" value="Search" i18n:attr="value"/>
+        </p>
+        <p>
+          <xsl:call-template name="type">
+            <xsl:with-param name="searchType">documents</xsl:with-param>
+          </xsl:call-template>
+          &#160;&#160;&#160;
+          <xsl:call-template name="type">
+            <xsl:with-param name="searchType">images</xsl:with-param>
+          </xsl:call-template>
+        </p>
       </form>
       <xsl:apply-templates select="search:hits"/>
     </div>
   </xsl:template>
+  
+  
+  <xsl:template name="type">
+    <xsl:param name="searchType"/>
+    <xsl:param name="default"/>
+    <input type="radio" name="type" value="{$searchType}">
+      <xsl:if test="$selectedType = $searchType">
+        <xsl:attribute name="checked">checked</xsl:attribute>
+      </xsl:if>
+    </input>
+    <i18n:text><xsl:value-of select="$searchType"/></i18n:text>
+  </xsl:template>
+  
 
   <xsl:template match="search:hits">
     <!--
@@ -75,10 +109,19 @@
         </xsl:otherwise>
       </xsl:choose>
     </h2>
-    <ul class="search-results">
-      <xsl:apply-templates/>
+    <ul class="search-results {$selectedType}">
+      <xsl:choose>
+        <xsl:when test="$selectedType = 'images'">
+          <xsl:apply-templates select="search:hit" mode="image"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:apply-templates select="search:hit" mode="document"/>
+        </xsl:otherwise>
+      </xsl:choose>
     </ul>
     
+    <hr style="clear: both; border: none;" size="0"/>
+    
     <xsl:variable name="pages" select="/search:results/search:navigation/search:navigation-page"/>
     <xsl:if test="count($pages) &gt; 1">
       <p>
@@ -121,8 +164,27 @@
     -->
   </xsl:template>
   
-  <xsl:template match="search:hit">
-    <li class="search-result">
+  
+  <xsl:template match="search:hit" mode="image">
+    <li>
+      <xsl:variable name="uuid" select="search:field[@name='uuid']"/>
+      <xsl:variable name="language" select="search:field[@name='language']"/>
+      <a href="lenya-document:{$uuid},lang={$language}?uuid2url.extension=html">
+        <img src="lenya-document:{$uuid},lang={$language}?lenya.module=svg&amp;height=100">
+          <meta:value element="title" ns="http://purl.org/dc/elements/1.1/" default="No Title"
+            i18n:attr="default" uuid="{$uuid}" lang="{$language}"/>
+        </img>
+      </a>
+      <div class="imageTitle">
+        <meta:value element="title" ns="http://purl.org/dc/elements/1.1/" default="No Title"
+          i18n:attr="default" uuid="{$uuid}" lang="{$language}"/>
+      </div>
+    </li>
+  </xsl:template>
+  
+  
+  <xsl:template match="search:hit" mode="document">
+    <li>
       <div class="search-result-rank"><xsl:value-of select="@rank + 1"/>. </div>
       <xsl:variable name="uuid" select="search:field[@name='uuid']"/>
       <xsl:variable name="language" select="search:field[@name='language']"/>
@@ -138,6 +200,7 @@
       </div>
     </li>
   </xsl:template>
+  
 
   <xsl:template name="navigation-paging-form">
     <xsl:param name="page-length"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org