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

59667324 use elasticsearch gem #138

Merged
merged 20 commits into from
Jan 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bundler_args: --without development
before_script:
- mysql -e 'CREATE DATABASE tariff_test;'
before_install:
- export PATH=$PATH:/usr/share/elasticsearch/bin/
- sudo apt-get update -qq
- sudo apt-get install -qq wbritish
- cp config/database.travis.yml config/database.yml
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://BnrJb6FZyzspBboNJzYZ@gem.fury.io/govuk/"
gem "rails", "3.2.16"

gem "addressable", "2.3.2"
gem "hashie", "2.0.5"
gem "multi_json", "~> 1.7.7"
gem "mysql2", "0.3.13"
gem "sequel-rails", "0.7.0"
Expand All @@ -12,8 +13,8 @@ gem "mlanett-redis-lock", "0.2.5", require: 'redis-lock'
gem "ansi"
gem "sequel", "4.3.0"
gem "sidekiq", "2.17.2"
gem "tire", "0.6.0"
gem "tire-contrib", '~> 0.1.3'
gem "elasticsearch", "0.4.7"
gem "elasticsearch-extensions", "0.0.12"
gem "yajl-ruby", require: "yajl"
gem "strong_parameters"

Expand Down Expand Up @@ -62,7 +63,6 @@ group :test do
gem "simplecov"
gem "simplecov-rcov"
gem "webmock"
gem "vcr"
end

group :router do
Expand Down
33 changes: 16 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ GEM
crack (0.3.2)
curb (0.8.3)
diff-lcs (1.2.4)
elasticsearch (0.4.7)
elasticsearch-api (= 0.4.7)
elasticsearch-transport (= 0.4.7)
elasticsearch-api (0.4.7)
multi_json
elasticsearch-extensions (0.0.12)
ansi
elasticsearch
ruby-prof
elasticsearch-transport (0.4.7)
faraday
multi_json
erubis (2.7.0)
exception_notification (2.6.1)
actionmailer (>= 3.0.4)
Expand Down Expand Up @@ -94,7 +106,6 @@ GEM
guard (>= 1.1)
haml (3.1.7)
hashie (2.0.5)
hashr (0.0.22)
highline (1.6.15)
hike (1.2.3)
httpauth (0.2.0)
Expand Down Expand Up @@ -191,8 +202,6 @@ GEM
redis-namespace (1.4.1)
redis (~> 3.0.4)
ref (1.0.5)
rest-client (1.6.7)
mime-types (>= 1.16)
router-client (3.0.1)
activesupport
builder
Expand All @@ -208,6 +217,7 @@ GEM
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
ruby-prof (0.14.2)
ruby2ruby (1.3.1)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
Expand Down Expand Up @@ -254,16 +264,6 @@ GEM
thor (0.18.1)
tilt (1.4.1)
timers (1.1.0)
tire (0.6.0)
activemodel (>= 3.0)
activesupport
ansi
hashr (~> 0.0.19)
multi_json (~> 1.3)
rake
rest-client (~> 1.6)
tire-contrib (0.1.3)
tire
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -275,7 +275,6 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
vcr (2.2.5)
warden (1.2.3)
rack (>= 1.0)
webmock (1.8.11)
Expand All @@ -300,12 +299,15 @@ DEPENDENCIES
capistrano
ci_reporter
curb (= 0.8.3)
elasticsearch (= 0.4.7)
elasticsearch-extensions (= 0.0.12)
exception_notification
factory_girl_rails
fakefs
forgery
gds-sso (= 3.1.0)
guard-rspec
hashie (= 2.0.5)
jquery-rails (= 1.0.19)
json_expressions
logstasher (= 0.4.1)
Expand All @@ -329,11 +331,8 @@ DEPENDENCIES
simplecov-rcov
strong_parameters
therubyracer (= 0.12.0)
tire (= 0.6.0)
tire-contrib (~> 0.1.3)
uglifier
unicorn (~> 4.6.3)
vcr
webmock
whenever (= 0.7.3)
yajl-ruby
14 changes: 8 additions & 6 deletions app/controllers/api/v1/search_references_base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class SearchReferencesBaseController < ApiController
def index
@search_references = begin
search_reference_collection.by_title
.paginate(per_page: per_page, page: page)
.paginate(page, per_page)
rescue Sequel::Error
search_reference_collection.by_title
.paginate(per_page: default_limit, page: default_page)
.paginate(page, per_page)
end
end

Expand All @@ -31,26 +31,28 @@ def destroy
end

def create
@search_reference = CreateSearchReference.create(
@search_reference = SearchReference.new(
search_reference_params.merge(search_reference_resource_association_hash)
)

@search_reference.save

respond_with @search_reference, location: collection_url
end

def update
@search_reference = search_reference_resource
@search_reference = UpdateSearchReference.update(
@search_reference,
@search_reference.set(
search_reference_params
)
@search_reference.save

respond_with @search_reference
end

def destroy
@search_reference = search_reference_resource
@search_reference = DestroySearchReference.destroy(@search_reference)
@search_reference.destroy

respond_with @search_reference
end
Expand Down
25 changes: 0 additions & 25 deletions app/interactors/create_search_reference.rb

This file was deleted.

24 changes: 0 additions & 24 deletions app/interactors/destroy_search_reference.rb

This file was deleted.

28 changes: 0 additions & 28 deletions app/interactors/update_search_reference.rb

This file was deleted.

41 changes: 1 addition & 40 deletions app/models/chapter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require_relative 'goods_nomenclature'

class Chapter < GoodsNomenclature
include Tire::Model::Search

plugin :json_serializer
plugin :oplog, primary_key: :goods_nomenclature_sid
plugin :conformance_validator
plugin :elasticsearch

set_dataset filter("goods_nomenclatures.goods_nomenclature_item_id LIKE ?", '__00000000').
order(Sequel.asc(:goods_nomenclature_item_id))
Expand All @@ -27,16 +25,6 @@ class Chapter < GoodsNomenclature
remover: proc{ |search_reference| search_reference.update(referenced_id: nil, referenced_class: nil)},
clearer: proc{ search_references_dataset.update(referenced_id: nil, referenced_class: nil) }

# Tire configuration
tire do
index_name 'chapters'
document_type 'chapter'

mapping do
indexes :description, analyzer: 'snowball'
end
end

dataset_module do
def by_code(code = "")
filter("goods_nomenclatures.goods_nomenclature_item_id LIKE ?", "#{code.to_s.first(2)}00000000")
Expand Down Expand Up @@ -76,33 +64,6 @@ def headings_to
last_heading.short_code
end

def serializable_hash
chapter_attributes = {
id: goods_nomenclature_sid,
goods_nomenclature_item_id: goods_nomenclature_item_id,
producline_suffix: producline_suffix,
validity_start_date: validity_start_date,
validity_end_date: validity_end_date,
description: formatted_description
}

if section.present?
chapter_attributes.merge!({
section: {
numeral: section.numeral,
title: section.title,
position: section.position
}
})
end

chapter_attributes
end

def to_indexed_json
serializable_hash.to_json
end

def changes(depth = 1)
operation_klass.select(
Sequel.as('Chapter', :model),
Expand Down
Loading