[Yanel-commits] rev 43973 - 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 09:42:12 CEST 2009
Author: michi
Date: 2009-08-04 09:42:12 +0200 (Tue, 04 Aug 2009)
New Revision: 43973
Added:
public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/Result.java
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/SearchResource.java
Log:
Result class introduced and code refactored accordingly
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:09:34 UTC (rev 43972)
+++ public/yanel/trunk/src/contributions/resources/search/htdocs/results2xhtml.xsl 2009-08-04 07:42:12 UTC (rev 43973)
@@ -52,7 +52,7 @@
</xsl:template>
<xsl:template match="y:results">
- <h2>All Results</h2>
+ <h2>All Results (<a href="?q={../y:query}&yanel.resource.viewid=xml">as XML</a>)</h2>
<p>Provider: <xsl:value-of select="@provider"/></p>
<ul>
<xsl:apply-templates select="y:result"/>
@@ -60,7 +60,7 @@
</xsl:template>
<xsl:template match="y:result">
- <li><a href="{$yarep.back2realm}{@repo-path}"><xsl:value-of select="@repo-path"/></a></li>
+ <li><a href="{$yarep.back2realm}{@url}"><xsl:value-of select="@url"/></a></li>
</xsl:template>
<xsl:template match="y:exception">
Added: 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 (rev 0)
+++ 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)
@@ -0,0 +1,32 @@
+package org.wyona.yanel.impl.resources.search;
+
+/**
+ *
+ */
+public class Result {
+
+ private String url;
+ private String title;
+
+ /**
+ *
+ */
+ public Result(String url, String title) {
+ this.url = url;
+ this.title = title;
+ }
+
+ /**
+ * Get URL
+ */
+ public String getURL() {
+ return url;
+ }
+
+ /**
+ * Get title
+ */
+ public String getTitle() {
+ return title;
+ }
+}
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:09:34 UTC (rev 43972)
+++ 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)
@@ -32,16 +32,14 @@
if (query != null) {
sb.append("<y:query>" + query + "</y:query>");
try {
- org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().search(query);
- if (nodes != null && nodes.length > 0) {
- //sb.append("<provider source-name=\"" + "Wyona-FOAF" + "\" source-domain=\"" + "http://foaf.wyona.org" + "\" numberOfResults=\"" + pNodes.length + "\">");
+ Result[] results = getLocalResults(query);
sb.append("<y:results provider=\"google\">");
- for (int i = 0; i < nodes.length; i++) {
- sb.append("<y:result repo-path=\""+nodes[i].getPath()+"\">");
+ 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>");
}
sb.append("</y:results>");
- }
} catch(org.wyona.yarep.core.search.SearchException e) {
log.error(e, e);
sb.append("<y:exception>" + e.getMessage() + "</y:exception>");
@@ -50,4 +48,20 @@
sb.append("</y:search>");
return new ByteArrayInputStream(sb.toString().getBytes());
}
+
+ /**
+ *
+ */
+ private Result[] getLocalResults(String query) throws Exception {
+ org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().search(query);
+ 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");
+ }
+ return results;
+ } else {
+ return new Result[0];
+ }
+ }
}
More information about the Yanel-commits
mailing list