You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Erik Hatcher (JIRA)" <ji...@apache.org> on 2015/11/09 22:20:11 UTC

[jira] [Comment Edited] (SOLR-7915) Provide pluggable Velocity context tool facility

    [ https://issues.apache.org/jira/browse/SOLR-7915?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14997371#comment-14997371 ] 

Erik Hatcher edited comment on SOLR-7915 at 11/9/15 9:19 PM:
-------------------------------------------------------------

I just tested this, thanks for asking [~arafalov] (on a clean branch_5x checkout) - 

{code}
bin/solr create -c files -d example/files
bin/post -c files ~/Documents/TestDocs
curl http://localhost:8983/solr/files/config -H 'Content-type:application/json' -d '{
  "add-queryresponsewriter":{
    "name":"celeritas",
    "class":"solr.VelocityResponseWriter",
    "params.resource.loader.enabled": "true",
    "tools":{
      "just_a_string":"java.lang.String"
    }
  }
}'
{code}

It modifies configoverlay.json with:
{code}
{"queryResponseWriter":{"celeritas":{
      "name":"celeritas",
      "class":"solr.VelocityResponseWriter",
      "params.resource.loader.enabled":"true",
      "tools":{"just_a_string":"java.lang.String"}}}}
{code}

And that behaves as expected leveraging the new tool, http://localhost:8983/solr/files/select?q=*:*&wt=celeritas&v.template=foo&v.template.foo=$response.results.numFound:%20(and%20btw:%20just_a_string.class%20=%20$just_a_string.class) responds with:

{code}
328: (and btw: just_a_string.class = class java.lang.String)
{code}

The example really is a glorified version of outputting, through a Velocity template (provided in the request, and enabled by params resource loader), $just_a_string.class, showing that the tool $just_a_string was created and methods can be called on it.


was (Author: ehatcher):
I just tested this, thanks for asking [~arafalov] (on a clean branch_5x checkout) - 

{code}
bin/solr create -c files -d example/files
bin/post -c files ~/Documents/TestDocs
curl http://localhost:8983/solr/files/config -H 'Content-type:application/json' -d '{
  "add-queryresponsewriter":{
    "name":"celeritas",
    "class":"solr.VelocityResponseWriter",
    "params.resource.loader.enabled": "true",
    "tools":{
      "just_a_string":"java.lang.String"
    }
  }
}'
{code}

It modifies configoverlay.json with:
{code}
{"queryResponseWriter":{"celeritas":{
      "name":"celeritas",
      "class":"solr.VelocityResponseWriter",
      "params.resource.loader.enabled":"true",
      "tools":{"just_a_string":"java.lang.String"}}}}
{code}

And that behaves as expected leveraging the new tool, http://localhost:8983/solr/files/select?q=*:*&wt=celeritas&v.template=foo&v.template.foo=$response.results.numFound:%20(and%20btw:%20just_a_string.class%20=%20$just_a_string.class) responds with:

{code}
328: (and btw: just_a_string.class = class java.lang.String)
{code}


> Provide pluggable Velocity context tool facility
> ------------------------------------------------
>
>                 Key: SOLR-7915
>                 URL: https://issues.apache.org/jira/browse/SOLR-7915
>             Project: Solr
>          Issue Type: Improvement
>          Components: contrib - Velocity
>    Affects Versions: 5.3
>            Reporter: Erik Hatcher
>            Assignee: Erik Hatcher
>             Fix For: 5.4, Trunk
>
>         Attachments: SOLR-7915.patch
>
>
> Currently the "tools" placed in the VelocityResponseWriter's context are hard-coded.  It can be very handy to be able to plug in 3rd party or custom tools (just any ol' Java object a "tool" can be).
> Here's a list of the currently hard-coded tools: https://github.com/apache/lucene-solr/blob/trunk/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java#L189-L199
> ----
> The implementation committed allows custom tools to be registered as part of the VelocityResponseWriter definition in solrconfig.xml like this:
> {code}
>         <queryResponseWriter name="velocityWithCustomTools" class="solr.VelocityResponseWriter">
>           <lst name="tools">
>             <str name="mytool">com.example.solr.velocity.MyTool</str>
>             <!-- ... -->
>           </lst>
>         </queryResponseWriter>
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org