Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 549ce91

Browse files
committed
inserting order on results
1 parent 352c097 commit 549ce91

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Run the below code:
1111

1212
```
13-
docker-compose run web
13+
docker-compose up web
1414
```
1515

1616
## Setup

app/models/user_neo4j.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ def friends_by_search(term)
5454
where('ANY(title IN l.titles WHERE toLower(title) CONTAINS toLower({title})) OR
5555
ANY(subtitle IN l.subtitles WHERE toLower(subtitle) CONTAINS toLower({title}))').
5656
where('l <> user').
57-
params({ title: term })
57+
params({ title: term }).
58+
to_a
5859

60+
# TODO: Use only one query to get users and shortest paths
5961
friends.each do |friend|
6062
friends_path[friend.uuid] = Neo4j::ActiveBase.current_session.
6163
query("MATCH (r:UserNeo4j { uuid: '#{uuid}' }),
@@ -64,6 +66,17 @@ def friends_by_search(term)
6466
RETURN p", limit: 1).first.p.nodes
6567
end
6668

69+
# TODO: Use only queries to generate order
70+
friends.sort_by! do |item|
71+
total = 0
72+
73+
total += (friends_path[item.uuid].length - 2) * 10
74+
total += item.titles.any? { titles.include?(term) } ? -10 : 0
75+
total += item.subtitles.any? { |subtitle| subtitle.include?(term) } ? -5 : 0
76+
77+
total
78+
end
79+
6780
[friends, friends_path]
6881
end
6982

lib/website_scrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.titles(url)
1313

1414
{
1515
titles: nokogiri.search('h1').map { |item| item.text.squish },
16-
subtitles: nokogiri.search('h2').map { |item| item.text.squish },
16+
subtitles: nokogiri.search('h2, h3').map { |item| item.text.squish },
1717
}
1818
end
1919
end

0 commit comments

Comments
 (0)