On Tue, 2007-01-16 at 16:19 -0500, Walter Lewis wrote:
> [EMAIL PROTECTED] wrote:
> > Any ideas on how to implement a cocoon layer above solr?

I just finished a forrest plugin (in the whiteboard, our testing ground
in forrest) that is doing what you asked for and some pagination.
Forrest is cocoon based so you just have to build the plugin jar and add
it to your cocoon project. Please ask on the forrest list if you have
problems.

http://forrest.apache.org/pluginDocs/plugins_0_80/org.apache.forrest.plugin.output.solr/

> You're far from the only one approaching solr via cocoon ... :)
> 
> The approach we took, passes the search parameters to a "solrsearch" 
> stylesheet, the heart of which is a <cinclude> block that embeds the 
> solr results.  A further transformation prepares the results of the solr 
> query for display.

That was my first version for above plugin as well, but since forrest
makes use of the cocoon crawler I needed something with a default search
string for offline generation.

You should have a closer look on 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/output.xmap?view=markup
and 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/input.xmap?view=markup

For the original use case of this thread I added a generator:

<map:generator name="solr-search"
        logger="sitemap.generator.searchgenerator"
        src="org.apache.forrest.solr.client.SolrSearchGenerator" />

and as well a paginator transformer that calculates the next pages based on 
start, rows and numFound:

 <map:transformer logger="sitemap.transformer.solr" name="solr" pool-max="16" 
        src="org.apache.forrest.solr.client.SolrQueryTransformer" />

We use it as follows:

<!-- Will dispatch a query against the solr server -->
      <map:match pattern="solr-search.xml">
        <map:generate type="solr-search">
<!-- You would replace this with your own. In forrest we have a property system 
for that
<property name="solr.select.url" value="http://localhost:8983/solr/select"/>
-->
          <map:parameter name="destinationUrl" 
value="{properties:solr.select.url}"/>
        </map:generate>
<!-- here we add the pagination to the sax from the generator will result in 
something like:
...
<result name="response" numFound="17" start="0">
 <paginator found="17" start="0" rows="10" pages="2">
  <page id="1" 
queryString="q=forrest&amp;hl=true&amp;rows=10&amp;version=2.2&amp;indent=on&amp;hl.fl=content&amp;fl=id,title&amp;Search=Search&amp;start=0"
 current="true"/>
  <page id="2" 
queryString="q=forrest&amp;hl=true&amp;rows=10&amp;version=2.2&amp;indent=on&amp;hl.fl=content&amp;fl=id,title&amp;Search=Search&amp;start=10"/>
 </paginator> 
<doc> 
...-->
        <map:transform type="solr"/>
<!-- here we transform the solr response into xdocs (forrest internal format)
the pagination:
<xsl:template match="paginator">
<section>
      <title>Result pages</title>
      <p>
        <xsl:for-each select="page">
          <xsl:variable name="current" select="@current"/>
          <xsl:choose>
            <xsl:when test="$current='true'">
              <xsl:text> </xsl:text><xsl:value-of select="@id"/><xsl:text> 
</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <a href="{concat($searchForm,'?',@queryString)}">
                <xsl:value-of select="@id"/>
              </a>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </p>
    </section>
  </xsl:template>
-->
        <map:transform src="resources/stylesheets/solrQueryResult-to-xdocs.xsl">
          <map:parameter name="searchForm" value="{request:servletPath}"/>
        </map:transform>
        <map:serialize type="xml"/>
      </map:match>

You may be interested in the update generator as well. 

Please give feedback to [EMAIL PROTECTED] 

It really needs more testing besides myself, you could be the first to provide 
feedback.

<map:generator name="solrUpdate"
        src="org.apache.forrest.solr.client.SolrUpdateGenerator"/>

<!-- Update generator will send the command to the solr server and
        generate the server response -->
      <map:match pattern="**.do">
        <map:generate type="solrUpdate" src="cocoon:/{1}">
          <map:parameter name="destinationUrl" 
value="{properties:solr.update.url}"/>
        </map:generate>
        <map:serialize type="xml"/>
      </map:match>

HTH

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)


Reply via email to