diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index fd08262..f784170 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -49,6 +49,6 @@ input#show-advanced:checked + div { padding-left: 12rem; } -.rating > div { - margin-right: 2px; +.rating > div, .characters > div { + margin-right: 3px; } \ No newline at end of file diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index b2ff31c..9547223 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -25,6 +25,20 @@ class SearchController < ApplicationController s.add_query(match: { title: { query: @search_params['q'], operator: :and } }) if @search_params['q'].present? s.add_query(match: { author: { query: @search_params['author'], operator: :and } }) if @search_params['author'].present? + # tags -> match any of the included tags, exclude any of the excluded tags + tag_musts, tag_must_nots = parse_tag_queries + boolses = {} + + boolses[:must] = ( + tag_musts.map { |t| { term: { tags: t } } } + ) if tag_musts.any? + + boolses[:must_not] = ( + tag_must_nots.map { |t| { term: { tags: t } } } + ) if tag_must_nots.any? + + s.add_query(bool: boolses ) if boolses.any? + # ratings -> match stories with any of them s.add_filter(bool: { should: @search_params['ratings'].keys.map { |k| { term: { content_rating: k } } } @@ -35,12 +49,6 @@ class SearchController < ApplicationController should: @search_params['state'].keys.map { |k| { term: { completion_status: k } } } }) if @search_params['state'].present? - # tags -> match any of the included tags, exclude any of the excluded tags - tag_musts, tag_must_nots = parse_tag_queries - - s.add_filter(terms: { tags: tag_musts }) if tag_musts.any? - s.add_filter(bool: { must_not: { terms: { tags: tag_must_nots } } }) if tag_must_nots.any? - # sort direction if using_random s.add_sort _random: :desc @@ -68,7 +76,11 @@ class SearchController < ApplicationController def parse_tag_queries tag_searches = (@search_params['tags'] + ',' + @search_params['characters']).split(',').reject &:blank? - [tag_searches.select { |t| t[0] != '-' }, tag_searches.select { |t| t[0] == '-' }] + [ + tag_searches.select { |t| t[0] != '-' }, + tag_searches.select { |t| t[0] == '-' } + .map { |t| t[1..] } + ] end def parse_sort