-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1840 from elzj/search_overhaul
Issue 4044: Search overhaul, part 1
- Loading branch information
Showing
24 changed files
with
743 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
class BookmarkIndexer < Indexer | ||
|
||
def self.klass | ||
'Bookmark' | ||
end | ||
|
||
def self.index_all(options={}) | ||
options[:skip_delete] = true | ||
BookmarkableIndexer.delete_index | ||
BookmarkableIndexer.create_index | ||
create_mapping | ||
BookmarkedExternalWorkIndexer.index_all(skip_delete: true) | ||
BookmarkedSeriesIndexer.index_all(skip_delete: true) | ||
BookmarkedWorkIndexer.index_all(skip_delete: true) | ||
super | ||
end | ||
|
||
def self.mapping | ||
{ | ||
"bookmark" => { | ||
"_parent" => { | ||
type: 'bookmarkable' | ||
}, | ||
properties: { | ||
bookmarkable_type: { | ||
type: 'string', | ||
index: 'not_analyzed' | ||
}, | ||
bookmarker: { | ||
type: 'string', | ||
analyzer: 'simple' | ||
}, | ||
notes: { | ||
type: 'string', | ||
analyzer: 'snowball' | ||
}, | ||
tag: { | ||
type: 'string', | ||
analyzer: 'simple' | ||
} | ||
} | ||
} | ||
} | ||
end | ||
|
||
#################### | ||
# INSTANCE METHODS | ||
#################### | ||
|
||
# TODO: Make this work for deleted bookmarks | ||
def routing_info(id) | ||
{ | ||
'_index' => index_name, | ||
'_type' => document_type, | ||
'_id' => id, | ||
'parent' => objects[id.to_i].bookmarkable_id | ||
} | ||
end | ||
|
||
def document(object) | ||
tags = object.tags | ||
filters = tags.map{ |t| t.filter }.compact | ||
|
||
object.as_json( | ||
root: false, | ||
except: [:notes_sanitizer_version, :delta], | ||
methods: [:bookmarker, :collection_ids, :with_notes] | ||
).merge( | ||
tag: (tags + filters).map(&:name).uniq, | ||
tag_ids: tags.map(&:id), | ||
filter_ids: filters.map(&:id) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class BookmarkQuery < Query | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class BookmarkableIndexer < Indexer | ||
|
||
def self.index_name | ||
"ao3_#{Rails.env}_bookmarks" | ||
end | ||
|
||
def self.document_type | ||
'bookmarkable' | ||
end | ||
|
||
def self.mapping | ||
{ | ||
'bookmarkable' => { | ||
properties: { | ||
title: { | ||
type: 'string', | ||
analyzer: 'simple' | ||
}, | ||
creators: { | ||
type: 'string', | ||
analyzer: 'simple', | ||
index_name: 'creator' | ||
}, | ||
tag: { | ||
type: 'string', | ||
analyzer: 'simple' | ||
}, | ||
work_types: { | ||
type: 'string', | ||
index: 'not_analyzed', | ||
index_name: 'work_type' | ||
} | ||
} | ||
} | ||
} | ||
end | ||
|
||
def routing_info(id) | ||
{ | ||
'_index' => index_name, | ||
'_type' => document_type, | ||
'_id' => "#{id}-#{klass.underscore}" | ||
} | ||
end | ||
|
||
def document(object) | ||
object.bookmarkable_json | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class BookmarkedExternalWorkIndexer < BookmarkableIndexer | ||
def self.klass | ||
"ExternalWork" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class BookmarkedSeriesIndexer < BookmarkableIndexer | ||
def self.klass | ||
"Series" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class BookmarkedWorkIndexer < BookmarkableIndexer | ||
def self.klass | ||
"Work" | ||
end | ||
|
||
# Only index works with bookmarks | ||
def self.indexables | ||
Work.joins(:stat_counter).where("bookmarks_count > 0") | ||
end | ||
end |
Oops, something went wrong.