You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2009/05/06 07:54:30 UTC

[Solr Wiki] Update of "DataImportHandler" by NoblePaul

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The following page has been changed by NoblePaul:
http://wiki.apache.org/solr/DataImportHandler

The comment on the change is:
Functions documentation

------------------------------------------------------------------------------
   * ''escapeSql'' : Use this to escape special sql characters . eg : `'${dataimporter.functions.escapeSql(item.ID)}'`. Takes only one argument and must be a valid value in the !VaraiableResolver.
   * ''encodeUrl'' : Us this to encode urls . eg : `'${dataimporter.functions.encodeUrl(item.ID)}'` . Takes only one argument and must be a valid value in the !VariableResolver
  
+ ==== Custom Functions ====
+ It is possible to plug in custom functions into DIH. Implement an [http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/Evaluator.java?view=markup Evalutor] and specify it in the data-config.xml . Following is an example of an evaluator which does a 'toLowerCase' on a String.
+ {{{
+ <dataConfig>
+    <function name="toLowerCase" class="foo.LowerCaseFunctionEvaluator"/>
+    <document>
+    <entity query="select * from table where name='${dataimporter.functions.toLowerCase(dataimporter.request.user)'">
+     <!- ......field declarations......->
+    </entity> 
+ </dataConfig>
+ }}}
+ 
+ The implementation of !LowerCaseFunctionEvaluator
+ {{{
+   public class LowerCaseFunctionEvaluator implements Evaluator{
+     public String evaluate(String expression, Context context) {
+       List l = EvaluatorBag.parseParams(expression, context.getVariableResolver());
+ 
+       if (l.size() != 1) {
+           throw new RuntimeException("'toLowerCase' must have only one parameter ");
+       }
+       return l.get(0).toString().toLowerCase();
+       
+     }
+ 
+   }
+ }}}
+ 
  === Accessing request parameters ===
  The parameters passed over the http request can be accessed  using the 'request' namespace eg: `'${dataimporter.request.command}'` will return the command that was run. Any extra parameter can be accessed using this
  [[Anchor(interactive)]]