Index: contrib/jruby/test/b =================================================================== Index: contrib/jruby/test/test.rb =================================================================== --- contrib/jruby/test/test.rb (revision 0) +++ contrib/jruby/test/test.rb (revision 0) @@ -0,0 +1,8 @@ +#!/bin/env jruby + +require 'test/unit' +require 'testJRuby' +require 'testIndex' +require 'testDoc' +require 'testSearch' +require 'testReuters' Property changes on: contrib/jruby/test/test.rb ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/test/r.rb =================================================================== --- contrib/jruby/test/r.rb (revision 0) +++ contrib/jruby/test/r.rb (revision 0) @@ -0,0 +1,2 @@ +#!/bin/env ruby +puts :a => "b", :c => "d", :c => "f" Property changes on: contrib/jruby/test/r.rb ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/test/org =================================================================== --- contrib/jruby/test/org (revision 0) +++ contrib/jruby/test/org (revision 0) @@ -0,0 +1 @@ +link ../../../build/classes/java/org \ No newline at end of file Property changes on: contrib/jruby/test/org ___________________________________________________________________ Name: svn:special + * Index: contrib/jruby/test/testDoc.rb =================================================================== --- contrib/jruby/test/testDoc.rb (revision 0) +++ contrib/jruby/test/testDoc.rb (revision 0) @@ -0,0 +1,47 @@ +#!/bin/env jruby + +require 'test/unit' + +require 'fileutils' + +require 'lucene' + +class DocTest < Test::Unit::TestCase + + def setup + FileUtils.rm_rf( "index" ) + @index = Index.create( "index" ) + end + + def teardown + @index.close + FileUtils.rm_rf( "index" ) + end + + def test_add_list + @index << [ :contents, "the quick brown fox jumped over the lazy dog" ] + end + + def test_add_lists + + @index << [ :contents, "the quick brown fox jumped over the lazy dog" ] \ + << [ :contents, "Alas poor Yorick,", \ + :contents, "I knew him Horatio" ] \ + << [ :contents, [ "To be,", "or not ", "to be" ] ] + + end + + def test_commit + + @index << [ :contents, "the quick brown fox jumped over the lazy dog" ] \ + << [ :contents, "Alas poor Yorick,", \ + :contents, "I knew him Horatio" ] \ + << [ :contents, [ "To be,", "or not ", "to be" ] ] + + @index.commit + + assert( @index.length == 3 ) + + end + +end Property changes on: contrib/jruby/test/testDoc.rb ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/test/testSearch.rb =================================================================== --- contrib/jruby/test/testSearch.rb (revision 0) +++ contrib/jruby/test/testSearch.rb (revision 0) @@ -0,0 +1,31 @@ +#!/bin/env jruby + +require 'test/unit' +require 'fileutils' +require 'lucene' + +class SearchTest < Test::Unit::TestCase + + def setup + FileUtils.rm_rf( "index" ) + @index = Index.create( "index" ) + @index << [ :contents, "the quick brown fox jumped over the lazy dog" ] \ + << [ :contents, "Alas poor Yorick,", \ + :contents, "I knew him Horatio" ] \ + << [ :contents, [ "Good night,", "good night!", "Parting is such sweet sorrow" ] ] \ + << [ :contents, "Good night, good night! Parting is such sweet sorrow" ] \ + << commit + end + + def teardown + @index.close + FileUtils.rm_rf( "index" ) + end + + def test_search + yorick = @index[ "yorick" ] + assert( yorick.length == 1 ) + assert( @index[ '"night parting"' ].length == 2 ) + end + +end Property changes on: contrib/jruby/test/testSearch.rb ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/test/test.sh =================================================================== --- contrib/jruby/test/test.sh (revision 0) +++ contrib/jruby/test/test.sh (revision 0) @@ -0,0 +1,3 @@ +./testJRuby.rb +./testIndex.rb +./testDoc.rb \ No newline at end of file Property changes on: contrib/jruby/test/test.sh ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/test/testIndex.rb =================================================================== --- contrib/jruby/test/testIndex.rb (revision 0) +++ contrib/jruby/test/testIndex.rb (revision 0) @@ -0,0 +1,59 @@ +#!/bin/env jruby + +require 'test/unit' + +require 'fileutils' + +require 'lucene' + +class IndexTest < Test::Unit::TestCase + + def setup + FileUtils.rm_rf( "index" ) + end + + def teardown + FileUtils.rm_rf( "index" ) + end + + def test_create + + assert( !File.exist?( "index" ) ) + + assert_raise NoMethodError do + Index.new( "index" ) + end + + assert_raise NativeException do + Index.open( "index" ) + end + + index = Index.create( "index" ) + + assert( File.exist?( "index" ) ) + + index.close + + index = Index.open( "index" ) + + index.close + + end + + def test_block_create + + result = Index.create( "index" ) do |index| + puts index + 54321 + end + assert_equal( result, 54321 ) + + result = Index.open( "index" ) do |index| + puts index + 12345 + end + assert_equal( result, 12345 ) + + end + +end Property changes on: contrib/jruby/test/testIndex.rb ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/test/testReuters.rb =================================================================== --- contrib/jruby/test/testReuters.rb (revision 0) +++ contrib/jruby/test/testReuters.rb (revision 0) @@ -0,0 +1,35 @@ +#!/bin/env jruby + +require 'test/unit' +require 'fileutils' +require 'lucene' +require 'reuters' + +class ReutersTest < Test::Unit::TestCase + + def setup + FileUtils.rm_rf( "index" ) + @index = Index.create( "index" ) + end + + def teardown + @index.close + FileUtils.rm_rf( "index" ) + end + + def test_ingest + + Reuters::DataSet.new( "../../../../../data/reuters/" ) do |reuters| + + assert( true || reuters.length == 1 ) + reuters.each do |doc| + @index << doc + end + @index << commit + assert( true || @index["fred"] == 10 ) + + end + + end + +end Property changes on: contrib/jruby/test/testReuters.rb ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/test/reuters.rb =================================================================== --- contrib/jruby/test/reuters.rb (revision 0) +++ contrib/jruby/test/reuters.rb (revision 0) @@ -0,0 +1,55 @@ +require 'lucene' + +module Reuters + + class Document + end + + class Documents + + def initialize( dataset ) + end + + def length + # @directory.length + end + + def close + end + + end + + class DataSet + + include Enumerable + + def initialize( path, args = {} ) + @path = path + @args = args + @documents = Documents.new( self ) + + result = self + + if block_given? + result = self.each { |doc| yield doc } + close + end + + result + + end + + def length + @documents.length + end + + def each + end + + def close + @documents.close + end + + end + +end Index: contrib/jruby/test/testJRuby.rb =================================================================== --- contrib/jruby/test/testJRuby.rb (revision 0) +++ contrib/jruby/test/testJRuby.rb (revision 0) @@ -0,0 +1,11 @@ +#!/bin/env jruby + +require 'test/unit' + +class UnitTestTest < Test::Unit::TestCase + + def test_success + assert( true, 'assert true' ) + end + +end Property changes on: contrib/jruby/test/testJRuby.rb ___________________________________________________________________ Name: svn:executable + * Index: contrib/jruby/TODO.txt =================================================================== --- contrib/jruby/TODO.txt (revision 0) +++ contrib/jruby/TODO.txt (revision 0) @@ -0,0 +1,3 @@ +Too much to enumerate at this point. Hopefully that will change with time. + +That said, it would be good to get this packaged as a WAR for a standard java web container. \ No newline at end of file Index: contrib/jruby/lib/lucene/document.rb =================================================================== --- contrib/jruby/lib/lucene/document.rb (revision 0) +++ contrib/jruby/lib/lucene/document.rb (revision 0) @@ -0,0 +1,89 @@ +module Lucene + + require 'java' + + JDocument = org.apache.lucene.document.Document + JField = org.apache.lucene.document.Field + + class JField + + def flags + str = "" + ( not is_indexed ) && str += "i" + is_compressed && str += "C" + is_lazy && str += "L" + ( not is_tokenized ) && str += "t" + get_omit_norms && str += "O" + str + end + + def value + string_value + end + + end + + class Document + + attr_accessor :id + attr_accessor :score + + class Fields + + def hash + @hash = {} + + @jdoc.get_fields.each do |field| + @hash[ field.name ] = field + end + end + + def initialize jdoc + @jdoc = jdoc + hash + end + + def [] key + @hash[ key ] + @jdoc.get_fields( key ) + end + + def each + @jdoc.get_fields.each { |f| yield f } + end + + end + + def construct list, java + @java = java || JDocument.new + if list + pair_up list do |k,v| + doc.add( JField.new( k.to_s, StringReader.new( v ) ) ) + end + end + self + end + + def self.from_java( java ) + doc = new + doc.construct nil, java + end + + def initialize( list = nil ) + construct list, nil + end + + def self.pair_up list + ( 0...list.length-1 ).step(2) do |i| + k,vs = list[i,2] + vs.to_a.each { |v| yield [k, v] } + end + end + + def fields + Fields.new( @java ) + end + + end + +end Index: contrib/jruby/lib/lucene/reader.rb =================================================================== --- contrib/jruby/lib/lucene/reader.rb (revision 0) +++ contrib/jruby/lib/lucene/reader.rb (revision 0) @@ -0,0 +1,209 @@ +module Lucene + + require 'java' + + JString = java.lang.String + + IndexReader = org.apache.lucene.index.IndexReader + + TermEnumUtils = org.apache.lucene.index.TermEnumUtils + + require 'lucene/document' + + class Terms + + class TermArray + + def initialize( java ) + @java = java + end + + def [] ( index, length = nil ) + if length == nil + @java[ index ] + else + result = [] + (index..index+length-1).each do |i| + break if i >= @java.length + result << @java[i] + end + result + end + end + + def each + index = 0; + while index < @java.length + yield @java[index] + index += 1 + end + end + + end + + include Enumerable + + def each + begin + begin + yield @java.term + rescue + end + end while @java.next + end + + def initialize( java ) + @java = java + end + + def close + @java.close + end + + def sort_by order + x = Java::JavaClass.for_name("java.lang.String").new_array( order.length ) + order.each_with_index { |s,i| x[i] = JString.new(s).java_object } + TermArray.new( TermEnumUtils::sort_by( @java, x ) ) + end + + def xby_doc_freq + TermArray.new( TermEnumUtils::by_doc_freq( @java ) ) + end + + def [] *options + TermArray.new( TermEnumUtils::by_doc_freq( @java ) )[ *options ] + end + + def length + TermEnumUtils::length( @java ) + end + + end + + class Documents + + def initialize( hits, first = 0, length = -1 ) + @hits = hits + @first = first + @length = length + end + + def length + @hits.length + end + + def sort_by *args + self + end + + def [] *args + self.class.new( @hits, args[0], args[1] ) + end + + def each + + ( @first .. @first + @length - 1 ).each do |i| + break if i >= @hits.length + # JRuby/Rails reload bug requires the extra scoping on Document + doc = Lucene::Document.from_java( @hits.doc(i) ) + doc.id = @hits.id(i) + doc.score = @hits.score(i) + yield( doc ) + end + end + + end + + class Reader + + include Enumerable + + attr_reader :java + + class Fields + + include Enumerable + + def initialize + @hash = {} + end + + def << field + @hash[field.name] = field + end + + def each + @hash.values.each do |field| + yield field + end + end + + def length + @hash.keys.length + end + + def [] key + @hash[ key ] + end + + end + + class Field + + attr_reader :name, :has_norms + + def initialize( name, nas_norms ) + @name = name + @has_norms = has_norms + end + + end + + def initialize( filename, args = {} ) + @filename = filename + @java = IndexReader.open( filename ) + end + + def close + @java.close + end + + def length + @java.numDocs + end + + def fields + fields = Fields.new + @java.getFieldNames( IndexReader::FieldOption::ALL ).each do |name| + fields << Field.new( name, @java.has_norms( name ) ) + end + fields + end + + def terms + Terms.new( @java.terms ) + end + + def documents + Documents.new( @java ) + end + + def has_deletions? + @java.hasDeletions + end + + def version + @java.getVersion + end + + def last_modified + Time.at( IndexReader.lastModified( @filename )/1000 ) + end + + def [] index + Document.from_java( @java.document( index ) ) + end + + end + +end Index: contrib/jruby/lib/lucene/analyzer/standard.rb =================================================================== --- contrib/jruby/lib/lucene/analyzer/standard.rb (revision 0) +++ contrib/jruby/lib/lucene/analyzer/standard.rb (revision 0) @@ -0,0 +1,9 @@ +module Lucene + module Analyzer + + require 'java' + + Standard = org.apache.lucene.analysis.standard.StandardAnalyzer + + end +end Index: contrib/jruby/lib/lucene/index.rb =================================================================== --- contrib/jruby/lib/lucene/index.rb (revision 0) +++ contrib/jruby/lib/lucene/index.rb (revision 0) @@ -0,0 +1,170 @@ +module Lucene + + require 'lucene/reader' + require 'lucene/writer' + require 'lucene/searcher' + require 'lucene/parser' + require 'lucene/analyzer/standard' + + class Index + + attr_reader :filename + alias_method :path, :filename + + def self.create( filename, args = {} ) + args = args.clone + args[ :filename ] = filename + create = args.clone + create[ :create ] = true + args[ :writer ] = Writer.new( filename, create ) + index = result = new( args ) + if block_given? + result = yield( index ) + index.close + end + result + end + + def self.open( filename, args = {} ) + args = args.clone + args[ :filename ] = filename + args[ :reader ] = Reader.new( filename, args ) + index = result = new( args ) + if block_given? + result = yield( index ) + index.close + end + result + end + + def close + @reader and @reader.close + @writer and @writer.close + @searcher and @searcher.close + end + + def << ( arg ) + if arg == :commit + commit + else + writer << arg + end + self + end + + def [] ( arg ) + begin + i = arg.to_int + rescue + end + if i + reader[ i ] + else + searcher[ parser[ arg ] ] + end + end + + def commit + if @writer + @writer.close + @writer = nil + end + end + + def length + reader.length + end + + def terms + reader.terms + end + + def documents + reader.documents + end + + def fields + reader.fields + end + + protected + + def writer + @writer or @writer = Writer.new( @filename ) + end + + def reader + @reader or @reader = Reader.new( @filename ) + end + + def searcher + @searcher or @searcher = Searcher.new( reader ) + end + + def parser + @parser or @parser = Parser.new( :contents, analyzer ) + end + + def analyzer + @analyzer or @analyzer = @args[ :analyzer ] || Analyzer::Standard.new + end + + def initialize( args ) + @args = args + @filename = args[ :filename ] + @reader = args[ :reader ] + @writer = args[ :writer ] + end + + protected + + class Fields + + include Enumerable + + def initialize ( doc = nil ) + @doc = doc + @hash = {} + end + + def << field + @hash[field.name] = field + end + + def each + if @doc + @doc.java.getFields.each do |field| + yield field + end + end + @hash.values.each do |field| + yield field + end + end + + def length + @hash.keys.length + end + + def [] key + raise "hell" + end + + end + + class Field + + attr_reader :name, :has_norms + + def initialize( name, nas_norms ) + @name = name + @has_norms = has_norms + end + + end + + private_class_method :new + + end + +end Index: contrib/jruby/lib/lucene/writer.rb =================================================================== --- contrib/jruby/lib/lucene/writer.rb (revision 0) +++ contrib/jruby/lib/lucene/writer.rb (revision 0) @@ -0,0 +1,30 @@ +module Lucene + + require 'java' + + class Writer + + def initialize( filename, args = {} ) + analyzer = args[ :analyzer ] || StandardAnalyzer.new + create = args[ :create ] || false + @java = IndexWriter.new( filename, analyzer, create ) + end + + def << ( arg ) + + if !(Document === arg) + arg = Document.new( arg ) + end + + @java.addDocument( arg.to_java ) + + self + end + + def close + @java.close + end + + end + +end Index: contrib/jruby/lib/lucene/parser.rb =================================================================== --- contrib/jruby/lib/lucene/parser.rb (revision 0) +++ contrib/jruby/lib/lucene/parser.rb (revision 0) @@ -0,0 +1,19 @@ +module Lucene + + require 'java' + + QueryParser = org.apache.lucene.queryParser.QueryParser + + class Parser + + def initialize( field, analyzer ) + @java = QueryParser.new( field.to_s, analyzer ) + end + + def [] ( query ) + @java.parse( query ) + end + + end + +end Index: contrib/jruby/lib/lucene/searcher.rb =================================================================== --- contrib/jruby/lib/lucene/searcher.rb (revision 0) +++ contrib/jruby/lib/lucene/searcher.rb (revision 0) @@ -0,0 +1,23 @@ +module Lucene + + require 'java' + + IndexSearcher = org.apache.lucene.search.IndexSearcher + + class Searcher + + def initialize( reader, args = {} ) + @java = IndexSearcher.new( reader.java ) + end + + def close + @java.close + end + + def [] ( query ) + Documents.new( @java.search( query ) ) + end + + end + +end Index: contrib/jruby/lib/lucene.rb =================================================================== --- contrib/jruby/lib/lucene.rb (revision 0) +++ contrib/jruby/lib/lucene.rb (revision 0) @@ -0,0 +1,21 @@ +# fixed in trunk, I believe ... + +class Hash + + def merge! options + + options.each do |k,v| + self[ k ] = ( block_given? && has_key?( k ) ) ? yield( k, self[ k ], v ) : v + end + + self + + end + +end + +module Lucene + + require 'lucene/index' + +end Index: contrib/jruby/src/java/org/apache/lucene/index/TermEnumUtils.java =================================================================== --- contrib/jruby/src/java/org/apache/lucene/index/TermEnumUtils.java (revision 0) +++ contrib/jruby/src/java/org/apache/lucene/index/TermEnumUtils.java (revision 0) @@ -0,0 +1,122 @@ +package org.apache.lucene.index; + +import java.util.Comparator; +import java.util.Collections; +import java.util.Vector; + +public abstract class TermEnumUtils { + + public static int length( TermEnum enumeration ) + throws java.io.IOException { + + int count = 0; + + while ( enumeration.next() ) { + count++; + } + + return count; + } + + static class Term { + + private int _freq; + private String _field; + private String _text; + + public Term( org.apache.lucene.index.Term term, int freq ) { + _field = term.field(); + _text =term.text(); + _freq = freq; + } + + public String text() { + return _text; + } + + public String field() { + return _field; + } + + public int doc_freq() { + return _freq; + } + + }; + + public static Term[] xby_doc_freq( TermEnum enumeration ) + throws java.io.IOException { + + Vector terms = new Vector(); + + while ( enumeration.next() ) { + terms.add( new Term( enumeration.term(), enumeration.docFreq() ) ); + } + + Collections.sort( terms, new CompareDocFreqs( new String[ 10 ] ) ); + + return (Term[])terms.toArray( new Term[0] ); + } + + public static Term[] sort_by( TermEnum enumeration, String[] order ) + throws java.io.IOException { + + Vector terms = new Vector(); + + while ( enumeration.next() ) { + terms.add( new Term( enumeration.term(), enumeration.docFreq() ) ); + } + + Collections.sort( terms, new CompareDocFreqs( order ) ); + + return (Term[])terms.toArray( new Term[0] ); + } + + private static class CompareDocFreqs implements Comparator { + + private String[] order; + + public CompareDocFreqs( String[] order ) { + this.order = order; + } + + public int compare( Object a, Object b ) { + + Term ta = (Term)a; + Term tb = (Term)b; + int i; + + for( i = 0; i < order.length; i++ ) { + + + int polarity = 1; + + String s = order[i]; + if ( s.charAt( 0 ) == '-' ) { + s = s.substring(1); + polarity = -1; + } + + if ( s.equals( "Field" ) ) { + int c = ta.field().compareTo( tb.field() ); + if ( c != 0 ) { + return polarity * c; + } + } else if ( s.equals( "Text" ) ) { + int c = ta.text().compareTo( tb.text() ); + if ( c != 0 ) { + return polarity * c; + } + } else if ( s.equals( "Frequency" ) ) { + int c = ta.doc_freq() - tb.doc_freq(); + if ( c != 0 ) { + return polarity * c; + } + } + } + return 0; + } + + } + +}; Index: contrib/jruby/rune/test/unit/document_test.rb =================================================================== --- contrib/jruby/rune/test/unit/document_test.rb (revision 0) +++ contrib/jruby/rune/test/unit/document_test.rb (revision 0) @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class DocumentTest < Test::Unit::TestCase + fixtures :documents + + # Replace this with your real tests. + def test_truth + assert true + end +end Index: contrib/jruby/rune/test/unit/index_test.rb =================================================================== --- contrib/jruby/rune/test/unit/index_test.rb (revision 0) +++ contrib/jruby/rune/test/unit/index_test.rb (revision 0) @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class IndexTest < Test::Unit::TestCase + fixtures :indices + + # Replace this with your real tests. + def test_truth + assert true + end +end Index: contrib/jruby/rune/test/test_helper.rb =================================================================== --- contrib/jruby/rune/test/test_helper.rb (revision 0) +++ contrib/jruby/rune/test/test_helper.rb (revision 0) @@ -0,0 +1,28 @@ +ENV["RAILS_ENV"] = "test" +require File.expand_path(File.dirname(__FILE__) + "/../config/environment") +require 'test_help' + +class Test::Unit::TestCase + # Transactional fixtures accelerate your tests by wrapping each test method + # in a transaction that's rolled back on completion. This ensures that the + # test database remains unchanged so your fixtures don't have to be reloaded + # between every test method. Fewer database queries means faster tests. + # + # Read Mike Clark's excellent walkthrough at + # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting + # + # Every Active Record database supports transactions except MyISAM tables + # in MySQL. Turn off transactional fixtures in this case; however, if you + # don't care one way or the other, switching from MyISAM to InnoDB tables + # is recommended. + self.use_transactional_fixtures = true + + # Instantiated fixtures are slow, but give you @david where otherwise you + # would need people(:david). If you don't want to migrate your existing + # test cases which use the @david style and don't mind the speed hit (each + # instantiated fixtures translates to a database query per test method), + # then set this back to true. + self.use_instantiated_fixtures = false + + # Add more helper methods to be used by all tests here... +end Index: contrib/jruby/rune/test/functional/document_controller_test.rb =================================================================== --- contrib/jruby/rune/test/functional/document_controller_test.rb (revision 0) +++ contrib/jruby/rune/test/functional/document_controller_test.rb (revision 0) @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'document_controller' + +# Re-raise errors caught by the controller. +class DocumentController; def rescue_action(e) raise e end; end + +class DocumentControllerTest < Test::Unit::TestCase + def setup + @controller = DocumentController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # Replace this with your real tests. + def test_truth + assert true + end +end Index: contrib/jruby/rune/test/functional/query_controller_test.rb =================================================================== --- contrib/jruby/rune/test/functional/query_controller_test.rb (revision 0) +++ contrib/jruby/rune/test/functional/query_controller_test.rb (revision 0) @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'query_controller' + +# Re-raise errors caught by the controller. +class QueryController; def rescue_action(e) raise e end; end + +class QueryControllerTest < Test::Unit::TestCase + def setup + @controller = QueryController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # Replace this with your real tests. + def test_truth + assert true + end +end Index: contrib/jruby/rune/test/functional/index_controller_test.rb =================================================================== --- contrib/jruby/rune/test/functional/index_controller_test.rb (revision 0) +++ contrib/jruby/rune/test/functional/index_controller_test.rb (revision 0) @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'index_controller' + +# Re-raise errors caught by the controller. +class IndexController; def rescue_action(e) raise e end; end + +class IndexControllerTest < Test::Unit::TestCase + def setup + @controller = IndexController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # Replace this with your real tests. + def test_truth + assert true + end +end Index: contrib/jruby/rune/test/functional/terms_controller_test.rb =================================================================== --- contrib/jruby/rune/test/functional/terms_controller_test.rb (revision 0) +++ contrib/jruby/rune/test/functional/terms_controller_test.rb (revision 0) @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'terms_controller' + +# Re-raise errors caught by the controller. +class TermsController; def rescue_action(e) raise e end; end + +class TermsControllerTest < Test::Unit::TestCase + def setup + @controller = TermsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # Replace this with your real tests. + def test_truth + assert true + end +end Index: contrib/jruby/rune/test/fixtures/documents.yml =================================================================== --- contrib/jruby/rune/test/fixtures/documents.yml (revision 0) +++ contrib/jruby/rune/test/fixtures/documents.yml (revision 0) @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 +two: + id: 2 Index: contrib/jruby/rune/app/helpers/document_helper.rb =================================================================== --- contrib/jruby/rune/app/helpers/document_helper.rb (revision 0) +++ contrib/jruby/rune/app/helpers/document_helper.rb (revision 0) @@ -0,0 +1,2 @@ +module DocumentHelper +end Index: contrib/jruby/rune/app/helpers/application_helper.rb =================================================================== --- contrib/jruby/rune/app/helpers/application_helper.rb (revision 0) +++ contrib/jruby/rune/app/helpers/application_helper.rb (revision 0) @@ -0,0 +1,3 @@ +# Methods added to this helper will be available to all templates in the application. +module ApplicationHelper +end Index: contrib/jruby/rune/app/helpers/query_helper.rb =================================================================== --- contrib/jruby/rune/app/helpers/query_helper.rb (revision 0) +++ contrib/jruby/rune/app/helpers/query_helper.rb (revision 0) @@ -0,0 +1,2 @@ +module QueryHelper +end Index: contrib/jruby/rune/app/helpers/index_helper.rb =================================================================== --- contrib/jruby/rune/app/helpers/index_helper.rb (revision 0) +++ contrib/jruby/rune/app/helpers/index_helper.rb (revision 0) @@ -0,0 +1,2 @@ +module IndexHelper +end Index: contrib/jruby/rune/app/helpers/terms_helper.rb =================================================================== --- contrib/jruby/rune/app/helpers/terms_helper.rb (revision 0) +++ contrib/jruby/rune/app/helpers/terms_helper.rb (revision 0) @@ -0,0 +1,2 @@ +module TermsHelper +end Index: contrib/jruby/rune/app/models/document.rb =================================================================== --- contrib/jruby/rune/app/models/document.rb (revision 0) +++ contrib/jruby/rune/app/models/document.rb (revision 0) @@ -0,0 +1,15 @@ +require 'lucene' + +class Document < Lucene::Documents + + def self.count options + Index.index[ options[:conditions] ].length + end + + def self.find *options + raise options[0] + " not implemented" unless options[0] == :all + options = options[1] + Index.index[ options[:conditions] ][ options[:offset], options[:limit] ] + end + +end Index: contrib/jruby/rune/app/models/term.rb =================================================================== --- contrib/jruby/rune/app/models/term.rb (revision 0) +++ contrib/jruby/rune/app/models/term.rb (revision 0) @@ -0,0 +1,15 @@ +require 'lucene' + +class Term < Lucene::Terms + + def self.count options + Index.index.terms.length + end + + def self.find *options + raise options[0] + " not implemented" unless options[0] == :all + options = options[1] + Index.index.terms.sort_by( options[:order] )[ options[:offset], options[:limit] ] + end + +end Index: contrib/jruby/rune/app/models/index.rb =================================================================== --- contrib/jruby/rune/app/models/index.rb (revision 0) +++ contrib/jruby/rune/app/models/index.rb (revision 0) @@ -0,0 +1,39 @@ +require 'lucene' + +class Index < Lucene::Index + + class << self + + attr_accessor :index + + # until Hash#merge! fixed + + attr_accessor :order + + end + + def length + reader.length + end + + def terms + reader.terms + end + + def fields + reader.fields + end + + def has_deletions? + reader.has_deletions? + end + + def version + reader.version + end + + def last_modified + reader.last_modified + end + +end Index: contrib/jruby/rune/app/controllers/terms_controller.rb =================================================================== --- contrib/jruby/rune/app/controllers/terms_controller.rb (revision 0) +++ contrib/jruby/rune/app/controllers/terms_controller.rb (revision 0) @@ -0,0 +1,63 @@ +class TermsController < ApplicationController + + def index + + @path = session[:path] + + @index = find( @path ) + + if !@index + redirect_to :controller => "index" + end + + if ( page = request.parameters[:page] ) + session[:page] = page + else + if session[:page] + request.parameters[:page] = session[:page] + end + end + + @order = session[:order] || ( session[:order] = [] ) + + if ( @sort = request.parameters[:sort_by] ) + + polarity = @order.grep( /(-?)#{@sort}/ ) + + unless polarity.empty? + @order.delete polarity[0] + unless polarity[0][0] == ?- + @sort = "-#{@sort}" + end + end + + @order.unshift @sort + + redirect_to + + end + + @order.unshift "-Frequency" if @order.empty? + + @term_pages, @terms = paginate( :terms, :order => @order \ + , :per_page => 25 + ) + + end + + def find( filename ) + if filename + begin + @index = Index.open( filename ) + rescue Exception => e + flash[:notice] = "No index at " + filename + ": " + e + if false + flash[:notice] += "
" + e.backtrace * "
" + end + nil + end + Index.index = @index + end + end + +end Index: contrib/jruby/rune/app/controllers/document_controller.rb =================================================================== --- contrib/jruby/rune/app/controllers/document_controller.rb (revision 0) +++ contrib/jruby/rune/app/controllers/document_controller.rb (revision 0) @@ -0,0 +1,33 @@ +class DocumentController < ApplicationController + + def index + @path = session[:path] + @index = find( @path ) + + @id = request.parameters[:id] ? request.parameters[:id].to_i : session[:id] + session[:id] = @id + + if !@index + redirect_to :controller => "index" + end + + @document = Index.index[@id] unless @id == nil + + end + + def find( filename ) + if filename + begin + @index = Index.open( filename ) + rescue Exception => e + flash[:notice] = "No index at " + filename + ": " + e + if false + flash[:notice] += "
" + e.backtrace * "
" + end + nil + end + Index.index = @index + end + end + +end Index: contrib/jruby/rune/app/controllers/application.rb =================================================================== --- contrib/jruby/rune/app/controllers/application.rb (revision 0) +++ contrib/jruby/rune/app/controllers/application.rb (revision 0) @@ -0,0 +1,7 @@ +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +class ApplicationController < ActionController::Base + # Pick a unique cookie name to distinguish our session data from others' + session :session_key => '_rune_session_id' +end Index: contrib/jruby/rune/app/controllers/query_controller.rb =================================================================== --- contrib/jruby/rune/app/controllers/query_controller.rb (revision 0) +++ contrib/jruby/rune/app/controllers/query_controller.rb (revision 0) @@ -0,0 +1,74 @@ +class QueryController < ApplicationController + + def index + + @path = session[:path] + @index = find( @path ) + + if !@index + redirect_to :controller => "index" + end + + if ( qpage = request.parameters[:page] ) + session[:qpage] = qpage + else + if session[:qpage] + request.parameters[:page] = session[:qpage] + end + end + + @order = session[:order] || ( session[:order] = [] ) + + if ( @sort = request.parameters[:sort_by] ) + + polarity = @order.grep( /(-?)#{@sort}/ ) + + unless polarity.empty? + @order.delete polarity[0] + unless polarity[0][0] == ?- + @sort = "-#{@sort}" + end + end + + @order.unshift @sort + + redirect_to + + end + + @order.unshift "-Frequency" if @order.empty? + + if ( @query = request.parameters[:query] ) + session[:query] = @query + else + if session[:query] + @query = request.parameters[:query] = session[:query] + end + end + + if @query + @fields = @index.fields + @doc_pages, @docs = paginate( :documents, :order => @order \ + , :per_page => 25 \ + , :conditions => @query \ + ) + end + + end + + def find( filename ) + if filename + begin + @index = Index.open( filename ) + rescue Exception => e + flash[:notice] = "No index at " + filename + ": " + e + if false + flash[:notice] += "
" + e.backtrace * "
" + end + nil + end + Index.index = @index + end + end + +end Index: contrib/jruby/rune/app/controllers/index_controller.rb =================================================================== --- contrib/jruby/rune/app/controllers/index_controller.rb (revision 0) +++ contrib/jruby/rune/app/controllers/index_controller.rb (revision 0) @@ -0,0 +1,26 @@ +class IndexController < ApplicationController + + def index + if request.post? + @path = session[:path] = params[:path] + else + @path = session[:path] + end + @index = find( @path ) + end + + def find( filename ) + if filename + begin + @index = Index.open( filename ) + rescue Exception => e + flash[:notice] = "No index at " + filename + ": " + e + if false + flash[:notice] += "
" + e.backtrace * "
" + end + nil + end + end + end + +end Index: contrib/jruby/rune/app/views/layouts/application.rhtml =================================================================== --- contrib/jruby/rune/app/views/layouts/application.rhtml (revision 0) +++ contrib/jruby/rune/app/views/layouts/application.rhtml (revision 0) @@ -0,0 +1,28 @@ + + + + + + + + <%= "rune" %> + <%= @index && ': ' + h( @index.path) %> + + + <%= stylesheet_link_tag "style", :media => "all" %> + + + + + + <%= render :partial => "/banner" %> + <%= render :partial => "/flash" %> + <%= render :partial => "/menu" %> + + <%= yield %> + + + + Index: contrib/jruby/rune/app/views/_flash.rhtml =================================================================== --- contrib/jruby/rune/app/views/_flash.rhtml (revision 0) +++ contrib/jruby/rune/app/views/_flash.rhtml (revision 0) @@ -0,0 +1,3 @@ +<% if flash[:notice] -%> +
<%= flash[:notice] %>
+<% end -%> Index: contrib/jruby/rune/app/views/query/index.rhtml =================================================================== --- contrib/jruby/rune/app/views/query/index.rhtml (revision 0) +++ contrib/jruby/rune/app/views/query/index.rhtml (revision 0) @@ -0,0 +1,45 @@ +<% form_tag do %> + +
+ +
+ +
<%= text_field_tag :query, @query %>
+ + <% if @query %> + + Documents + + + + <% [ "Score", "Id", @fields.collect { |f| f.name } ].flatten.each do |column| %> + + <% end %> + + <% @docs.each do |doc| %> + + + + <% @fields.each do |field| %> + + <% end %> + + <% end %> + + + +
<%= column %>
<%= format "%.2f", doc.score * 100 %><%= link_to doc.id, :controller => :document, + :id => doc.id %> + <% map = lambda { |v| v.value } %> + <%= doc.fields[field.name].to_a.map(&map).first %> +
+ <%= pagination_links @doc_pages %> +
+ +
+ + <% end %> + +
+ +<% end %> \ No newline at end of file Index: contrib/jruby/rune/app/views/index/index.rhtml =================================================================== --- contrib/jruby/rune/app/views/index/index.rhtml (revision 0) +++ contrib/jruby/rune/app/views/index/index.rhtml (revision 0) @@ -0,0 +1,29 @@ +<% form_tag do %> + +
+ +
+ Index Path: + <%= text_field_tag :path, @path %> +
+ + <% if @index %> + +
Number of fields:<%= @index.fields.length %>
+
Number of documents:<%= @index.length %>
+
Number of terms:<%= @index.terms.length %>
+
Has deletions?<%= @index.has_deletions? ? "yes" : "no" %>
+
Index version:<%= @index.version %>
+
Last modified:<%= @index.last_modified %>
+ +
+
Fields
+ <%= render :partial => "/fields" %> +
+ + <% end %> + +
+ +<% end %> + Index: contrib/jruby/rune/app/views/_menu.rhtml =================================================================== --- contrib/jruby/rune/app/views/_menu.rhtml (revision 0) +++ contrib/jruby/rune/app/views/_menu.rhtml (revision 0) @@ -0,0 +1,8 @@ + \ No newline at end of file Index: contrib/jruby/rune/app/views/_banner.rhtml =================================================================== --- contrib/jruby/rune/app/views/_banner.rhtml (revision 0) +++ contrib/jruby/rune/app/views/_banner.rhtml (revision 0) @@ -0,0 +1,7 @@ + + Index: contrib/jruby/rune/app/views/terms/index.rhtml =================================================================== --- contrib/jruby/rune/app/views/terms/index.rhtml (revision 0) +++ contrib/jruby/rune/app/views/terms/index.rhtml (revision 0) @@ -0,0 +1,36 @@ +
+ +
+ + Terms + + + + + + + + + <% %w{ Field Text Frequency }.each do |column| %> + + <% end %> + + <% @terms.each do |term| %> + + + + + + <% end %> + + + +
<%= link_to "Document", { :sort_by => "Frequency" } %>
<%= link_to column, { :sort_by => column } %>
<%= term.field %> + <%= link_to term.text, :controller => :query, + :query => "#{term.field}:#{term.text}" %> + <%= term.doc_freq %>
+ <%= pagination_links @term_pages %> +
+ + +
\ No newline at end of file Index: contrib/jruby/rune/app/views/_fields.rhtml =================================================================== --- contrib/jruby/rune/app/views/_fields.rhtml (revision 0) +++ contrib/jruby/rune/app/views/_fields.rhtml (revision 0) @@ -0,0 +1,7 @@ +
+ <% @index.fields.each do |f| %> +
<%= f.name %>
+
<%= f.has_norms && "(has norms)" %>
+ <% end %> +
+ Index: contrib/jruby/rune/app/views/document/index.rhtml =================================================================== --- contrib/jruby/rune/app/views/document/index.rhtml (revision 0) +++ contrib/jruby/rune/app/views/document/index.rhtml (revision 0) @@ -0,0 +1,35 @@ +<% form_tag :id => nil do %> + +
+ +
Document Id: <%= text_field_tag :id, @id, :size => 4 %>
+ + <% if @id %> + +
Fields
+ + + + + + + <% x = nil %> + <% @document.fields.each do |field| %> + + + + + + <% end %> +
NameFlagsValue
+ <% if not x == field.name %> + <%= field.name %> + <% x = field.name %> + <% end %> + <%= field.flags %><%= field.value %>
+ + <% end %> + +
+ +<% end %> \ No newline at end of file Index: contrib/jruby/rune/tmp/sessions/ruby_sess.4b960861815c7360 =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: contrib/jruby/rune/tmp/sessions/ruby_sess.4b960861815c7360 ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: contrib/jruby/rune/tmp/sessions/ruby_sess.b7f03ef81abc11ce =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: contrib/jruby/rune/tmp/sessions/ruby_sess.b7f03ef81abc11ce ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: contrib/jruby/rune/tmp/sessions/ruby_sess.027ac1afc75f4854 =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: contrib/jruby/rune/tmp/sessions/ruby_sess.027ac1afc75f4854 ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: contrib/jruby/rune/tmp/sessions/ruby_sess.4efd430db4238f44 =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: contrib/jruby/rune/tmp/sessions/ruby_sess.4efd430db4238f44 ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: contrib/jruby/rune/tmp/sessions/ruby_sess.da213a9343fd032c =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: contrib/jruby/rune/tmp/sessions/ruby_sess.da213a9343fd032c ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: contrib/jruby/rune/luke/.plugins =================================================================== --- contrib/jruby/rune/luke/.plugins (revision 0) +++ contrib/jruby/rune/luke/.plugins (revision 0) @@ -0,0 +1,3 @@ +org.getopt.luke.plugins.AnalyzerToolPlugin +org.getopt.luke.plugins.ScriptingPlugin +org.getopt.luke.plugins.SimilarityDesignerPlugin Index: contrib/jruby/rune/luke/xml/qexplain.xml =================================================================== --- contrib/jruby/rune/luke/xml/qexplain.xml (revision 0) +++ contrib/jruby/rune/luke/xml/qexplain.xml (revision 0) @@ -0,0 +1,6 @@ + + + Index: contrib/jruby/rune/luke/xml/SampleScript.js =================================================================== --- contrib/jruby/rune/luke/xml/SampleScript.js (revision 0) +++ contrib/jruby/rune/luke/xml/SampleScript.js (revision 0) @@ -0,0 +1,16 @@ +// This is a sample script to demonstrate scripting of Luke + +print("Available plugins:"); +plugins = app.plugins; +for (var i = 0; i < plugins.size(); i++) { + print(" - " + plugins.get(i).pluginName); +} +print("Available analyzers:"); +for (var i = 0; i < app.analyzers.length; i++) { + print(" - " + app.analyzers[i]); +} +if (ir != null) { + print("Number of documents: " + ir.numDocs()); + print("Field names: " + ir.fieldNames); +} +app.actionAbout(); Index: contrib/jruby/rune/luke/xml/scr-plugin.xml =================================================================== --- contrib/jruby/rune/luke/xml/scr-plugin.xml (revision 0) +++ contrib/jruby/rune/luke/xml/scr-plugin.xml (revision 0) @@ -0,0 +1,16 @@ + + +