-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve textSearch_profiles result (#3134)
* Version 1: implementing new version of profiles endpoint and fixing recentPeople endpoint * Code climate * Code climate * Code climate [2] * Code climate [3] * Code climate [4] * Refactoring getRecentProfiles method * fixing order_by X sort_by * Trying to fix travis error * trying to fix travis again * using find_users * Fix User.search query * Fixing conflict * Giving better names for the methods * Hacking travis
- Loading branch information
1 parent
ed75ab7
commit 17827d1
Showing
18 changed files
with
539 additions
and
345 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
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' | ||
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.