-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SRCH-1384 update LinkPopularity query to search by
type
field (#563)
- Loading branch information
1 parent
e47dd91
commit 28764c1
Showing
4 changed files
with
58 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class LinkPopularity | ||
extend LogstashPrefix | ||
|
||
def self.popularity_for(url, days_back) | ||
link_popularity_query = ElasticLinkPopularityQuery.new(url, days_back) | ||
total = ES::ELK.client_reader.count(index: indexes_to_date(days_back, true), type: 'click', body: link_popularity_query.body)["count"] | ||
total = ES::ELK.client_reader.count( | ||
index: indexes_to_date(days_back, true), | ||
body: link_popularity_query.body | ||
)['count'] | ||
[Math.log10(total), 1.0].max | ||
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e | ||
rescue Elasticsearch::Transport::Transport::Errors::NotFound | ||
1.0 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
describe LinkPopularity, ".popularity_for(url, days_back)" do | ||
context 'when days_back logstash indexes does not exist' do | ||
before do | ||
allow(ES::ELK.client_reader).to receive(:count).and_raise(Elasticsearch::Transport::Transport::Errors::NotFound) | ||
describe LinkPopularity do | ||
describe '.popularity_for' do | ||
subject(:popularity_for) do | ||
LinkPopularity.popularity_for('http://www.gov.gov/someurl.html', 7) | ||
end | ||
|
||
it 'should return a default popularity of 1.0' do | ||
expect(LinkPopularity.popularity_for("http://www.gov.gov/someurl.html", 7)).to eq(1.0) | ||
context 'when clicks have occurred' do | ||
let(:click_count) { 50 } | ||
|
||
before do | ||
allow(ES::ELK.client_reader).to receive(:count). | ||
and_return( 'count' => click_count ) | ||
end | ||
|
||
it 'returns the base 10 log of the click count' do | ||
expect(popularity_for).to eq(1.6989700043360187) | ||
end | ||
|
||
context 'when the base 10 log of the click count is < 1' do | ||
let(:click_count) { 5 } | ||
|
||
it { is_expected.to eq(1.0) } | ||
end | ||
end | ||
|
||
context 'when days_back logstash indexes does not exist' do | ||
before do | ||
allow(ES::ELK.client_reader).to receive(:count). | ||
and_raise(Elasticsearch::Transport::Transport::Errors::NotFound) | ||
end | ||
|
||
it 'returns a default popularity of 1.0' do | ||
expect(popularity_for).to eq(1.0) | ||
end | ||
end | ||
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