Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6344759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:42:12+00:00 2026-05-24T20:42:12+00:00

I’m trying to extend Lucene’s Analyzer from JRuby and use it from java. A

  • 0

I’m trying to extend Lucene’s Analyzer from JRuby and use it from java. A simple analyzer would look like:

class MyAnalyzer < Java::OrgApacheLuceneAnalysis::Analyzer
  def TokenStream (file_name, reader) 
     result = StandardTokenizer.new(Version::LUCENE_CURRENT, reader)
     result = LowerCaseFilter.new(result)
     result = LengthFilter.new(result, 3, 50) 
     result = StopFilter.new(result, StandardAnalyzer.STOP_WORDS_SET)
     result = PorterStemFilter.new(result)
     result
  end 
end

Then I compile it: jrubyc -c /home/camilo/trunk/utils/target/dependency/lucene-core-3.0.2.jar --javac MyAnalyzer.rb and package it as a jar.

Now, when trying to use MyAnalyzer back in java, MyAnalyzer is a descendent of org.jruby.RubyObject, and not of org.apache.lucene.analysis.Analyzer.

Is there a way to make Java treat MyAnalyzer as an Analyzer instead of a RubyObject? Or is this way outside the scope of what JRuby can do now?

JRuby version: jruby 1.6.0 (ruby 1.8.7 patchlevel 330)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:42:13+00:00Added an answer on May 24, 2026 at 8:42 pm

    From what I understand from you are trying to do, I’m guessing you are trying to create a JRuby class that extends a Java class (with a scripting engine), and hand back that class to Java.

    Your Ruby class probably looks like this:

    require 'java'
    require 'lucene-core.jar'
    
    java_import 'org.apache.lucene.analysis.Analyzer'
    java_import 'org.apache.lucene.analysis.standard.StandardTokenizer'
    java_import 'org.apache.lucene.util.Version'
    java_import 'org.apache.lucene.analysis.TokenStream'
    java_import 'java.io.Reader'
    
    class MyAnalyzer < Analyzer
    
      def tokenStream(file_name, reader) 
         result = StandardTokenizer.new(Version::LUCENE_CURRENT, reader)
          # ...
      end 
    end
    

    You can then use this class in Java as follows:

    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    import javax.script.ScriptException;
    import java.io.FileReader;
    import java.io.FileNotFoundException;
    import java.io.Reader;
    import org.apache.lucene.analysis.Analyzer;
    
    public class RunMyAnalyzer {
    
        public static void main(String[] args) throws ScriptException, FileNotFoundException {
            String filename = "my-analyzer.rb";
    
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("jruby");
            Reader reader = new FileReader(filename);
            engine.eval(reader);
    
            // Instantiate the JRuby class, and cast the result of eval.
            Analyzer analyzer = (Analyzer) engine.eval("MyAnalyzer.new");
    
            // You can then use this analyzer like a Lucene Analyzer
        }
    }
    

    You then compile and run with:

    $ javac -cp .:lucene-core.jar:$JRUBY_HOME/lib/jruby.jar RunMyAnalyzer.java 
    $ java -cp .:lucene-core.jar:$JRUBY_HOME/lib/jruby.jar RunMyAnalyzer
    

    The key here is that JRuby produces a proxy class that can then be casted into Analyzer, the Java superclass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.