Skip to content
This repository has been archived by the owner on Dec 21, 2017. It is now read-only.

v0.3.0 #6

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bc6a063
Change version number to 0.1.0
emmanuel-keller Sep 2, 2013
e6db2b6
Few documentation updates
emmanuel-keller Sep 2, 2013
3e56905
Update documentation and gem spec
emmanuel-keller Sep 2, 2013
b26e469
#1 fixed. The non required yield call has been removed. document_test
emmanuel-keller Sep 5, 2013
d605833
Fixes #2, integer and decimal types use now respectively the
emmanuel-keller Sep 6, 2013
0c86476
#3 fix: the order_by clause works now. The ordering was corrupted when
emmanuel-keller Sep 6, 2013
7e9882d
Documentation update. New gem version (0.1.1).
emmanuel-keller Sep 6, 2013
1fe8203
New release 0.1.1
emmanuel-keller Sep 6, 2013
6a16c5e
Fixes #1. All the fields were merged in the same array structure. The
emmanuel-keller Sep 12, 2013
4a2d95f
Workaroung on #4 and new suggestion support #5
emmanuel-keller Oct 7, 2013
f9684b3
Fixes & optimizations to Searchable.
ysbaddaden Oct 7, 2013
21514f9
removed fixme.
ysbaddaden Oct 7, 2013
d3dac8e
Merge pull request #6 from ysbaddaden/master
emmanuel-keller Oct 7, 2013
e7fd239
Design improvements (thx Julien !), fixes authentication issue on
emmanuel-keller Oct 23, 2013
cbe7f15
Merge branch 'master' of https://github.com/OriPekelman/oss_active_re…
emmanuel-keller Oct 23, 2013
8e8245e
Merge with upstream
emmanuel-keller Oct 23, 2013
bb71904
Merge branch 'master' of https://github.com/jaeksoft/oss_active_record
emmanuel-keller Oct 23, 2013
d08d695
v0.3
emmanuel-keller Oct 23, 2013
21f0017
Add after_destroy callback support
emmanuel-keller Oct 23, 2013
17f8578
Add support of deletion
emmanuel-keller Oct 23, 2013
e541659
Crete index object when needed
AlexParamonov Mar 7, 2014
44fad8f
delete_by_id is also pseudo public. Force index build
AlexParamonov Mar 7, 2014
ba6f22a
Merge pull request #7 from AlexParamonov/fix/undefined_method_documen…
emmanuel-keller Mar 7, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ test/dummy/.sass-cache
/.project
/.DS_Store
/.buildpath
/oss_active_record-*.gem
/Gemfile.lock
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ gemspec

# To use debugger
gem 'pry'
gem 'oss_rb', :git => "https://github.com/emmanuel-keller/oss_rb"
gem 'oss_rb'
36 changes: 16 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
GIT
remote: https://github.com/emmanuel-keller/oss_rb
revision: fc29f72083004be1100e21ab4b5690a60924dc8c
specs:
oss_rb (0.0.1)
activesupport
rest-client

PATH
remote: .
specs:
oss_active_record (0.0.1)
oss_active_record (0.3.0)
oss_rb (>= 0.1.3)
rails (~> 4.0.0)

GEM
Expand Down Expand Up @@ -39,20 +32,23 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.0)
atomic (1.1.10)
arel (4.0.1)
atomic (1.1.14)
builder (3.1.4)
coderay (1.0.9)
erubis (2.7.0)
hike (1.2.3)
i18n (0.6.4)
i18n (0.6.5)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.23)
mime-types (1.25)
minitest (4.7.5)
multi_json (1.7.7)
multi_json (1.8.2)
oss_rb (0.1.3)
activesupport
rest-client
polyglot (0.3.3)
pry (0.9.12.2)
coderay (~> 1.0.5)
Expand Down Expand Up @@ -83,25 +79,25 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.0)
sprockets-rails (2.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.7)
sqlite3 (1.3.8)
thor (0.18.1)
thread_safe (0.1.2)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
treetop (1.4.14)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
tzinfo (0.3.38)

PLATFORMS
ruby

DEPENDENCIES
oss_active_record!
oss_rb!
oss_rb
pry
sqlite3
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
A very initial active_record intergration for OpenSearchServer http://www.open-search-server.com
An active_record intergration for OpenSearchServer

This is very very initial, no tests yet, but there is a running dummy application
This is very very initial, but there is a running dummy application with test cases.

Depends on OriPekelman/oss_rb
Depends on jaeksoft/oss_rb

## Requirement

A running OpenSearchServer instance (>= v1.5)
http://www.open-search-server.com

## Installation

Add this line to your application's Gemfile:

gem 'oss_rb', :github => "OriPekelman/oss_rb"
gem 'oss_active_record', :github => "OriPekelman/oss_active_record"
gem 'oss_rb'
gem 'oss_active_record'


And then execute:

$ bundle

Or install it yourself as (not on rubygems yet!):
Or install it yourself as:

$ gem install oss_active_record

## Configuration
Add `config/initializers/oss_active_record.rb` with the url of opens-search-server

Rails.configuration.open_search_server_url = "http://localhost:8080"
Add `config/initializers/oss_active_record.rb` with the URL, login and api key of opens-search-server

## Usage
Rails.configuration.open_search_server_url = 'http://localhost:8080'
Rails.configuration.open_search_server_login = 'my_login'
Rails.configuration.open_search_server_apikey = 'my_api_key'

## Usage

