[Yanel-commits] rev 20896 - in public/yanel/trunk/src/contributions/resources/nutch: conf src/java/org/wyona/yanel/impl/resources xslt

michi at wyona.com michi at wyona.com
Fri Dec 15 12:42:58 CET 2006


Author: michi
Date: 2006-12-15 12:42:56 +0100 (Fri, 15 Dec 2006)
New Revision: 20896

Modified:
   public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties
   public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties
   public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
   public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl
Log:
paging fixed

Modified: public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties	2006-12-15 11:42:21 UTC (rev 20895)
+++ public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties	2006-12-15 11:42:56 UTC (rev 20896)
@@ -2,10 +2,10 @@
 resultsForQuery = Suchergebnisse:
 searchFor = Suche nach ...
 results = Treffer
-ofAbout = (von insgesamt 
-hitsFound =  gefundenen Treffern)
+ofAbout = von insgesamt
+hitsFound = gefundenen Treffern
 for = von
-viewResultsAsXml = Ergebnisse als XML sehen
+viewResultsAsXml = Als XML anzeigen
 yourSearch = Ihre Suche
 didNotMatchAnyDocuments = hat keine Ergebnisse ergeben.
 pages = Seite

Modified: public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties	2006-12-15 11:42:21 UTC (rev 20895)
+++ public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties	2006-12-15 11:42:56 UTC (rev 20896)
@@ -2,10 +2,10 @@
 resultsForQuery = Results for query:
 searchFor = Search for ...
 results = Hits
-ofAbout = (of about 
-hitsFound =  total hits)
+ofAbout = of about
+hitsFound = total hits
 for = for
-viewResultsAsXml = View results as XML
+viewResultsAsXml = View as XML
 yourSearch = Your search
 didNotMatchAnyDocuments = did not match any documents.
 pages = page(s)

Modified: public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java	2006-12-15 11:42:21 UTC (rev 20895)
+++ public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java	2006-12-15 11:42:56 UTC (rev 20896)
@@ -25,7 +25,10 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.xml.parsers.DocumentBuilder;
@@ -88,7 +91,9 @@
     private String localFile = "nutch-local.xml";
     private Path path = null;
     private Repository repository  = null;
-    private String language = "en";
+    private String language = "";
+    private String defaultLanguage = "en";
+    private String searchTerm = "";
     private String show = "";//default is empty, else show either CACHE, EXPLAIN, ANCHORS
     private String resourceBundle = "nutch";
     private RepoPath rp = null;
@@ -115,23 +120,22 @@
      * 
      */
     public View getView(Path path, String viewId) {
-        return getView(path, viewId, "NO_SEARCH_TERM", start, hitsPerPage, language, show, 0, 0);
+        return getView(path, viewId, 0, 0);
     }
 
     /**
      * 
      */
