[deploy] Fix listing tags bug (#7533)

* Fix listing tags bug

* Fix failing specs

* Fix failing specs

* Fix failig spec

* Fix failing specs

* Refactor code

* Fix failing specs

* Support AND/OR queries based on params

* Add tag_boolean to search params
This commit is contained in:
Sai Bhargav 2020-04-28 14:04:09 +00:00 committed by GitHub
parent 8140e46ceb
commit 2d20d67594
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View file

@ -8,6 +8,7 @@ class SearchController < ApplicationController
:classified_listing_search,
:page,
:per_page,
:tag_boolean_mode,
{
tags: []
},

View file

@ -331,6 +331,7 @@ export class Listings extends Component {
page,
per_page: LISTING_PAGE_SIZE,
tags,
tag_boolean_mode: 'all',
};
const responsePromise = fetchSearch('classified_listings', dataHash);

View file

@ -60,10 +60,16 @@ module Search
end
def term_keys
TERM_KEYS.map do |term_key|
TERM_KEYS.flat_map do |term_key|
next unless @params.key? term_key
{ terms: { term_key => Array.wrap(@params[term_key]) } }
values = Array.wrap(@params[term_key])
if params[:tag_boolean_mode] == "all" && term_key == :tags
values.map { |tag| { terms: { term_key => Array.wrap(tag) } } }
else
{ terms: { term_key => values } }
end
end.compact
end

View file

@ -16,11 +16,25 @@ RSpec.describe Search::QueryBuilders::ClassifiedListing, type: :service do
describe "#as_hash" do
it "applies TERM_KEYS from params" do
params = { category: "cfp", tags: ["beginner"], contact_via_connect: false }
params = { category: "cfp", tags: %w[beginner intermediate professional], contact_via_connect: false }
filter = described_class.new(params: params)
exepcted_filters = [
{ "terms" => { "category" => ["cfp"] } },
{ "terms" => { "tags" => %w[beginner intermediate professional] } },
{ "terms" => { "contact_via_connect" => [false] } },
{ "terms" => { "published" => [true] } },
]
expect(filter.as_hash.dig("query", "bool", "filter")).to match_array(exepcted_filters)
end
it "applies TERM_KEYS from params with boolean mode" do
params = { category: "cfp", tags: %w[beginner intermediate professional], contact_via_connect: false, tag_boolean_mode: "all" }
filter = described_class.new(params: params)
exepcted_filters = [
{ "terms" => { "category" => ["cfp"] } },
{ "terms" => { "tags" => ["beginner"] } },
{ "terms" => { "tags" => ["intermediate"] } },
{ "terms" => { "tags" => ["professional"] } },
{ "terms" => { "contact_via_connect" => [false] } },
{ "terms" => { "published" => [true] } },
]