Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Elasticsearch::Data::Topic < Elasticsearch::Data::DataBase | ||
name_fields %i[name] | ||
data_fields %i[locale forum_id] | ||
track_changes_fields %i[name forum_id] | ||
|
||
private | ||
|
||
def name | ||
fix Topics::TopicViewFactory.new(true, true).build(@entry).topic_title | ||
end | ||
|
||
def locale | ||
@entry.locale | ||
end | ||
|
||
def forum_id | ||
@entry.forum_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Elasticsearch::Query::Topic < Elasticsearch::Query::QueryBase | ||
method_object %i[phrase locale forum_id limit] | ||
|
||
private | ||
|
||
def query | ||
{ | ||
bool: { | ||
must: [name_fields_query, locale_query, forum_id_query] | ||
} | ||
} | ||
end | ||
|
||
def locale_query | ||
{ term: { locale: @locale } } | ||
end | ||
|
||
def forum_id_query | ||
{ term: { forum_id: @forum_id } } | ||
end | ||
|
||
def cache_key | ||
super + [@locale, @forum_id] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,4 +290,6 @@ | |
end | ||
end | ||
end | ||
|
||
it_behaves_like :elasticsearch_concern, :anime | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe Elasticsearch::Query::Topic do | ||
let(:service) do | ||
Elasticsearch::Query::Topic.new( | ||
phrase: phrase, | ||
locale: locale, | ||
forum_id: forum_id, | ||
limit: limit | ||
) | ||
end | ||
|
||
describe '#call', :vcr do | ||
let(:phrase) { 'kai' } | ||
let(:locale) { 'ru' } | ||
let(:forum_id) { 1 } | ||
let(:limit) { 10 } | ||
|
||
subject { service.call } | ||
|
||
it { is_expected.to have(limit).items } | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
spec/vcr_cassettes/Elasticsearch_Query_Topic/_call/1_1_1.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.