lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Solr Wiki] Trivial Update of "DataImportHandler" by KojiSekiguchi
Date Sat, 11 Dec 2010 13:40:18 GMT
Dear Wiki user,

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

The "DataImportHandler" page has been changed by KojiSekiguchi.
http://wiki.apache.org/solr/DataImportHandler?action=diff&rev1=275&rev2=276

--------------------------------------------------

  A !VariableResolver is the component which replaces all those placeholders such as `${<name>}`.
It is a multilevel Map.  Each namespace is a Map and namespaces are separated by periods (.)
. eg if there is a placeholder ${item.ID} , 'item' is a nampespace (which is a map) and 'ID'
is a value in that namespace. It is possible to nest namespaces like ${item.x.ID} where x
could be another Map. A reference to the current !VariableResolver can be obtained from the
Context. Or the object can be directly consumed by using ${<name>} in 'query' for RDMS
queries or 'url' in Http .
  === Custom formatting in query and url using Functions ===
  While the namespace concept is useful , the user may want to put some computed value into
the query or url for example there is a Date object and your datasource  accepts Date in some
custom format . There are a few functions provided by the !DataImportHandler which can do
some of these.
-  * ''formatDate'' : It is used like this `'${dataimporter.functions.formatDate(item.ID,
'yyyy-MM-dd HH:mm')}'` . The first argument can be a valid value from the !VariableResolver
and the second cvalue can be a a format string (use !SimpledateFormat) . The first argument
can be a computed value eg: `'${dataimporter.functions.formatDate('NOW-3DAYS', 'yyyy-MM-dd
HH:mm')}'` and it uses the syntax of the datemath parser in Solr. (note that it must enclosed
in single quotes) . <!> Note . This syntax has been changed in 1.4 . The second parameter
was not enclosed in single quotes earlier. But it will continue to work without single quote
also.
+  * ''formatDate'' : It is used like this `'${dataimporter.functions.formatDate(item.ID,
'yyyy-MM-dd HH:mm')}'` . The first argument can be a valid value from the !VariableResolver
and the second value can be a format string (use !SimpleDateFormat) . The first argument can
be a computed value eg: `'${dataimporter.functions.formatDate('NOW-3DAYS', 'yyyy-MM-dd HH:mm')}'`
and it uses the syntax of the datemath parser in Solr. (note that it must enclosed in single
quotes) . <!> Note . This syntax has been changed in 1.4 . The second parameter was
not enclosed in single quotes earlier. But it will continue to work without single quote also.
   * ''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
+  * ''encodeUrl'' : Use 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://lucene.apache.org/solr/api/org/apache/solr/handler/dataimport/Evaluator.html|Evaluator]]
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"/>
+   <function name="toLowerCase" class="foo.LowerCaseFunctionEvaluator"/>
-    <document>
+   <document>
-    <entity query="select * from table where name='${dataimporter.functions.toLowerCase(dataimporter.request.user)'">
+     <entity query="select * from table where name='${dataimporter.functions.toLowerCase(dataimporter.request.user)'">
-     <!- ......field declarations......->
+       <!- ......field declarations......->
-    </entity>
+     </entity>
+   </document>
  </dataConfig>
  }}}
  

Mime
View raw message