shuffle code around so excerpt is not messed up
This commit is contained in:
parent
12ecf8624a
commit
a4aedddd38
|
@ -7,12 +7,22 @@ class SearchObserver < ActiveRecord::Observer
|
||||||
HtmlScrubber.scrub(html)
|
HtmlScrubber.scrub(html)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_index(table, id, search_data)
|
def self.update_index(table, id, raw_data)
|
||||||
search_data = Search.prepare_data(search_data)
|
raw_data = Search.prepare_data(raw_data)
|
||||||
|
|
||||||
table_name = "#{table}_search_data"
|
table_name = "#{table}_search_data"
|
||||||
foreign_key = "#{table}_id"
|
foreign_key = "#{table}_id"
|
||||||
|
|
||||||
|
# insert some extra words for I.am.a.word so "word" is tokenized
|
||||||
|
search_data = raw_data.gsub(/\p{L}*\.\p{L}*/) do |with_dot|
|
||||||
|
split = with_dot.split(".")
|
||||||
|
if split.length > 1
|
||||||
|
with_dot + (" " << split[1..-1].join(" "))
|
||||||
|
else
|
||||||
|
with_dot
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# for user login and name use "simple" lowercase stemmer
|
# for user login and name use "simple" lowercase stemmer
|
||||||
stemmer = table == "user" ? "simple" : Search.long_locale
|
stemmer = table == "user" ? "simple" : Search.long_locale
|
||||||
|
|
||||||
|
@ -20,16 +30,22 @@ class SearchObserver < ActiveRecord::Observer
|
||||||
# when inserting data like this.
|
# when inserting data like this.
|
||||||
rows = Post.exec_sql_row_count("UPDATE #{table_name}
|
rows = Post.exec_sql_row_count("UPDATE #{table_name}
|
||||||
SET
|
SET
|
||||||
raw_data = :search_data,
|
raw_data = :raw_data,
|
||||||
locale = :locale,
|
locale = :locale,
|
||||||
search_data = TO_TSVECTOR('#{stemmer}', :search_data)
|
search_data = TO_TSVECTOR('#{stemmer}', :search_data)
|
||||||
WHERE #{foreign_key} = :id",
|
WHERE #{foreign_key} = :id",
|
||||||
search_data: search_data, id: id, locale: SiteSetting.default_locale)
|
raw_data: raw_data,
|
||||||
|
search_data: search_data,
|
||||||
|
id: id,
|
||||||
|
locale: SiteSetting.default_locale)
|
||||||
if rows == 0
|
if rows == 0
|
||||||
Post.exec_sql("INSERT INTO #{table_name}
|
Post.exec_sql("INSERT INTO #{table_name}
|
||||||
(#{foreign_key}, search_data, locale, raw_data)
|
(#{foreign_key}, search_data, locale, raw_data)
|
||||||
VALUES (:id, TO_TSVECTOR('#{stemmer}', :search_data), :locale, :search_data)",
|
VALUES (:id, TO_TSVECTOR('#{stemmer}', :search_data), :locale, :raw_data)",
|
||||||
search_data: search_data, id: id, locale: SiteSetting.default_locale)
|
raw_data: raw_data,
|
||||||
|
search_data: search_data,
|
||||||
|
id: id,
|
||||||
|
locale: SiteSetting.default_locale)
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
# don't allow concurrency to mess up saving a post
|
# don't allow concurrency to mess up saving a post
|
||||||
|
@ -125,14 +141,7 @@ class SearchObserver < ActiveRecord::Observer
|
||||||
|
|
||||||
def characters(string)
|
def characters(string)
|
||||||
scrubbed << " "
|
scrubbed << " "
|
||||||
scrubbed << string.gsub(/\p{L}*\.\p{L}*/) do |with_dot|
|
scrubbed << string
|
||||||
split = with_dot.split(".")
|
|
||||||
if split.length > 1
|
|
||||||
with_dot + (" " << split[1..-1].join(" "))
|
|
||||||
else
|
|
||||||
with_dot
|
|
||||||
end
|
|
||||||
end
|
|
||||||
scrubbed << " "
|
scrubbed << " "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue