From 8a026069363ce8f55ce2130c3daad8eea37c6566 Mon Sep 17 00:00:00 2001 From: Muhamed Isabegovic Date: Thu, 8 Oct 2026 09:45:13 +0200 Subject: [PATCH 1/2] Filter explore results by tag - Add Browse.by_tag: locations carry tags, and a tag's experiences, plans and moments are the ones that reach a tagged location, so the scope mirrors by_city_name rather than adding a browses column - Read a tag param on explore, carry it in filter_params so load-more reproduces it, and count it as an active filter for own moments - Offer the curated tag sets in a filter-bar select, handled by the explore Stimulus controller like the city select, with bs/en keys Tests: not run, this machine has no bundle or test database; ruby -c clean on the changed Ruby files. --- app/controllers/new_design_controller.rb | 13 ++++- .../controllers/explore_controller.js | 12 +++++ app/models/browse.rb | 49 +++++++++++++++++++ app/views/new_design/explore.html.erb | 12 +++++ config/locales/bs.yml | 3 ++ config/locales/en.yml | 3 ++ .../controllers/new_design_controller_test.rb | 18 +++++++ wiki/initiatives/open-issues.md | 4 +- wiki/product/features.md | 4 +- wiki/state.md | 4 +- 10 files changed, 114 insertions(+), 8 deletions(-) diff --git a/app/controllers/new_design_controller.rb b/app/controllers/new_design_controller.rb index 04e243be..d59a37cb 100644 --- a/app/controllers/new_design_controller.rb +++ b/app/controllers/new_design_controller.rb @@ -63,6 +63,7 @@ def explore @duration = params[:duration] @min_rating = params[:min_rating] @city_name = params[:city_name] + @tag = params[:tag] @origin = params[:origin] @audio_support = params[:audio_support] == "true" @accessible = params[:accessible] == "true" @@ -115,6 +116,13 @@ def explore .pluck(:city) .sort + # Load tags for filter dropdown + @tags = Location.not_archived.where.not(tags: [ nil, [] ]) + .pluck(:tags) + .flatten + .uniq + .sort + # Load categories for filter dropdown @experience_categories = ExperienceCategory.active.ordered @@ -146,6 +154,7 @@ def build_browse_queries(search_types) # Build base Browse query with common filters base_browse = Browse.smart_search(@query) base_browse = base_browse.by_city_name(@city_name) if @city_name.present? + base_browse = base_browse.by_tag(@tag) if @tag.present? base_browse = base_browse.by_min_rating(@min_rating) if @min_rating.present? base_browse = base_browse.by_season(@season) if @season.present? base_browse = base_browse.by_budget(@budget) if @budget.present? @@ -240,7 +249,7 @@ def lead_own_with_named(scope) # asked for. id, partial and the *_page keys stay out — loadMore sets its own # page, and an id would re-name a moment on every fetch. def filter_params - params.permit(:q, :season, :budget, :duration, :min_rating, :city_name, + params.permit(:q, :season, :budget, :duration, :min_rating, :city_name, :tag, :origin, :audio_support, :lat, :lng, :radius, :sort, types: []) .to_h.reject { |_, value| value.blank? } end @@ -248,7 +257,7 @@ def filter_params # Unfiltered, a traveller keeps seeing every moment they own, including ones # at places since retired that browse no longer indexes. def filters_active? - @query.present? || @city_name.present? || @season.present? || @budget.present? || + @query.present? || @city_name.present? || @tag.present? || @season.present? || @budget.present? || @min_rating.present? || @origin.present? || (@lat.present? && @lng.present?) end diff --git a/app/javascript/controllers/explore_controller.js b/app/javascript/controllers/explore_controller.js index 9c9c7af2..2a948960 100644 --- a/app/javascript/controllers/explore_controller.js +++ b/app/javascript/controllers/explore_controller.js @@ -15,6 +15,7 @@ export default class extends Controller { "typeCheckbox", "filterInput", "citySelect", + "tagSelect", "audioToggle", "accessibleToggle", "nearbyButton", @@ -207,6 +208,11 @@ export default class extends Controller { formData.append("city_name", this.citySelectTarget.value) } + // Tag filter + if (this.hasTagSelectTarget && this.tagSelectTarget.value) { + formData.append("tag", this.tagSelectTarget.value) + } + // Audio support filter if (this.hasAudioToggleTarget && this.audioToggleTarget.checked) { formData.append("audio_support", "true") @@ -324,6 +330,9 @@ export default class extends Controller { // Count city select if (this.hasCitySelectTarget && this.citySelectTarget.value) count++ + // Count tag select + if (this.hasTagSelectTarget && this.tagSelectTarget.value) count++ + // Count toggles if (this.hasAudioToggleTarget && this.audioToggleTarget.checked) count++ if (this.hasAccessibleToggleTarget && this.accessibleToggleTarget.checked) count++ @@ -363,6 +372,9 @@ export default class extends Controller { // Reset city select if (this.hasCitySelectTarget) this.citySelectTarget.value = "" + // Reset tag select + if (this.hasTagSelectTarget) this.tagSelectTarget.value = "" + // Clear toggles if (this.hasAudioToggleTarget) this.audioToggleTarget.checked = false if (this.hasAccessibleToggleTarget) this.accessibleToggleTarget.checked = false diff --git a/app/models/browse.rb b/app/models/browse.rb index a5516079..2a8032b6 100644 --- a/app/models/browse.rb +++ b/app/models/browse.rb @@ -107,6 +107,55 @@ class Browse < ApplicationRecord where("category_keys @> ?", [ category_key ].to_json) } + # Filter by tag - only locations carry tags, so a tag's experiences, plans + # and moments are the ones that reach a tagged location (mirrors by_city_name) + scope :by_tag, ->(tag) { + return all if tag.blank? + + tagged_location_ids = Location + .where("EXISTS (SELECT 1 FROM jsonb_array_elements_text(tags) AS tag WHERE lower(tag) = lower(?))", tag.to_s.strip) + .pluck(:id) + return none if tagged_location_ids.empty? + + experience_ids = ExperienceLocation + .where(location_id: tagged_location_ids) + .pluck(:experience_id) + .uniq + + plan_ids = PlanExperience + .joins(experience: :experience_locations) + .where(experience_locations: { location_id: tagged_location_ids }) + .pluck(:plan_id) + .uniq + + moment_ids = Moment + .where(location_id: tagged_location_ids) + .pluck(:id) + + conditions = [] + values = [] + + conditions << "(browsable_type = 'Location' AND browsable_id IN (?))" + values << tagged_location_ids + + if experience_ids.any? + conditions << "(browsable_type = 'Experience' AND browsable_id IN (?))" + values << experience_ids + end + + if plan_ids.any? + conditions << "(browsable_type = 'Plan' AND browsable_id IN (?))" + values << plan_ids + end + + if moment_ids.any? + conditions << "(browsable_type = 'Moment' AND browsable_id IN (?))" + values << moment_ids + end + + where(conditions.join(" OR "), *values) + } + # Filter by AI generated / Human made scope :ai_generated, -> { where(ai_generated: true) } scope :human_made, -> { where(ai_generated: false) } diff --git a/app/views/new_design/explore.html.erb b/app/views/new_design/explore.html.erb index 6ae579c5..4af1bb9d 100644 --- a/app/views/new_design/explore.html.erb +++ b/app/views/new_design/explore.html.erb @@ -502,6 +502,18 @@ { class: "rounded-full border-0 bg-white dark:bg-gray-700 py-2 pl-3 pr-8 text-sm text-gray-900 dark:text-white shadow-sm ring-1 ring-inset ring-gray-200 dark:ring-gray-600 focus:ring-2 focus:ring-inset focus:ring-blue-600 dark:focus:ring-yellow-500", data: { explore_target: "citySelect", action: "change->explore#onFilterChange" } } %> + + <%# Tag Filter - Keep as select for curated tag sets %> +
+ + + + <%= f.select :tag, + options_for_select([[t("explore.tags.any"), ""]] + @tags.map { |tag| [tag, tag] }, @tag), + {}, + { class: "rounded-full border-0 bg-white dark:bg-gray-700 py-2 pl-3 pr-8 text-sm text-gray-900 dark:text-white shadow-sm ring-1 ring-inset ring-gray-200 dark:ring-gray-600 focus:ring-2 focus:ring-inset focus:ring-blue-600 dark:focus:ring-yellow-500", + data: { explore_target: "tagSelect", action: "change->explore#onFilterChange" } } %> +
diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 10ffb227..b8b54459 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -123,6 +123,7 @@ bs: audio_support: Audio ture accessible: "♿ Pristupačno" origin: Porijeklo + tag: Oznaka accessible_aria: Prikaži samo lokacije pristupačne za invalidska kolica origins: ai: AI Generirano @@ -150,6 +151,8 @@ bs: name: Naziv cities: any: Sva mjesta + tags: + any: Sve oznake loading: Učitavanje... load_more: Učitaj više results_count: Pronađeno %{count} rezultata diff --git a/config/locales/en.yml b/config/locales/en.yml index 80daeaa8..7892dfc0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -125,6 +125,7 @@ en: audio_support: Audio tours accessible: "♿ Accessible" origin: Origin + tag: Tag accessible_aria: Show only wheelchair accessible places origins: ai: AI Generated @@ -152,6 +153,8 @@ en: name: Name cities: any: All places + tags: + any: All tags loading: Loading... load_more: Load More results_count: '%{count} results found' diff --git a/test/controllers/new_design_controller_test.rb b/test/controllers/new_design_controller_test.rb index a2d5e01e..3c23d8f1 100644 --- a/test/controllers/new_design_controller_test.rb +++ b/test/controllers/new_design_controller_test.rb @@ -451,6 +451,24 @@ class NewDesignControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "explore filters by tag" do + @location.update!(tags: [ "historic" ]) + @mostar_location.update!(tags: [ "food" ]) + + get explore_path, params: { types: [ "location" ], tag: "historic" } + + assert_response :success + assert_select "a[href=?]", location_path(@location), minimum: 1 + assert_select "a[href=?]", location_path(@mostar_location), count: 0 + end + + test "explore with a tag nobody carries finds nothing" do + get explore_path, params: { types: [ "location" ], tag: "nonexistent" } + + assert_response :success + assert_select "a[href=?]", location_path(@location), count: 0 + end + test "explore filters by origin ai" do get explore_path, params: { origin: "ai" } diff --git a/wiki/initiatives/open-issues.md b/wiki/initiatives/open-issues.md index 563201e0..4923104d 100644 --- a/wiki/initiatives/open-issues.md +++ b/wiki/initiatives/open-issues.md @@ -2,7 +2,7 @@ title: Open issues kind: reference status: living -updated: 2026-09-29 +updated: 2026-10-08 repos: - usput.ba confidence: medium @@ -48,7 +48,7 @@ The 17 open GitHub issues on misabegovic/usput.ba as of 2026-09-29, grouped by t ## Explore, search and maps -- [#111](https://github.com/misabegovic/usput.ba/issues/111) **Improve explore page filters** (filter on tags). Partly addressed: explore now filters by type, season, budget, duration, rating, city, origin, audio and accessibility (`app/controllers/new_design_controller.rb`), but not by tag. Tags reach search only as full text. +- [#111](https://github.com/misabegovic/usput.ba/issues/111) **Improve explore page filters** (filter on tags). Addressed: explore now filters by type, season, budget, duration, rating, city, tag, origin, audio and accessibility (`app/controllers/new_design_controller.rb`; `app/models/browse.rb`, `by_tag`). Tags also reach full text search through the composed browse description (`app/services/browse_adapter.rb`). - [#86](https://github.com/misabegovic/usput.ba/issues/86) **Map view** for exploring and for plan, experience and location pages, with nearby places. Largely addressed: a location map (#163), map points and a map panel on places, a route page, and map cards on the plan walk (#164) and the Explore Bosnia deck (#165) (`config/routes.rb`). A map on experience pages is (unverified, 2026-09-29). - [#153](https://github.com/misabegovic/usput.ba/issues/153) **Cycling trails** (experiences for cyclists). Not addressed: no cycling experience type or trail data exists. - [#29](https://github.com/misabegovic/usput.ba/issues/29) **Area information**: live conditions for planning (roads, accidents, weather, ice). Not addressed. diff --git a/wiki/product/features.md b/wiki/product/features.md index f7d2e49a..ee45e960 100644 --- a/wiki/product/features.md +++ b/wiki/product/features.md @@ -2,7 +2,7 @@ title: Feature inventory kind: reference status: living -updated: 2026-09-30 +updated: 2026-10-08 repos: - usput.ba confidence: medium @@ -99,7 +99,7 @@ This is what Usput.ba ships as of 2026-09-29, grouped by what a person does with ## Explore and search - **Home page.** Shows positive reviews (rating 3 or more), the newest approved public moments, and trending locations and experiences with a rating of at least 3.5 (`app/controllers/new_design_controller.rb`, `home`). -- **Explore.** `/explore` searches one index, `Browse`, across locations, experiences, public plans and approved public moments. Filters: type, city, budget, minimum rating, season, duration, AI or human origin, audio support, accessibility and a nearby radius, with a sort order. Results page with load-more. A search that matches a single place expands to nearby items (`new_design_controller.rb`, `explore`, `build_browse_queries`; `app/models/browse.rb`). The most liked moments rank first ([#167](https://github.com/misabegovic/usput.ba/pull/167)). +- **Explore.** `/explore` searches one index, `Browse`, across locations, experiences, public plans and approved public moments. Filters: type, city, budget, minimum rating, season, duration, tag, AI or human origin, audio support, accessibility and a nearby radius, with a sort order. Results page with load-more. A search that matches a single place expands to nearby items (`new_design_controller.rb`, `explore`, `build_browse_queries`; `app/models/browse.rb`). The most liked moments rank first ([#167](https://github.com/misabegovic/usput.ba/pull/167)). - **Explore Bosnia deck.** `/explore-bosnia` deals places as a deck of cards, nearest first. Position orders the deck but does not bound it, so a traveller anywhere gets the whole country. Paging uses a keyset cursor because a check-in removes a place from the set. Categories combine, and a filter turned off stays off. Places already reached drop out, and an empty deck says whether nothing is here or everything has been visited. Without a browser location the deck is ordered from the city the request's IP suggests ([#165](https://github.com/misabegovic/usput.ba/pull/165); `app/controllers/explore_bosnia_controller.rb`). - **Retired places stay hidden.** An archived location leaves Browse and the traveller-facing scopes ([#167](https://github.com/misabegovic/usput.ba/pull/167); `app/models/location.rb`, `places`). diff --git a/wiki/state.md b/wiki/state.md index 9fb0a457..3da0fbae 100644 --- a/wiki/state.md +++ b/wiki/state.md @@ -2,7 +2,7 @@ title: Product state kind: reference status: living -updated: 2026-09-30 +updated: 2026-10-08 repos: - usput.ba confidence: medium @@ -62,7 +62,7 @@ Where Usput.ba has been, what is true in the code today, what the older planning ## Now - **Stack.** Rails 8.1 on PostgreSQL (PostGIS only offline, to build the Mine Checker's static artifacts, per `docs/mine_checker/README.md`), Hotwire, Tailwind, Solid Queue; two databases (`db/schema.rb`, `sources/planning/decisions/2026-02-03-remove-platform-database.md`). -- **Public product.** Home, explore (the Browse-backed search with filters for type, season, budget, duration, rating, city, origin, audio and accessibility), Explore Bosnia (a deck of places, nearest first), location, experience and plan pages, the plan wizard, walking a plan with check-ins, moments with likes, a travel profile that works without an account, reviews, `/mine-check` and the minesweeper game (`config/routes.rb`). +- **Public product.** Home, explore (the Browse-backed search with filters for type, season, budget, duration, rating, city, tag, origin, audio and accessibility), Explore Bosnia (a deck of places, nearest first), location, experience and plan pages, the plan wizard, walking a plan with check-ins, moments with likes, a travel profile that works without an account, reviews, `/mine-check` and the minesweeper game (`config/routes.rb`). - **Accounts.** Devise with sign-in by email, confirmation within three days, reset by email through Postmark, an account page, and one token that ends every session on a password change, a block or a button; #171's session rows are gone ([decision](decisions/accounts-through-devise.md)). A database holding accounts without an email cannot migrate, by design: the rebuild starts empty. - **Admin.** Avo 4 Community at `/admin`, open only to curators and admins, checked in the route and again inside Avo; users page for admins, with role changes and blocks, places, experiences and plans with all 16 languages editable, plans limited to curated ones and travellers' public ones, and audio tours ([Avo admin and roles](initiatives/avo-admin-and-roles.md)). Curators create and edit there directly; there are no proposals. What is left of the old curator dashboard runs beside it until each Avo slice replaces a part. - **Curator dashboard.** What remains at `/curator` is the start page with counts and recent activity, whose links now open the admin, the moments queue (`Moment` enum `moderation_status`), the reviews list, where only an admin removes a review, and the old users pages. Proposals (`ContentChange`, its contributions and curator reviews) and the curator pages for places, experiences, plans and audio tours were removed on 2026-09-30 ([removal plan](initiatives/remove-curator-dashboard.md)). From 7886fa40e5a45b18b34305e116c25321dec2877c Mon Sep 17 00:00:00 2001 From: Muhamed Isabegovic Date: Thu, 8 Oct 2026 10:23:46 +0200 Subject: [PATCH 2/2] [Tests] The tag select filters explore in a real browser - Choosing a tag reloads explore with only the places carrying it, and the url names the tag; the controller tests covered the server, this covers the select's wiring in explore_controller.js --- test/system/explore_tag_filter_test.rb | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/system/explore_tag_filter_test.rb diff --git a/test/system/explore_tag_filter_test.rb b/test/system/explore_tag_filter_test.rb new file mode 100644 index 00000000..02253ff1 --- /dev/null +++ b/test/system/explore_tag_filter_test.rb @@ -0,0 +1,29 @@ +require "application_system_test_case" + +# The tag select on explore in a real browser: choosing a tag reloads the +# results with only the places carrying it, and the url says which tag. +class ExploreTagFilterTest < ApplicationSystemTestCase + setup do + @historic = Location.create!(name: "Tag Fortress", city: "Jajce", lat: 44.34, lng: 17.27, tags: [ "historic" ]) + @food = Location.create!(name: "Tag Kafana", city: "Mostar", lat: 43.34, lng: 17.81, tags: [ "food" ]) + [ @historic, @food ].each { |location| Browse.sync_record(location) } + end + + teardown do + [ @historic, @food ].each { |location| location&.destroy } + end + + test "choosing a tag narrows explore to the places carrying it" do + visit explore_path(types: [ "location" ]) + assert_text "Tag Fortress" + assert_text "Tag Kafana" + + click_once_wired("[data-explore-target='filterToggle']", "explore") + find("[data-explore-target='tagSelect']").select("historic") + + assert_current_path(/tag=historic/) + assert_text "Tag Fortress" + assert_no_text "Tag Kafana" + assert_equal "historic", find("[data-explore-target='tagSelect']", visible: :all).value + end +end