Skip to content

Commit 367d998

Browse files
committed
Extract search from protip
1 parent b32c700 commit 367d998

File tree

4 files changed

+37
-40
lines changed

4 files changed

+37
-40
lines changed

app/models/protip.rb

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -426,46 +426,6 @@ def valid_reviewers
426426
# Homepage 4.0 rewrite
427427
#######################
428428

429-
class Search < SearchModule::Search
430-
431-
class Scope < SearchModule::Search::Scope
432-
433-
def to_hash
434-
case @domain
435-
when :user
436-
followings(@object)
437-
when :network
438-
network(@object)
439-
end
440-
end
441-
442-
def followings(user)
443-
{
444-
or: [
445-
{ terms: { "user.user_id" => [user.id] + user.following_users_ids + user.following_team_members_ids } },
446-
{ terms: { "tags" => user.following_networks_tags } }
447-
]
448-
}
449-
end
450-
451-
def network(tag)
452-
{
453-
terms: { tags: Network.find_by_slug(Network.slugify(tag)).try(&:tags) || [tag, Network.unslugify(tag)].uniq }
454-
}
455-
end
456-
end
457-
458-
class Query < SearchModule::Search::Query
459-
def default_query
460-
"flagged:false"
461-
end
462-
end
463-
464-
def failover_strategy
465-
{ failover: Protip.order('score DESC') }
466-
end
467-
end
468-
469429
def deindex_search
470430
Services::Search::DeindexProtip.run(self)
471431
end

app/models/protip/search.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Search < SearchModule::Search
2+
3+
def failover_strategy
4+
{failover: Protip.order('score DESC')}
5+
end
6+
end

app/models/protip/search/query.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Query < SearchModule::Search::Query
2+
def default_query
3+
"flagged:false"
4+
end
5+
end

app/models/protip/search/scope.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Scope < SearchModule::Search::Scope
2+
3+
def to_hash
4+
case @domain
5+
when :user
6+
followings(@object)
7+
when :network
8+
network(@object)
9+
end
10+
end
11+
12+
def followings(user)
13+
{
14+
or: [
15+
{ terms: { "user.user_id" => [user.id] + user.following_users_ids + user.following_team_members_ids } },
16+
{ terms: { "tags" => user.following_networks_tags } }
17+
]
18+
}
19+
end
20+
21+
def network(tag)
22+
{
23+
terms: { tags: Network.find_by_slug(Network.slugify(tag)).try(&:tags) || [tag, Network.unslugify(tag)].uniq }
24+
}
25+
end
26+
end

0 commit comments

Comments
 (0)