[Yanel-commits] rev 43974 - in public/yanel/trunk/src/contributions/resources/search: htdocs src/java/org/wyona/yanel/impl/resources/search

michi at wyona.com michi at wyona.com
Tue Aug 4 10:19:35 CEST 2009


Author: michi
Date: 2009-08-04 10:19:35 +0200 (Tue, 04 Aug 2009)
New Revision: 43974

Modified:
   public/yanel/trunk/src/contributions/resources/search/htdocs/results2xhtml.xsl
   public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/Result.java
   public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java
Log:
provider implemented

Modified: public/yanel/trunk/src/contributions/resources/search/htdocs/results2xhtml.xsl
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/htdocs/results2xhtml.xsl	2009-08-04 07:42:12 UTC (rev 43973)
+++ public/yanel/trunk/src/contributions/resources/search/htdocs/results2xhtml.xsl	2009-08-04 08:19:35 UTC (rev 43974)
@@ -34,17 +34,16 @@
         <h1>Search</h1>
 
         <form>
-          Your Search <input type="text" name="q" value="{/y:search/y:query}"/> <input type="submit" value="Search"/>
+          Search <input type="text" name="q" value="{/y:search/y:query}"/> with <select name="provider"><option value="google">Google</option><option value="bing">bing</option><option value="yanel" selected="true">IMS</option></select> &#160; <input type="submit" value="Search"/>
         </form>
 
         <hr/>
 
         <xsl:apply-templates select="/y:search/y:exception"/>
+        <p>Search results provider: <xsl:value-of select="/y:search/y:provider"/></p>
         <xsl:apply-templates select="/y:search/y:results"/>
         <xsl:if test="not(/y:search/y:results) and not(/y:search/y:exception)">
-<p>
-         Your search - <xsl:value-of select="/y:search/y:query"/> - did not match any documents
-</p>
+          <p>Your search - <xsl:value-of select="/y:search/y:query"/> - did not match any documents</p>
         </xsl:if>
 
       </body>
@@ -53,7 +52,6 @@
 
   <xsl:template match="y:results">
     <h2>All Results (<a href="?q={../y:query}&amp;yanel.resource.viewid=xml">as XML</a>)</h2>
-<p>Provider: <xsl:value-of select="@provider"/></p>
     <ul>
     <xsl:apply-templates select="y:result"/>
     </ul>

Modified: public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/Result.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/Result.java	2009-08-04 07:42:12 UTC (rev 43973)
+++ public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/Result.java	2009-08-04 08:19:35 UTC (rev 43974)
@@ -7,13 +7,17 @@
 
     private String url;
     private String title;
+    private String desc;
+    private String contentType;
 
     /**
-     *
+     * @param desc Description
      */
-    public Result(String url, String title) {
+    public Result(String url, String title, String desc, String contentType) {
         this.url = url;
         this.title = title;
+        this.desc = desc;
+        this.contentType = contentType;
     }
 
     /**
@@ -29,4 +33,18 @@
      public String getTitle() {
          return title;
      }
+
+    /**
+     * Get description
+     */
+     public String getDescription() {
+         return desc;
+     }
+
+    /**
+     * Get content type (for example text/html, application/xhtml+xml, etc.)
+     */
+     public String getContentType() {
+         return contentType;
+     }
 }

Modified: public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java	2009-08-04 07:42:12 UTC (rev 43973)
+++ public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java	2009-08-04 08:19:35 UTC (rev 43974)
@@ -29,17 +29,46 @@
         sb.append("<y:search xmlns:y=\"http://www.wyona.org/yanel/search/1.0\">");
 
         String query = getRequest().getParameter("q");
+        String provider = getRequest().getParameter("provider");
         if (query != null) {
             sb.append("<y:query>" + query + "</y:query>");
             try {
-                Result[] results = getLocalResults(query);
-                sb.append("<y:results provider=\"google\">");
-                for (int i = 0; i < results.length; i++) {
-                    sb.append("<y:result url=\"" + results[i].getURL() + "\">");
-                    sb.append("  <y:title>" + results[i].getTitle() + "</y:title>");
-                    sb.append("</y:result>");
+                Result[] results;
+                if (provider != null) {
+                    if (provider.equals("yanel")) {
+                        results = getLocalResults(query);
+                    } else if (provider.equals("google")) {
+                        log.warn("Provider '" + provider + "' not implemented yet!");
+                        results = new Result[0];
+                        log.warn("Provider '" + provider + "' not implemented yet!");
+                    } else if (provider.equals("bing")) {
+                        results = new Result[0];
+                        log.warn("Provider '" + provider + "' not implemented yet!");
+                    } else {
+                        results = getLocalResults(query);
+                        log.warn("No such provider: " + provider);
+                    }
+                } else {
+                    results = getLocalResults(query);
+                    provider = "yanel";
+                    log.warn("No search provider specified!");
                 }
-                sb.append("</y:results>");
+
+                sb.append("<y:provider>" + provider + "</y:provider>");
+
+                if (results != null && results.length > 0) {
+                    sb.append("<y:results>");
+                    for (int i = 0; i < results.length; i++) {
+                        sb.append("<y:result url=\"" + results[i].getURL() + "\">");
+                        if (results[i].getTitle() != null) {
+                            sb.append("  <y:title>" + results[i].getTitle() + "</y:title>");
+                        } else {
+                            sb.append("  <y:no-title/>");
+                        }
+                        sb.append("</y:result>");
+                    }
+                    sb.append("</y:results>");
+                }
             } catch(org.wyona.yarep.core.search.SearchException e) {
                 log.error(e, e);
                 sb.append("<y:exception>" + e.getMessage() + "</y:exception>");
@@ -57,11 +86,18 @@
         if (nodes != null && nodes.length > 0) {
             Result[] results = new Result[nodes.length];
             for (int i = 0; i < nodes.length; i++) {
-                results[i] = new Result(nodes[i].getPath(), "TODO");
+                results[i] = new Result(nodes[i].getPath(), null, null, nodes[i].getMimeType());
             }
             return results;
         } else {
             return new Result[0];
         }
     }
+
+    /**
+     * @see ViewableV2#exists()
+     */
+    public boolean exists() {
+        return true;
+    }
 }



More information about the Yanel-commits mailing list