-    public View getView(Path path, String viewId, String searchTerm, int start, int hitsPerPage, String language, String show, int idx, int id) {
+    public View getView(Path path, String viewId, int idx, int id) {
         View nutchView = null;
         this.path = path;
-        this.language = language;
         try {
             rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()),
                     getRepositoryFactory());
             repository = rp.getRepo();
             resourceBundle = getMessageBundle(path);
             nutchView = new View();
-            nutchView.setInputStream(getInputStream(searchTerm, start, hitsPerPage, viewId, language, show, idx, id));
+            nutchView.setInputStream(getInputStream(viewId, show, idx, id));
             if("cache".equals(show)) {
                 nutchView.setMimeType(cachedMimeType);
             } else if("explain".equals(show) || "anchors".equals(show))  {
@@ -157,22 +161,22 @@
         servletContext = request.getSession().getServletContext();
         int _start = 0;
         try {
-            _start = Integer.parseInt(request.getParameter("start"));
+            start = Integer.parseInt(request.getParameter("start"));
         } catch(Exception e) {
-            _start = start;
+            start = _start;
         }
-        int _hitsPerPage = 0;
+        int _hitsPerPage = 10;
         try {
-            _hitsPerPage = Integer.parseInt(request.getParameter("hitsPerPage"));
+            hitsPerPage = Integer.parseInt(request.getParameter("hitsPerPage"));
         } catch(Exception e) {
-            _hitsPerPage = hitsPerPage;
+            hitsPerPage = _hitsPerPage;
         }
         String _language = language;
         try {
-            _language = request.getParameter("yanel.meta.language");
+            language = request.getParameter("yanel.meta.language");
         } catch(Exception e) {
             //use fallback language
-            _language = language;
+            language = _language;
         }
         int idx = 0;
         try {
@@ -186,8 +190,10 @@
         } catch(Exception e) {
             id = 0;
         }
-        if(_language == null || ("").equals(_language)) _language = language;
-        return getView(new Path(request.getServletPath()), viewId, request.getParameter("query"), _start, _hitsPerPage, _language, request.getParameter("show"), idx, id);
+        show = request.getParameter("show");
+        searchTerm = request.getParameter("query");
+        if(language == null || ("").equals(language)) language = defaultLanguage;
+        return getView(new Path(request.getServletPath()), viewId, idx, id);
     }
 
     /**
@@ -248,7 +254,7 @@
     /**
      * Generate result XML
      */
-    private InputStream getInputStream(String searchTerm, int start, int hitsPerPage, String viewId, String language, String show, int idx, int id) {
+    private InputStream getInputStream(String viewId, String show, int idx, int id) {
         setupDocument(searchTerm);
         if("cache".equals(show)){
             return new StringBufferInputStream(createCachedDocument4SearchResult(idx, id));
@@ -304,7 +310,6 @@
         StreamSource streamSource = null;
         try {
             streamSource = getXSLTStreamSource(path, repository);
-            log.error("streamSource: " + streamSource);
             if(streamSource != null) {
                 transformer = TransformerFactory.newInstance().newTransformer(streamSource);
                 transformer.setParameter("yanel.path.name", path.getName());
@@ -320,6 +325,7 @@
                 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                 transformer.transform(new StreamSource(inputStream), new StreamResult(byteArrayOutputStream));
                 inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+                log.error("language: " + language);
                 i18nTransformer = new I18nTransformer(resourceBundle, language);
                 SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
                 saxParser.parse(inputStream, i18nTransformer);
@@ -386,12 +392,12 @@
             String content = "<html xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " +
                     "xmlns=\"http://www.w3.org/1999/xhtml\">" +
                     "<head><title><i18n:message key=\"scoreExplanation\"/>: " + searchTerm + "</title></head>" +
-                    "<body><table id=\"results\"><tr><td>" +
+                    "<body><div id=\"results\">" +
                     "<h3><i18n:message key=\"page\"/></h3>" +
                     replaceAmpersand(nutchBean.getDetails(hit).toHtml()) + 
                     "<h3><i18n:message key=\"scoreForQuery\"/>" + query + "</h3>" + 
                     nutchBean.getExplanation(query, hit) + 
-                    "</td></tr></table></body></html>"; 
+                    "</div></body></html>"; 
             I18nTransformer i18nTransformer = new I18nTransformer(resourceBundle, language);
             SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
             saxParser.parse(new StringBufferInputStream(content), i18nTransformer);
@@ -425,12 +431,12 @@
             String content = "<html xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " +
                     "xmlns=\"http://www.w3.org/1999/xhtml\">" +
                     "<head><title><i18n:message key=\"anchors\"/>: " + searchTerm + "</title></head>" +
-                    "<body><table id=\"results\"><tr><td><h3><i18n:message key=\"anchors\"/></h3>" +
-                    replaceAmpersand(details.getValue("url")) + 
-                    "<ul>" + 
-                    listItems +
-                    "</ul>" +
-                    "</td></tr></table></body></html>"; 
+                    "<body><div id=\"results\"><h3><i18n:message key=\"anchors\"/></h3>" +
+                    replaceAmpersand(details.getValue("url"));
+            if(anchors != null) {
+                content += "<ul>" + listItems + "</ul>"; 
+            }
+            content += "</div></body></html>"; 
             log.error("content:\n" + content);
             I18nTransformer i18nTransformer = new I18nTransformer(resourceBundle, language);
             SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
@@ -481,6 +487,11 @@
                 log.warn(exceptionMessage);
                 return;
             } else {
+                /**FIXME: add owl as well */
+                
+                getRefineList();
+                
+                
                 nutchBean = new NutchBean(configuration);
                 Query query = Query.parse(searchTerm, configuration);
                 Hits hits = nutchBean.search(query, totalHitCount);
@@ -549,6 +560,37 @@
             log.error(e.getMessage(), e);
         }
     }
+    
+    private List getRefineList() {
+        org.apache.nutch.ontology.Ontology ontology = null;
+        try {
+            // Configuration nutchConf = NutchConfiguration.get(application);
+            String urls = configuration.get("extension.ontology.urls");
+            log.error("URLS__> " + urls);
+            ontology = new org.apache.nutch.ontology.OntologyFactory(configuration).getOntology();
+            if (urls==null || urls.trim().equals("")) {
+                // ignored siliently
+            } else {
+                log.error("is ontology null? : " + ontology);
+                ontology.load(urls.split("\\s+"));
+            }
+        } catch (Exception e) {
+            // ignored siliently
+            log.error("BLOODCLOT: " + e.getMessage(), e);
+        }
+         
+        List refineList = new ArrayList();
+        if (ontology != null) {
+            Iterator iter = ontology.subclasses(searchTerm);
+            while (iter.hasNext()) {
+                String nextItem = (String)iter.next();
+                log.error("iterating: --> " + nextItem);  
+                // refineList.add((String)iter.next());
+                refineList.add(nextItem);
+            }
+        }
+        return refineList;
+    }
 
     /**
      * 
@@ -584,7 +626,7 @@
             while ((xsltPath = br.readLine()) != null) {
                 if (xsltPath.indexOf("xslt:") == 0) {
                     xsltPath = xsltPath.substring(6);
-                    log.error("XSLT Path: " + xsltPath);
+                    log.debug("XSLT Path: " + xsltPath);
                     return new Path(xsltPath);
                 }
             }
@@ -613,11 +655,11 @@
             while ((xsltPath = br.readLine()) != null) {
                 if (xsltPath.indexOf("messageBundle:") == 0) {
                     xsltPath = xsltPath.substring(15);
-                    log.error("messageBundle: " + xsltPath);
+                    log.debug("messageBundle: " + xsltPath);
                     return xsltPath;
                 }
             }
-            log.error("messageBundle within rti: " + rpRTI.getPath());
+            log.debug("messageBundle within rti: " + rpRTI.getPath());
         } catch (Exception e) {
             log.warn(e);
         }

Modified: public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl	2006-12-15 11:42:21 UTC (rev 20895)
+++ public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl	2006-12-15 11:42:56 UTC (rev 20896)
@@ -35,12 +35,21 @@
     <body>
     <span id="pageInfo" itemsPerPage="{$hitsPerPage}"/>
     <form name="search">
-    <p>
-      <input type="text" name="query" value="{$query}"/>
-      <input type="hidden" name="yanel.meta.language" value="{$yanel.meta.language}"/>
-      <input type="hidden" name="totalHits" value="{$totalHits}"/>
-      <input type="submit" name="submit" value="i18n:attr key=search"/>
-    </p>
+      <table width="100%">
+        <tr>
+          <td>
+            <input type="text" name="query" value="{$query}"/>
+            <input type="hidden" name="yanel.meta.language" value="{$yanel.meta.language}"/>
+            <input type="hidden" name="totalHits" value="{$totalHits}"/>
+            <input type="submit" name="submit" value="i18n:attr key=search"/>
+          </td>
+          <td align="right">
+            <font size="-2">
+              <a href="?query={$query}&amp;hitsPerPage={$hitsPerPage}&amp;start={number(@yanel:start)}&amp;yanel.resource.viewid=source"><i18n:message key="viewResultsAsXml"/></a>
+            </font>
+          </td>
+        </tr>
+      </table>
     </form>
     
     <p>
@@ -66,7 +75,7 @@
   </xsl:template>
   
   <xsl:template match="yanel:no-query" mode="title">
-    <i18n:message key="resultsForQuery"/>
+    <i18n:message key="resultsForQuery"/><xsl:value-of select="."/>
   </xsl:template>
   
   <xsl:template match="yanel:results">
@@ -85,8 +94,7 @@
           <td colspan="2"><hr/></td>
         </tr>
         <tr>
-          <td width="50%"></td>
-          <td align="right">
+          <td align="right" colspan="2">
             <font size="-1">
               <i18n:message key="results"/>&#160;<b><xsl:value-of select="number(@yanel:start + 1)"/></b>- 
               
@@ -96,10 +104,7 @@
                   <xsl:otherwise><xsl:value-of select="number(@yanel:start + $hitsPerPage)" /></xsl:otherwise>
                 </xsl:choose>
               </xsl:variable>
-              <b><xsl:value-of select="$maxHit"/></b>&#160;<i18n:message key="ofAbout"/>&#160;
-              <b><xsl:value-of select="number(@yanel:totalHits)"/></b>&#160;<i18n:message key="for"/>&#160; 
-              <b><xsl:value-of select="$query"/></b><br/>
-              <a href="?query={$query}&amp;hitsPerPage={$hitsPerPage}&amp;start={number(@yanel:start)}&amp;yanel.resource.viewid=source"><i18n:message key="viewResultsAsXml"/></a>
+              <b><xsl:value-of select="$maxHit"/></b>&#160;<i18n:message key="ofAbout"/>&#160;<b><xsl:value-of select="number(@yanel:totalHits)"/></b>&#160;<i18n:message key="hitsFound"/>&#160;<i18n:message key="for"/>&#160;<b><xsl:value-of select="$query"/></b><br/>
             </font>
           </td>
         </tr>
@@ -117,7 +122,7 @@
             </td>
           </tr>
         </xsl:when>
-        <xsl:when test="$query = ''"><!-- if no query inserted show empty form --></xsl:when>
+        <xsl:when test="$query = ''"></xsl:when>
         <xsl:otherwise>
           <tr>
             <td colspan="2">
@@ -224,20 +229,14 @@
   
   <xsl:template match="yanel:exception">
     <tr>
-        <td colspan="2">
-          <div style="color: red; font-size: 24px;"><i18n:message key="exception"/></div> 
-          <xsl:variable name="message"><xsl:value-of select="substring-before(string(.), '#')"/></xsl:variable>
-          <xsl:variable name="directory"><xsl:value-of select="substring-after(string(.), '#')"/></xsl:variable>
-          <i18n:message key="{$message}"/><xsl:value-of select="$directory"/>
-          <xsl:value-of select="."/>
-        </td>
-      </tr>
-  <!--   <p>
-       <div style="color: red; font-size: 24px;"><i18n:message key="exception"/></div> 
-       <xsl:variable name="message"><xsl:value-of select="substring-before(string(.), '#')"/></xsl:variable>
-       <xsl:variable name="directory"><xsl:value-of select="substring-after(string(.), '#')"/></xsl:variable>
-       <i18n:message key="{$message}"/><xsl:value-of select="$directory"/>
-    </p> -->
+      <td colspan="2">
+        <div style="color: red; font-size: 24px;"><i18n:message key="exception"/></div>
+        <xsl:variable name="message"><xsl:value-of select="substring-before(string(.), '#')"/></xsl:variable>
+        <xsl:variable name="directory"><xsl:value-of select="substring-after(string(.), '#')"/></xsl:variable>
+        <i18n:message key="{$message}"/><xsl:value-of select="$directory"/>
+        <xsl:value-of select="."/>
+      </td>
+    </tr>
   </xsl:template>
 
 </xsl:stylesheet>




More information about the Yanel-commits mailing list