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/01/28 20:00:55 UTC

[Solr Wiki] Update of "DataImportHandler" by EdwardRudd

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 EdwardRudd:
http://wiki.apache.org/solr/DataImportHandler

The comment on the change is:
documented on removing entries from row and using arrays for ScriptTransformer

------------------------------------------------------------------------------
  </dataConfig>
  }}}
  
+ Another more complex example
+ {{{
+ <dataConfig>
+ 	<script><![CDATA[
+ 		function CategoryPieces(row)	{
+ 		    var pieces = row.get('category').split('/');
+                     var arr = new java.util.ArrayList();
+ 		    for (var i=0; i<pieces.length; i++) {
+                        arr.add(pieces[i]);
+                     }
+                     row.put('categorypieces', arr);
+                     row.remove('category');
+                     return row;
+ 		}
+ 	]]></script>
+ 	<document>
+ 		<entity name="e" pk="id" transformer="script:CategoryPieces" query="select * from X">
+                 ....
+                 </entity>
+         </document>
+ </dataConfig>
+ }}}
+ 
   * You can put a script tag inside the ''dataConfig'' node. By default, the language is assumed to be Javascript. In case you're using another language, specify on the script tag with attribute `'language="MyLanguage"'` (must be supported by java 6)
   * Write as many transformer functions as you want to use. Each such function must accept a ''row'' variable corresponding to ''Map<String, Object>'' and return a row (after applying transformations)
+  * To remove entries from the row use row.remove(keyname);
+  * To add multiple entries for a single field use var arr = new java.util.ArrayList(), you can't use a JavaScript array.
+  * Documentation for the Java Map object [http://java.sun.com/javase/6/docs/api/java/util/Map.html Java 6 Map]
+  * Documentation for the Java ArrayList object [http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html Java 6 ArrayList]
   * Make an entity use a function by specifying ''transformer="script:<function-name>"'' in the ''entity'' node.
   * In the above data-config, the javascript function ''f1'' will be executed once for each row returned by entity e.
   * The semantics of execution is same as that of a java transformer. The method can have two arguments as in 'transformRow(Map<String,Object> , Context context) in the abstract class 'Transformer' . As it is javascript the second argument may be omittted and it still works.
+ 
  [[Anchor(DateFormatTransformer)]]
  === DateFormatTransformer ===
  There is a built-in transformer called the !DateFormatTransformer which is useful for parsing date/time strings into java.util.Date instances.

Re: [Solr Wiki] Update of "DataImportHandler" by EdwardRudd

Posted by Noble Paul നോബിള്‍ नोब्ळ् <no...@gmail.com>.
Thanks Edward. Good addition.
I didn't know there are users for javascript . So I was lazy to document it
--Noble

On Thu, Jan 29, 2009 at 12:30 AM, Apache Wiki <wi...@apache.org> wrote:
> 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 EdwardRudd:
> http://wiki.apache.org/solr/DataImportHandler
>
> The comment on the change is:
> documented on removing entries from row and using arrays for ScriptTransformer
>
> ------------------------------------------------------------------------------
>  </dataConfig>
>  }}}
>
> + Another more complex example
> + {{{
> + <dataConfig>
> +       <script><![CDATA[
> +               function CategoryPieces(row)    {
> +                   var pieces = row.get('category').split('/');
> +                     var arr = new java.util.ArrayList();
> +                   for (var i=0; i<pieces.length; i++) {
> +                        arr.add(pieces[i]);
> +                     }
> +                     row.put('categorypieces', arr);
> +                     row.remove('category');
> +                     return row;
> +               }
> +       ]]></script>
> +       <document>
> +               <entity name="e" pk="id" transformer="script:CategoryPieces" query="select * from X">
> +                 ....
> +                 </entity>
> +         </document>
> + </dataConfig>
> + }}}
> +
>   * You can put a script tag inside the ''dataConfig'' node. By default, the language is assumed to be Javascript. In case you're using another language, specify on the script tag with attribute `'language="MyLanguage"'` (must be supported by java 6)
>   * Write as many transformer functions as you want to use. Each such function must accept a ''row'' variable corresponding to ''Map<String, Object>'' and return a row (after applying transformations)
> +  * To remove entries from the row use row.remove(keyname);
> +  * To add multiple entries for a single field use var arr = new java.util.ArrayList(), you can't use a JavaScript array.
> +  * Documentation for the Java Map object [http://java.sun.com/javase/6/docs/api/java/util/Map.html Java 6 Map]
> +  * Documentation for the Java ArrayList object [http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html Java 6 ArrayList]
>   * Make an entity use a function by specifying ''transformer="script:<function-name>"'' in the ''entity'' node.
>   * In the above data-config, the javascript function ''f1'' will be executed once for each row returned by entity e.
>   * The semantics of execution is same as that of a java transformer. The method can have two arguments as in 'transformRow(Map<String,Object> , Context context) in the abstract class 'Transformer' . As it is javascript the second argument may be omittted and it still works.
> +
>  [[Anchor(DateFormatTransformer)]]
>  === DateFormatTransformer ===
>  There is a built-in transformer called the !DateFormatTransformer which is useful for parsing date/time strings into java.util.Date instances.
>



-- 
--Noble Paul