How to write custom helper methods for by business rules

Question

I want to write custom methods which I can use while defining my business rules. This can be index time rules or search time rules. 

Answer

You could follow the steps mentioned below to create a Java class with helper methods that you require and then use them in your business rules.

  1. Create the Java class with the helper functions required. You could have a look at the structure of DroolsHelper.class mentioned here - http://docs.lucidworks.com/display/lweug/Drools+Integration
  2. Compile the Java class using - "javac com/rules/MyHelper.java". 
  3. To create a JAR file run - "jar cf jar-name.jar com/rules/MyHelper.class"
  4. Place the JAR in the following directory "$LWS_HOME/app/webapps/lwe-core/lwe-core/WEB-INF/lib/" -
  5. Create your rule in any of the .drl files under "$LWS_HOME/conf/solr/cores/[core-name]/conf/rules/"
    1. Don't forget to import the methods you have defined in the .drl file - "import function come.rules.MyHelper.*;"
    2. Use the functions you have defined in the "then" section of your rule file. 
  6. Restart the LWS server

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk