Commit 375f48a7 by Greg Price

Index and query ES using english analyzer

parent 78c8e6b8
......@@ -31,7 +31,7 @@ class Comment < Content
include Tire::Model::Callbacks
mapping do
indexes :body, type: :string, analyzer: :snowball, stored: true, term_vector: :with_positions_offsets
indexes :body, type: :string, analyzer: :english, stored: true, term_vector: :with_positions_offsets
indexes :course_id, type: :string, index: :not_analyzed, included_in_all: false
#indexes :comment_thread_id, type: :string, stored: true, index: :not_analyzed, included_in_all: false
#current prod tire doesn't support indexing BSON ids, will reimplement when we upgrade
......
# -*- coding: utf-8 -*-
require 'new_relic/agent/method_tracer'
require_relative 'content'
......@@ -26,8 +27,8 @@ class CommentThread < Content
include Tire::Model::Callbacks
mapping do
indexes :title, type: :string, analyzer: :snowball, boost: 5.0, stored: true, term_vector: :with_positions_offsets
indexes :body, type: :string, analyzer: :snowball, stored: true, term_vector: :with_positions_offsets
indexes :title, type: :string, analyzer: :english, boost: 5.0, stored: true, term_vector: :with_positions_offsets
indexes :body, type: :string, analyzer: :english, stored: true, term_vector: :with_positions_offsets
indexes :created_at, type: :date, included_in_all: false
indexes :updated_at, type: :date, included_in_all: false
indexes :last_activity_at, type: :date, included_in_all: false
......@@ -98,7 +99,7 @@ class CommentThread < Content
search = Tire::Search::Search.new 'comment_threads'
search.query {|query| query.match :_all, params["text"]} if params["text"]
search.query {|query| query.match [:title, :body], params["text"]} if params["text"]
search.highlight({title: { number_of_fragments: 0 } } , {body: { number_of_fragments: 0 } }, options: { tag: "<highlight>" })
search.filter(:term, commentable_id: params["commentable_id"]) if params["commentable_id"]
search.filter(:terms, commentable_id: params["commentable_ids"]) if params["commentable_ids"]
......@@ -126,7 +127,7 @@ class CommentThread < Content
if params["text"]
search = Tire::Search::Search.new 'comments'
search.query {|query| query.match :_all, params["text"]} if params["text"]
search.query {|query| query.match :body, params["text"]} if params["text"]
search.filter(:term, course_id: params["course_id"]) if params["course_id"]
search.size CommentService.config["max_deep_search_comment_count"].to_i
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment