Skip to content

Commit

Permalink
questions in full text search + show 15 results (publiclab#2136)
Browse files Browse the repository at this point in the history
* Update typeahead_service.rb

* Update typeahead_service.rb

* Update restful_typeahead.js

* Update revision.rb
  • Loading branch information
jywarren authored and Souravirus committed Mar 12, 2018
1 parent fb72e8f commit 789f2b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/restful_typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
jQuery(document).ready(function() {
var el = $('input.search-query.typeahead');
var typeahead = el.typeahead({
items: 8,
items: 15,
minLength: 3,
autoSelect: false,
source: function (query, process) {
Expand Down
2 changes: 2 additions & 0 deletions app/models/revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Revision < ActiveRecord::Base

belongs_to :node, foreign_key: 'nid', dependent: :destroy, counter_cache: :drupal_node_revisions_count
has_one :drupal_users, foreign_key: 'uid'
has_many :node_tag, foreign_key: 'nid'
has_many :tag, through: :node_tag

validates :title,
presence: :true,
Expand Down
29 changes: 20 additions & 9 deletions app/services/typeahead_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,27 @@ def search_tags(srchString, limit = 5)
end

# Search question entries for matching text
def search_questions(srchString, limit = 5)
def search_questions(input, limit = 5)
sresult = TagList.new
questions = Node.where(
'type = "note" AND node.status = 1 AND title LIKE ?',
'%' + srchString + '%'
)
.joins(:tag)
.where('term_data.name LIKE ?', 'question:%')
.order('node.nid DESC')
.limit(limit)
if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
questions = Node.search(input)
.group(:nid)
.includes(:node)
.references(:node)
.limit(limit)
.where("node.type": "note", "node.status": 1)
.order('node.changed DESC')
.joins(:tag)
.where('term_data.name LIKE ?', 'question:%')
else
questions = Node.where('title LIKE ?', '%' + input + '%')
.joins(:tag)
.where('term_data.name LIKE ?', 'question:%')
.limit(limit)
.group(:nid)
.where(type: "note", status: 1)
.order(changed: :desc)
end
questions.each do |match|
tval = TagResult.fromSearch(
match.nid,
Expand Down

0 comments on commit 789f2b6

Please sign in to comment.