...
 
Commits (1)
......@@ -9,6 +9,8 @@ window.init = ->
character_required = $("[name='search[character_required][]']")
character_optional = $("[name='search[character_optional][]']")
character_optional_exclude = $("[name='search[character_optional_exclude]']")
relationships = $("[name='search[relationship][0][]']")
relationships_exact = $("[name='search[relationship_exact][0]']")
tags_include_ids = $("[name='search[tags_include_ids][]']")
tags_exclude_ids = $("[name='search[tags_exclude_ids][]']")
fandoms = $("[name='search[fandoms][]']")
......@@ -31,6 +33,7 @@ window.init = ->
selectors = {title,author,summary,saved,
category_required,category_optional,category_optional_exclude,
character_required,character_optional,character_optional_exclude,
relationships, relationships_exact,
fandoms,crossovers,include_source_fandoms
status,language,rating,
tags_include_ids, tags_exclude_ids,
......@@ -45,6 +48,7 @@ window.init = ->
category_optional.chosen()
character_required.chosen({max_selected_options: 4})
character_optional.chosen()
relationships.chosen({max_selected_options: 4})
tags_include_ids.chosen()
tags_exclude_ids.chosen()
fandoms.chosen().off('change').on('change', (e,p) -> updateFandom(e,p))
......@@ -67,6 +71,9 @@ window.init = ->
$('#clear_character_optional').click ->
character_optional.val([])
$('#clear_relationship').click ->
character_optional.val([])
$('#advanced_search :checkbox').click ->
updateCheckboxLabel($(this))
......@@ -125,27 +132,17 @@ window.init = ->
if params.length > 0
$.getJSON("/characters?"+params.join('&'), (data) ->
select = $("[name='search[character_required][]']")
select2 = $("[name='search[character_optional][]']")
existing = select.val()
existing2 = select2.val()
options = select.prop('options')
options2 = select2.prop('options')
$('option', select).remove()
$('option', select2).remove()
$.each(data, (k,v) ->
options[options.length] = new Option(v.name,v.id)
options2[options.length] = new Option(v.name,v.id)
)
select.val(existing)
select2.val(existing2)
select.trigger('chosen:updated');
select2.trigger('chosen:updated');
for x in ['character_required', 'character_optional', 'relationships[0]']
select = $("[name='search["+x+"][]']")
existing = select.val()
options = select.prop('options')
$('option', select).remove()
$.each(data, (k,v) ->
options[options.length] = new Option(v.name,v.id)
)
select.val(existing)
select.trigger('chosen:updated');
)
updateFandom = (e,p,c) ->
......
......@@ -32,6 +32,7 @@ class Search < ActiveRecord::Base
@@fields = Set.new(%w(fandoms crossovers include_source_fandoms title author summary
category_required category_optional category_optional_exclude
character_required character_optional character_optional_exclude
relationship
tags_include tags_exclude
language status rating
wordcount_lower wordcount_upper chapters_lower chapters_upper
......@@ -53,6 +54,7 @@ class Search < ActiveRecord::Base
self.character_required ||= []
self.character_optional ||= []
self.character_optional_exclude ||= false
self.relationship ||= {}
self.tags_include_ids ||= []
self.tags_exclude_ids ||= []
self.language ||= 'english'
......
......@@ -21,7 +21,7 @@ class SearchQuery
}
}
indexes = ['ffn_index']
indexes = ['ffn2_index']
unless search.crossovers.empty?
if search.include_source_fandoms
indexes << 'ffncrossover_index'
......@@ -254,6 +254,25 @@ class SearchQuery
end
end
unless search.relationship.empty?
search.relationship.values.map do |ship|
subclauses = ship.map do |c|
term 'meta.relationships.characters.id' => c.to_i
end
clauses << {
nested: {
path: 'meta.relationships',
query: {
bool: {
must: subclauses
}
}
}
}
end
end
clauses << (terms 'meta.rated' => search.rating)
if search.wordcount_lower
......
......@@ -172,6 +172,24 @@
</div>
</div>
<h3><i class="fa fa-heart text-muted"></i> Relationship</h3>
<div class="row">
<div class="form-group col-lg-6">
<label for="search[relationship][0][]">Characters</label>
<small class="text-muted">Multi-select coming soon. <i>Note: not all stories are tagged appropriately.</i></small>
<select multiple
class="form-control"
data-placeholder="Choose up to 4 characters in relationships"
name="search[relationship][0][]"
id="search[relationship][0][]">
<option disabled></option>
<%= options_from_collection_for_select(@characters, :id, :name, @search[:relationship]) %>
</select>
<div class="visible-sm-block visible-xs-block">
<button type="button" id="clear_relationship" class="btn-sm btn btn-success">Clear Relationship</button>
</div>
</div>
</div>
<h3><i class="fa fa-tag text-muted"></i> Tags</h3>
<div class="row">
<div class="form-group col-lg-6">
......
class AddRelationshipToSearch < ActiveRecord::Migration[5.1]
def change
add_column :searches, :relationship, :jsonb
end
end
This diff is collapsed.