lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r709649 - in /lucene/solr/trunk/contrib/velocity: ./ src/main/java/ src/main/java/org/apache/solr/request/ src/main/solr/conf/velocity/
Date Sat, 01 Nov 2008 04:49:56 GMT
Author: ehatcher
Date: Fri Oct 31 21:49:56 2008
New Revision: 709649

URL: http://svn.apache.org/viewvc?rev=709649&view=rev
Log:
Wire in a SolrResourceLoader bridge for Velocity templates, allowing a JAR of templates to
live in conf/lib.  Refactored the footer.vm template to use this mechanism as an example.

Added:
    lucene/solr/trunk/contrib/velocity/src/main/java/footer.vm
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java
Removed:
    lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity/footer.vm
Modified:
    lucene/solr/trunk/contrib/velocity/build.xml
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java
    lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity/browse.vm

Modified: lucene/solr/trunk/contrib/velocity/build.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/build.xml?rev=709649&r1=709648&r2=709649&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/build.xml (original)
+++ lucene/solr/trunk/contrib/velocity/build.xml Fri Oct 31 21:49:56 2008
@@ -61,7 +61,9 @@
 
   <target name="build" depends="compile">
     <solr-jar destfile="src/main/solr/lib/${fullnamever}.jar" basedir="target/classes"
-              manifest="${common.dir}/${dest}/META-INF/MANIFEST.MF" />
+              manifest="${common.dir}/${dest}/META-INF/MANIFEST.MF">
+      <fileset dir="src/main/java" excludes="**/*.java"/>
+    </solr-jar>
   </target>
 
   <target name="compileTests" depends="compile">

Added: lucene/solr/trunk/contrib/velocity/src/main/java/footer.vm
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/footer.vm?rev=709649&view=auto
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/footer.vm (added)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/footer.vm Fri Oct 31 21:49:56 2008
@@ -0,0 +1,9 @@
+#if($params.getBool("debugQuery",false))
+<pre>
+  request = $request
+
+  response = $response.values
+</pre>
+#end
+
+Generated by <a href="http://wiki.apache.org/solr/VelocityResponseWriter">VelocityResponseWriter</a>
\ No newline at end of file

Modified: lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java?rev=709649&r1=709648&r2=709649&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java
(original)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java
Fri Oct 31 21:49:56 2008
@@ -30,6 +30,7 @@
 public class SolrParamResourceLoader extends ResourceLoader {
   private HashMap<String,String> templates = new HashMap();
   public SolrParamResourceLoader(SolrQueryRequest request) {
+    super();
 
     // TODO: Consider using content streams, but need a template name associated with each
stream
     // for now, a custom param convention of template.<name>=<template body>
is a nice example
@@ -44,7 +45,6 @@
         templates.put(name.substring(9) + ".vm",params.get(name));
       }
     }
-
   }
 
   public void init(ExtendedProperties extendedProperties) {

Added: lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java?rev=709649&view=auto
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java
(added)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java
Fri Oct 31 21:49:56 2008
@@ -0,0 +1,34 @@
+package org.apache.solr.request;
+
+import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.solr.core.SolrResourceLoader;
+
+import java.io.InputStream;
+
+// TODO: the name of this class seems ridiculous
+public class SolrVelocityResourceLoader extends ResourceLoader {
+  private SolrResourceLoader loader;
+
+  public SolrVelocityResourceLoader(SolrResourceLoader loader) {
+    super();
+    this.loader = loader;
+  }
+
+  public void init(ExtendedProperties extendedProperties) {
+  }
+
+  public InputStream getResourceStream(String template_name) throws ResourceNotFoundException
{
+    return loader.openResource(template_name);
+  }
+
+  public boolean isSourceModified(Resource resource) {
+    return false;
+  }
+
+  public long getLastModified(Resource resource) {
+    return 0;
+  }
+}

Modified: lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java?rev=709649&r1=709648&r2=709649&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java
(original)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java
Fri Oct 31 21:49:56 2008
@@ -49,8 +49,10 @@
       baseDir = new File(template_root);
     }
     engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, baseDir.getAbsolutePath());
-    engine.setProperty("params.resource.loader.instance",new SolrParamResourceLoader(request));
-    engine.setProperty(VelocityEngine.RESOURCE_LOADER, "params,file");
+    engine.setProperty("params.resource.loader.instance", new SolrParamResourceLoader(request));
+    engine.setProperty("solr.resource.loader.instance",
+        new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader()));
+    engine.setProperty(VelocityEngine.RESOURCE_LOADER, "params,file,solr");
 
     return engine;
   }

Modified: lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity/browse.vm
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity/browse.vm?rev=709649&r1=709648&r2=709649&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity/browse.vm (original)
+++ lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity/browse.vm Fri Oct 31 21:49:56
2008
@@ -44,19 +44,7 @@
 <div class="pagination">
   <span><span class="results-found">$page.results_found</span> results
found in ${response.responseHeader.QTime} ms</span>
 </div>
-#if (${nlResponse.suggestions.size()} > 0)
-<div class="spelling">
-  <span>Did you mean?</span>
-  #foreach ($suggestion in ${nlResponse.suggestions})
-  <a href="${request.requestURL}?q=${suggestion}">${suggestion}</a>#if ($velocityCount
< $nlResponse.suggestions.size()),#end
-  #end
-</div>
-#end
-#if (${nlResponse.autoSpell} == true)
-<div class="autoSpell">There were no results for your original query, so we automatically
searched a few spelling
-  variants: ${nlResponse.autoSpellQuery}
-</div>
-#end
+
 <div class="results">
   #foreach($id in $doclist.iterator())
     #set($doc = $searcher.doc($id,$response.returnFields))



Mime
View raw message