-
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.
Merge pull request #1 from david-days/to_service
Foundation structure for searching feature
- Loading branch information
Showing
5 changed files
with
48 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class SearchService | ||
|
||
def initialize | ||
end | ||
|
||
def type_ahead(id) | ||
matches = [] | ||
|
||
DrupalNode.limit(5) | ||
.order("nid DESC") | ||
.where('type = "note" AND node.status = 1 AND title LIKE ?', "%" + id + "%") | ||
.select("title,type,nid,path").each do |match| | ||
matches << "<i data-url='"+match.path+"' class='fa fa-file'></i> "+match.title | ||
end | ||
DrupalNode.limit(5) | ||
.order("nid DESC") | ||
.where('(type = "page" OR type = "place" OR type = "tool") AND node.status = 1 AND title LIKE ?', "%" + id + "%") | ||
.select("title,type,nid,path").each do |match| | ||
matches << "<i data-url='"+match.path+"' class='fa fa-"+match.icon+"'></i> "+match.title | ||
end | ||
DrupalNode.limit(5) | ||
.order("nid DESC") | ||
.where('type = "map" AND node.status = 1 AND title LIKE ?', "%" + id + "%") | ||
.select("title,type,nid,path").each do |match| | ||
matches << "<i data-url='"+match.path+"' class='fa fa-"+match.icon+"'></i> "+match.title | ||
end | ||
DrupalUsers.limit(5) | ||
.order("uid DESC") | ||
.where('name LIKE ? AND access != 0', "%" + id + "%").each do |match| | ||
matches << "<i data-url='/profile/"+match.name+"' class='fa fa-user'></i> "+match.name | ||
end | ||
DrupalTag.includes(:drupal_node) | ||
.where('node.status = 1') | ||
.limit(5) | ||
.where('name LIKE ?', "%" + id + "%").each do |match| | ||
matches << "<i data-url='/tag/"+match.name+"' class='fa fa-tag'></i> "+match.name | ||
end | ||
return matches | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.users @users | ||
json.notes @notes |