Skip to content
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

questions in full text search + show 15 results #2136

Merged
merged 4 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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