-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve textSearch_profiles result #3134
Merged
jywarren
merged 15 commits into
publiclab:master
from
milaaraujo:profiles-endpoint-most-recently-people
Aug 14, 2018
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
79830b1
Version 1: implementing new version of profiles endpoint and fixing r…
milaaraujo 1b01f35
Code climate
milaaraujo d46de64
Code climate
milaaraujo 068960f
Code climate [2]
milaaraujo ed2e00b
Code climate [3]
milaaraujo 562cef8
Code climate [4]
milaaraujo 7a9375b
Refactoring getRecentProfiles method
milaaraujo 1676896
fixing order_by X sort_by
milaaraujo bc84a5a
Trying to fix travis error
0f62acd
trying to fix travis again
d72f02a
using find_users
milaaraujo 218c140
Fix User.search query
fa1bae2
Fixing conflict
a2ac3ca
Giving better names for the methods
42c5e32
Hacking travis
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
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,12 +1,30 @@ | ||
class SearchCriteria | ||
attr_reader :query, :tag | ||
attr_reader :query, :tag, :sort_by | ||
|
||
def initialize(query, tag = nil) | ||
def initialize(query, tag: nil, sort_by: nil, order_direction: "DESC") | ||
@query = query | ||
@tag = tag | ||
@sort_by = sort_by | ||
@order_direction = order_direction | ||
end | ||
|
||
def valid? | ||
!query.nil? && query != 0 | ||
end | ||
|
||
def order_direction | ||
sanitize_direction(@order_direction) | ||
end | ||
|
||
private | ||
|
||
def sanitize_direction(direction) | ||
if direction.present? | ||
direction = direction.upcase | ||
options = %w(DESC ASC) | ||
options.include?(direction) ? direction : "DESC" | ||
else | ||
"DESC" | ||
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
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
13 changes: 13 additions & 0 deletions
13
db/migrate/20180804042601_add_full_text_index_on_username.rb
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,13 @@ | ||
class AddFullTextIndexOnUsername < ActiveRecord::Migration[5.2] | ||
def up | ||
if ActiveRecord::Base.connection.adapter_name == 'Mysql2' | ||
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. This is awesome!!! 🐎 |
||
add_index :rusers, :username, type: :fulltext, name: 'rusers_username_fulltext_idx' | ||
end | ||
end | ||
|
||
def down | ||
if ActiveRecord::Base.connection.adapter_name == 'Mysql2' | ||
remove_index :rusers, name: 'rusers_username_fulltext_idx' | ||
end | ||
end | ||
end |
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.
@jywarren gold lesson from this PR about the MySQL fulltext search: the 'IN BOOLEAN MODE' modifier with the * wildcard.
https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html
really glad that this is working now, thanks for the help!