diff --git a/app/assets/javascripts/restful_typeahead.js b/app/assets/javascripts/restful_typeahead.js index 8512881219..437ed82077 100644 --- a/app/assets/javascripts/restful_typeahead.js +++ b/app/assets/javascripts/restful_typeahead.js @@ -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) { diff --git a/app/models/revision.rb b/app/models/revision.rb index 032eafca07..254eabe9a4 100644 --- a/app/models/revision.rb +++ b/app/models/revision.rb @@ -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, diff --git a/app/services/typeahead_service.rb b/app/services/typeahead_service.rb index 44e9dd5c41..d5649d4128 100644 --- a/app/services/typeahead_service.rb +++ b/app/services/typeahead_service.rb @@ -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,