-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add tags streams #68
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2a0c393
Add cypher queries for tags
tipogi 365ee4d
Add hot tags endpoint
tipogi 1b7011d
Add hot tags by reach: Following, Followers, Friend, Most Followed
tipogi 8260a06
Add unit tests and benchmarks
tipogi f8b4594
Hot tags scores count by post number not by tagged number
tipogi e0ea9ee
Minor fixes
tipogi 6736b5c
Add threshold for hot tags and fix Swagger endpoints return types
tipogi f62e0e7
Improvements from PR review
tipogi 58d55fb
Add graph index on tag labels
SHAcollision 88692b2
Changes before merge to main
tipogi 2530f8d
Merge branch 'main' into feat/hot-tags
tipogi 3c7b3f2
fix unclosed delimiter error
tipogi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -208,3 +208,54 @@ pub fn get_user_following(user_id: &str, skip: Option<usize>, limit: Option<usiz | |
} | ||
query(&query_string).param("user_id", user_id) | ||
} | ||
|
||
// Retrieves popular tags across the entire network | ||
// Results ordered by post count (descending), effectively ranking "hot" tags. | ||
pub fn get_global_hot_tags_scores(threshold: u64) -> Query { | ||
query( | ||
" | ||
MATCH (u:User)-[tag:TAGGED]->(p:Post) | ||
WITH tag.label AS label, COUNT(DISTINCT p) AS uniquePosts | ||
WHERE uniquePosts >= $threshold | ||
RETURN COLLECT([toFloat(uniquePosts), label]) AS hot_tags | ||
", | ||
) | ||
.param("threshold", threshold as f64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this threshold is a good idea. It's okay if we use more memory on this sorted set. |
||
} | ||
|
||
// Retrieves popular hot tags taggers across the entire network | ||
pub fn get_global_hot_tags_taggers(tag_list: &[&str]) -> Query { | ||
query( | ||
" | ||
UNWIND $labels AS tag_name | ||
MATCH (u:User)-[tag:TAGGED]->(p:Post) | ||
WHERE tag.label = tag_name | ||
WITH tag.label AS label, COLLECT(DISTINCT u.id) AS userIds | ||
RETURN COLLECT(userIds) AS tag_user_ids | ||
", | ||
) | ||
.param("labels", tag_list) | ||
} | ||
|
||
// Analyzes tag usage for a specific list of user IDs. Groups tags by name, | ||
// showing for each: label, post count and list of user IDs | ||
// Orders by post_count (descending). | ||
// Note: Only considers users from the provided users_id list. | ||
pub fn get_tags_by_user_ids(users_id: &[&str]) -> Query { | ||
query( | ||
" | ||
UNWIND $ids AS id | ||
MATCH (u:User)-[tag:TAGGED]->(p:Post) | ||
WHERE u.id = id | ||
WITH tag.label AS label, COLLECT(DISTINCT u.id) AS taggers, COUNT(DISTINCT p) AS uniquePosts | ||
WITH { | ||
label: label, | ||
tagger_ids: taggers, | ||
post_count: uniquePosts | ||
} AS hot_tag | ||
ORDER BY hot_tag.post_count DESC | ||
RETURN COLLECT(hot_tag) AS hot_tags | ||
", | ||
) | ||
.param("ids", users_id) | ||
} |
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,5 +1,5 @@ | ||
pub mod info; | ||
pub mod post; | ||
pub mod tag; | ||
pub mod traits; | ||
pub mod user; | ||
pub mod traits; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query does not seem to order the results by desceding post count. It would need something like this before the
RETURN
statement:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tipogi This query still does not sort by descending post count. Maybe it works as intended this way, but the docstring is not correct.