From 80151adab2a8d4d6a40d0963868701e05066c9c4 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Tue, 31 May 2011 20:34:09 +0200 Subject: [PATCH] delete the old index, because it's obselete --- lib/polecat.rb | 1 - lib/polecat/index.rb | 68 ------------------------------------ spec/index/count_spec.rb | 25 ------------- spec/index/flush_spec.rb | 23 ------------ spec/index/index_dir_spec.rb | 19 ---------- spec/index/new_spec.rb | 22 ------------ spec/index/read_spec.rb | 22 ------------ spec/index/search_spec.rb | 38 -------------------- spec/index/write_spec.rb | 33 ----------------- 9 files changed, 251 deletions(-) delete mode 100644 lib/polecat/index.rb delete mode 100644 spec/index/count_spec.rb delete mode 100644 spec/index/flush_spec.rb delete mode 100644 spec/index/index_dir_spec.rb delete mode 100644 spec/index/new_spec.rb delete mode 100644 spec/index/read_spec.rb delete mode 100644 spec/index/search_spec.rb delete mode 100644 spec/index/write_spec.rb diff --git a/lib/polecat.rb b/lib/polecat.rb index 3325856..4f5c672 100644 --- a/lib/polecat.rb +++ b/lib/polecat.rb @@ -1,5 +1,4 @@ class Polecat - require 'polecat/index' require 'polecat/index_writer' require 'polecat/index_reader' require 'polecat/index_searcher' diff --git a/lib/polecat/index.rb b/lib/polecat/index.rb deleted file mode 100644 index 1532776..0000000 --- a/lib/polecat/index.rb +++ /dev/null @@ -1,68 +0,0 @@ -class Polecat - # storage of documents - # - # This is the core of the search platform, the index. It stores the documents, - # stores and reads them and make them searchable. - class Index - attr_reader :path - - # initialises an index object on the given path - # - # This method initialises an index on the path. The Path has to be a - # directory. - def initialize path - if File.directory? path - @path = path - @buffer = [] - @documents = [] - else - raise ArgumentError, "Argument no valid directory" - end - end - - # returns the document count currently loaded - def count - @documents.count - end - - # returns true, if it has an index - def index_dir? - File.exists?(@path + '/index.txt') - end - - def write doc - if (doc.kind_of? Document) - @buffer << doc - else - raise ArgumentError, "not a document" - end - end - - # read all stored documents from the index files into the index - def read - index_file = @path + '/index.txt' - if (File.exists? index_file) - @documents = Marshal.load(File.read(index_file)) - end - end - - def flush - @documents += @buffer - File.open @path + '/index.txt', 'w' do |file| - file.write Marshal.dump(@documents) - end - end - - def search term - matches = [] - linenr = 0 - @documents.each do |doc| - doc.attributes.each do |key, value| - matches << linenr if value[:value] =~ /#{term}/ - end - linenr += 1 - end - matches - end - end -end diff --git a/spec/index/count_spec.rb b/spec/index/count_spec.rb deleted file mode 100644 index e1c7829..0000000 --- a/spec/index/count_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "Index#count" do - before :all do - @path = prepare_index_dir - end - - it "returns 0 on a fresh index" do - i = Polecat::Index.new @path - i.count.should == 0 - end - - it "returns 1 when 1 entry is in the index" do - i = Polecat::Index.new @path - i.write Spec::FooDocument.new(:id => 1) - i.flush - i.count.should == 1 - end - - it "does not count entries, which got not flushed" do - i = Polecat::Index.new @path - i.write Spec::FooDocument.new(:id => 1) - i.count.should == 0 - end -end diff --git a/spec/index/flush_spec.rb b/spec/index/flush_spec.rb deleted file mode 100644 index 598450f..0000000 --- a/spec/index/flush_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "Document#flush" do - before do - @path = prepare_index_dir - @file = @path + '/index.txt' - @doc = Spec::FooDocument.new(:id => 1) - end - - it "does not write anything to the file, until the #flush was called" do - i = Polecat::Index.new @path - i.flush - i.write @doc - File.read(@file).should == Marshal.dump([]) - end - - it "writes the content in the buffer to the file" do - i = Polecat::Index.new @path - i.write @doc - i.flush - File.read(@file).should == Marshal.dump([@doc]) - end -end diff --git a/spec/index/index_dir_spec.rb b/spec/index/index_dir_spec.rb deleted file mode 100644 index feaa767..0000000 --- a/spec/index/index_dir_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "Document#index_dir?" do - before :all do - @path = prepare_index_dir - end - - it "returns false, if the directory does not contain an index" do - i = Polecat::Index.new @path - i.index_dir?.should == false - end - - it "returns true, if the directory contains an index" do - i = Polecat::Index.new @path - i.write Spec::FooDocument.new(:id => 1) - i.flush - i.index_dir?.should == true - end -end diff --git a/spec/index/new_spec.rb b/spec/index/new_spec.rb deleted file mode 100644 index d061470..0000000 --- a/spec/index/new_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "Index#new" do - before :all do - @path = prepare_index_dir - end - - it "takes a path as an argument" do - i = Polecat::Index.new @path - i.path.should == @path - end - - it "raises an ArgumentError, when no path is given" do - lambda { Polecat::Index.new }.should raise_error(ArgumentError) - end - - it "raises an ArgumentError, when the path is no directory" do - lambda { - Polecat::Index.new "/dev/null" - }.should raise_error(ArgumentError) - end -end diff --git a/spec/index/read_spec.rb b/spec/index/read_spec.rb deleted file mode 100644 index 6dd08d9..0000000 --- a/spec/index/read_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "Index#read" do - before :all do - @path = prepare_index_dir - end - - it "does not read any entries, when no files are in the directory" do - i = Polecat::Index.new @path - i.read - i.count.should == 0 - end - - it "loads all documents in the index directory" do - i = Polecat::Index.new @path - i.write Spec::FooDocument.new(:id => 1) - i.flush - i = Polecat::Index.new @path - i.read - i.count.should == 1 - end -end diff --git a/spec/index/search_spec.rb b/spec/index/search_spec.rb deleted file mode 100644 index 6e6f75e..0000000 --- a/spec/index/search_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "Index#search" do - before :all do - @doc1 = Spec::FooDocument.new :id => 1, :description => 'foo' - @doc2 = Spec::FooDocument.new :id => 2, :description => 'bar' - @doc3 = Spec::FooDocument.new :id => 3, :description => 'foo bar baz' - end - - before do - @path = prepare_index_dir - @file = @path + '/index.txt' - end - - it "returns an array of lines, where the match was found" do - i = Polecat::Index.new @path - i.write @doc1 - i.write @doc2 - i.write @doc1.clone - i.flush - i.search("foo").should == [0, 2] - end - - it "returns an array of lines, where the match is somewhere in it" do - i = Polecat::Index.new @path - i.write @doc3 - i.flush - i.search("baz").should == [0] - end - - it "returns an empty array, when no match was found" do - i = Polecat::Index.new @path - i.write @doc1 - i.write @doc2 - i.flush - i.search("baz").should == [] - end -end diff --git a/spec/index/write_spec.rb b/spec/index/write_spec.rb deleted file mode 100644 index e0649c5..0000000 --- a/spec/index/write_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "Document#write" do - before :all do - @doc1 = Spec::FooDocument.new(:id => 1) - @doc2 = Spec::FooDocument.new(:id => 2) - end - - before do - @path = prepare_index_dir - @file = @path + '/index.txt' - end - - it "writes a document to a file" do - i = Polecat::Index.new @path - i.write @doc1 - i.flush - File.read(@file).should == Marshal.dump([@doc1]) - end - - it "appends new entries to the end of the file" do - i = Polecat::Index.new @path - i.write @doc1 - i.write @doc2 - i.flush - File.read(@file).should == Marshal.dump([@doc1, @doc2]) - end - - it "raises an error, if the object is not a Polecat::Document" do - lambda { Polecat::Index.new(@path).write "foo" }.should( - raise_error(ArgumentError)) - end -end