JRuby Scripting

From DBSight Full-Text Search Engine/Platform Wiki

Table of contents


How does it work?

Scripting is mainly for customization work.

The scripts are stored under this directory

WEB-INF/scripts/

To invoke this, edit WEB-INF/conf/xsearch-web-config.xml

<commands>
 <command name="Incremental Indexing">stopIndexing updateIndex ... startIndexing ... buildDictionaryIfNeeded ping-a-url</command>
 ...
</commands>

If you have "example.rb" file under WEB-INF/scripts/, just add "example.rb" in one of the command value

For example

 <command name="Incremental Indexing">stopIndexing updateIndex ... startIndexing ... buildDictionaryIfNeeded ping-a-url example.rb</command>

The only variable is $dc

What can it do?

What's the execution environment?

Execution directory: "WEB-INF/"

Libraries available: All jar files under "WEB-INF/lib"

Hello for the index name

 p "hello for #{$dc.name}"


Execute some system commands

 system 'ls -l'
 system 'cp from_file_name to_file_name'
 system 'your_own_perl_scripts.pl'


Send a http request and print out response

 require 'scripts/example.rb'           #not really needed, just show an example usage
 
 require "java"
 
 include_class "net.javacoding.xsearch.utility.HttpPost"    #you may want to "open-uri" library instead, but it's not shipped by DBSight
 
 hp = HttpPost.new("http://en.wikipedia.org/wiki/JRuby")
 
 print hp.send


Copy files

 require "java"
 include_class "net.javacoding.xsearch.utility.FileUtil"
 FileUtil.copyFile( from_file_name, to_file_name)

Is it too limited?

JRuby is powerful. But its libraries are huge and we can not ship all of them. But you can add new jruby libraries to WEB-INF/scripts directory, Or, if you are more familiar with java, you can write your own java library and put it on the classpath, or simply drop the jar files under WEB-INF/lib, and call them via jruby.