```ruby
class Person < ActiveRecord::Base
Expand Down
2 changes: 2 additions & 0 deletions lib/oss_active_record.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "oss_active_record/searchable"
require "oss_active_record/search_request"
require "oss_active_record/index_instance"

module OssActiveRecord
end
99 changes: 99 additions & 0 deletions lib/oss_active_record/index_instance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module OssActiveRecord
class IndexInstance

@@_analyzers = {
:text => 'StandardAnalyzer',
:integer => 'IntegerAnalyzer',
:decimal => 'DecimalAnalyzer',
:suggestion => 'SuggestionAnalyzer'}

def initialize(index_name)
@_index_name ||= index_name
@_fields= []
@_field_id = nil
@_text_fields = {}
@_sortable_fields = {}
@_all_fields = {}
@_index = nil
end

def text_fields
@_text_fields
end

def fields
@_fields
end

def field_id
@_field_id
end

def oss_index
if @_index.nil?
@_index = Oss::Index.new(@_index_name,
Rails.configuration.open_search_server_url,
Rails.configuration.open_search_server_login,
Rails.configuration.open_search_server_apikey)
create_schema!
end
@_index
end

def find_sortable_name(field_name)
field_name == :score ? 'score' : @_sortable_fields[field_name] unless field_name.nil?
end

def find_field_name(field_name)
@_all_fields[field_name] unless field_name.nil?
end

def add_field(name, type, block=nil)
@_fields<<{:name => name, :type => type,:block => block}
end

# FIXME: private method
def create_schema!
@_index.create('EMPTY_INDEX') unless @_index.list.include? @_index_name
@_field_id = @_fields.detect {|f| f[:name] == :id }
@_field_id = {:name => 'id', :type => 'integer',:block => nil} if @_field_id.nil?
@_fields << @_field_id
@_fields.each do |field|
create_schema_field!(field)
end
end

# FIXME: private method
def create_schema_field!(field)
analyzer = @@_analyzers[field[:type]] if field[:name] != :id
termVectors = { :text => 'POSITIONS_OFFSETS'}
termVector = termVectors[field[:type]] || 'NO'
name = "#{field[:name]}|#{field[:type]}"
params = {
'name' => name,
'analyzer' => analyzer,
'stored' => 'NO',
'indexed' => 'YES',
'termVector' => termVector
}
@_text_fields[field[:name]] = name if field[:type] == :text
@_sortable_fields[field[:name]] = name unless field[:type] == :text
@_all_fields[field[:name]] = name
@_index.set_field(params)
@_index.set_field_default_unique(name, name) if field[:name] == :id
end

def index(docs)
oss_index.documents << docs
oss_index.index!
end

def delete_by_id(id)
oss_index
id_field = find_sortable_name(:id)
oss_index.delete_document_by_value(id_field, id) unless id_field.nil?
end

end

end
47 changes: 30 additions & 17 deletions lib/oss_active_record/search_request.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
module OssActiveRecord
class SearchRequest
def initialize(index, text_fields, sortable_fields)
@index = index
def initialize(index_instance)
@params = {'start' => 0, 'rows' => 10}
@filters = [];
@text_fields = text_fields;
@sortable_fields = sortable_fields;
@order_by = {};
@filters = []
@index_instance = index_instance
@order_by = {}
@fields = []
end

def fulltext(keywords, &block)
@params['query'] = keywords
self.instance_eval(&block) unless block.nil?
end

def field(field, phrase = false, boost = 1.0)
@fields<<{ "field"=> @index_instance.find_field_name(field), "phrase" => phrase, "boost" => boost} if field.is_a?Symbol
@fields<<{ "field"=> field, "phrase" => phrase, "boost" => boost} if field.is_a?String
end

def fields(fields)
fields.each do |key, value|
field key, false, value
end if fields.is_a?Hash
field fields unless fields.is_a?Hash
end

def filter(field, value, negative)
@filters << {"type"=> "QueryFilter", "negative"=> negative, "query"=> "#{field}:#{value}"}
@filters << {"type"=> "QueryFilter", "negative"=> negative, "query"=> "#{field}:(#{value})"}
end

def with(field, value)
filter field, value, false
index_field = @index_instance.find_field_name(field)
filter index_field, value, false unless index_field.nil?
end

def without(field, value)
filter field, value, true
index_field = @index_instance.find_field_name(field)
filter index_field, value, true unless index_field.nil?
end

def returns(fields)
Expand All @@ -37,24 +51,23 @@ def paginate(params)
end

def order_by(field = nil, direction = :asc)
field = field == :score ? 'score' :@sortable_fields[field]
@order_by[field.to_s] = direction.to_s.upcase unless field.nil?
index_field = field == :score ? 'score' :@index_instance.find_sortable_name(field)
@order_by[index_field] = direction.to_s.upcase unless index_field.nil?
end

def execute(&block)
self.instance_eval(&block) unless block.nil?
@params['filters'] = @filters unless @filters.length == 0
fields = []
@text_fields.each do |key, value|
fields<<{ "field"=> value,"phrase"=> true,"boost"=> 1.0}
end
@params['searchFields'] = fields unless fields.length == 0
@index_instance.text_fields.each do |key, value|
field value, true
end unless @fields.any?
@params['searchFields'] = @fields unless @fields.length == 0
sorts = []
@order_by.each do |key, value|
sorts<<{ "field"=> key,"direction"=> value}
end
@params['sorts'] = sorts unless sorts.length == 0
return @index.search_field(@params)
return @index_instance.oss_index.search_field(@params)
end

end
Expand Down
Loading