diff options
author | 2017-05-21 01:13:58 -0700 | |
---|---|---|
committer | 2017-05-21 01:14:07 -0700 | |
commit | d2343bd3830339b69ffec29e5a4e9648af640c44 (patch) | |
tree | 87967eafd7321b0e34a5d7c94d7ddf10abdfa060 | |
parent | Update asset URLs, use SVG logo (diff) | |
download | frontend-d2343bd3830339b69ffec29e5a4e9648af640c44.tar.gz frontend-d2343bd3830339b69ffec29e5a4e9648af640c44.tar.bz2 frontend-d2343bd3830339b69ffec29e5a4e9648af640c44.zip |
Implement hidden messages to block out spam.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r-- | lib/index.rb | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/lib/index.rb b/lib/index.rb index 6aee1e2..c4b0ff0 100644 --- a/lib/index.rb +++ b/lib/index.rb @@ -1,8 +1,12 @@ PER_PAGE = 100 +def index_names(list) + 'ml-' + list +end + def threads_in_month(list, year, month, page) $es.search( - index: 'ml-' + list, + index: index_name(list), size: PER_PAGE, from: PER_PAGE * (page - 1), body: { @@ -17,6 +21,7 @@ def threads_in_month(list, year, month, page) } } }, + filter: { not: { filter: { term: { hidden: true } } } }, sort: { date: 'desc' } @@ -26,12 +31,11 @@ end def most_recent(list, n) result = $es.search( - index: 'ml-' + list, + index: index_name(list), size: n, body: { - sort: { - date: 'desc' - } + sort: { date: 'desc' }, + filter: { not: { filter: { term: { hidden: true } } } } } ) @@ -46,7 +50,7 @@ end def messages_in_month(list, year, month, page) $es.search( - index: 'ml-' + list, + index: index_name(list), size: PER_PAGE, from: PER_PAGE * (page - 1), body: { @@ -57,6 +61,7 @@ def messages_in_month(list, year, month, page) } } }, + filter: { not: { filter: { term: { hidden: true } } } }, sort: { date: 'desc' } @@ -66,11 +71,12 @@ end def get_month_listing(list) $es.search( - index: 'ml-' + list, + index: index_name(list), search_type: 'count', size: 0, body: { size: 0, + filter: { not: { filter: { term: { hidden: true } } } }, aggs: { messages_by_month: { terms: { @@ -95,9 +101,11 @@ end def get_message_count_internal(list) $es.search( - index: 'ml-' + list, - size: 1, - body: {} + index: index_name(list), + size: 0, + body: { + filter: { not: { filter: { term: { hidden: true } } } } + } )['hits']['total'] rescue => _e '?' @@ -105,16 +113,11 @@ end def get_message(list, hash) $es.search( - index: 'ml-' + list, + index: index_name(list), size: 1, body: { - query: { - filtered: { - filter: { - term: { _id: hash } - } - } - } + query: { filtered: { filter: { term: { _id: hash } } } }, + filter: { not: { filter: { term: { hidden: true } } } } } ) end @@ -123,8 +126,11 @@ def get_parent_data(list, parent_id) return nil if parent_id.nil? parent = $es.search( - index: 'ml-' + list, - body: { query: { match: { _id: parent_id } } } + index: index_name(list), + body: { + query: { match: { _id: parent_id } }, + filter: { not: { filter: { term: { hidden: true } } } } + } ) if parent['hits']['total'] == 0 @@ -138,10 +144,11 @@ def get_child_data(list, parent_id) return nil if parent_id.nil? children = $es.search( - index: 'ml-' + list, + index: index_name(list), size: 100, body: { query: { match: { parent: parent_id } }, + filter: { not: { filter: { term: { hidden: true } } } }, sort: { date: 'asc' } } ) |