Research: Equipment Metadata and Filtering
Feature: 030-equipment-metadata-filteringDate: 2026-11-16 Spec: spec.md
1. Current State Audit
Discovery Catalog (search table & BaseProvider)
src/camply/db/models/search.pyalready definescampsite_types,has_electric,has_water,has_sewer,pets_allowed,ada_accessible, andmax_rv_length.src/camply/server/routers/search.pyandSearch.search()already accepthas_electric,pets_allowed, andmin_rv_length, and serializehas_electric,has_water,has_sewer,pets_allowed,ada_accessible,max_rv_length, andcampsite_typesinSearchResultResponse.- Gap 1:
BaseProvider.search_campground_statementandBaseProvider.search_rec_area_statement(src/camply/providers/base.py) omit all seven amenity/RV columns when populatingsearch, leaving them at schema defaults (False/None). - Gap 2:
Campground(src/camply/db/models/campgrounds.py) does not persist normalized capability columns, sopopulate_search_tablehas no campground-level source to copy or aggregate intosearch. - Gap 3:
/api/v1/search/explore(andSearchPage.tsx) exposeselectric,pets, andrv, but does not yet expose anada_accessiblequery filter despite the column already existing onSearch.
Saved Scans & Poller Matching (user_scans, scan_results, availability.py)
UserScan(src/camply/db/models/user_scans.py) currently supportsmin_stay_length,preferred_types,require_electric, andallowed_weekdays.ScanResult(src/camply/db/models/scan_results.py) already persistscampsite_type,is_electric, andis_accessible, andCampsiteDTOcarriesis_electric,is_accessible, and provider-specificmetadata.- Gap 4:
CampsiteDTOandScanResulthave no normalized top-levelmax_vehicle_length: int | Noneorpermitted_equipment: list[str]fields. - Gap 5:
UserScanhas nomin_rv_length: int | None(required vehicle length in whole feet) orrequire_accessible: boolpreference, andmatches_scan_filters(src/camply/db/availability.py) does not evaluate length or accessibility. - Gap 6:
alerts.py(matching_opening) andarea_alerts.pyrevalidate pending outbox payloads againstmatches_scan_filters; notification metadata snapshots must includeis_accessible,max_vehicle_length, andpermitted_equipmentso revalidation after scan edits matchesmatching_scan_resultsidentically.
2. Provider Capabilities & Extraction Strategy
Decision 1: Unified Site Capability Normalization on CampsiteDTO
- Decision: Add
max_vehicle_length: int | None = Noneandpermitted_equipment: list[str] = Field(default_factory=list)directly toCampsiteDTO(and persistmax_vehicle_length+permitted_equipmentonScanResult), alongside existingcampsite_type,is_electric, andis_accessible. - Rationale: Keeping normalized capabilities on
CampsiteDTOandScanResultavoids provider-specific parsing insidedb/availability.pyorworker/, preserves Constitution Principle IV (clean provider/worker separation), and lets every subscriber sharing aUniqueTargetfilter independently against cachedScanResultrows. - Alternatives considered: Parsing provider-specific
metadataJSON blobs insideavailability.py— rejected because every provider uses different keys (VehicleLength,permitted_equipment,Attributes,max_length) andScanResultdoes not currently storemetadata.
Decision 2: Provider-by-Provider Extraction Rules
- Recreation.gov (
src/camply/providers/recreation_gov/):- Site-level (
RecDotGovCampsite): Already fetchespermitted_equipment: list[RecDotGovEquipment](equipment_name,max_length: float),accessible: bool, andattributes(AttributeName/AttributeValue).- Compute
max_vehicle_lengthfromRecDotGovEquipmententries whoseequipment_namedenotes drivable/towable RV/trailer/vehicle equipment (excluding"Tent"-only or"Small Tent"entries when checking RV/vehicle length; ifmax_length > 0, floor to positiveintfeet, treating<= 0asNone). Also inspect driveway/pad length attributes whenpermitted_equipmentomits RV entries.
- Compute
- Discovery-level (
populate_database/ RIDB): The existingRIDBFullExport_V1_JSON.zipstreamed duringpopulate_databasecontainsCampsites_API_v1.json,CampsiteAttributes_API_v1.json, andPermittedEquipment_API_v1.json(or facility attributes in the same archive). Stream those files inijsonduringpopulate_databaseto compute per-FacilityIDaggregatehas_electric,has_water,has_sewer,pets_allowed,ada_accessible,max_rv_length, andcampsite_typesbefore committingCampgroundandSearchatomically.
- Site-level (
- UseDirect (10 deployments) (
src/camply/providers/usedirect/):- Site-level (
AvailabilityUnit): Already readsUnitTypesGroups,SleepingUnitIds->permitted_equipment,IsAda, andVehicleLength: int | None. MapVehicleLength> 0 directly tomax_vehicle_length(treating<= 0orNoneasNone). - Discovery-level (
populate_database+ optional enrichment): UseDirect'sfd/placesandfd/facilitiesomit per-site amenities, whilesearch/filtersexposesUnitTypesGroups/NightlySleepingUnitsandusedirect/enrichment.pyalready fetchesParkInformation(includingTrailerMaxLength/RVMaxLengthand park attributes) intoCampground.details. Duringpopulate_database, retain/promote any verified capabilities fromFacility/ existingdetails.vehicle_limitsor facility park-information endpoints without adding unbounded per-facility HTTP calls to the atomic catalog sync; enrichments that refreshCampground.detailscan also refresh the normalized discovery summary andSearchrow.
- Site-level (
- GoingToCamp (14 deployments) (
src/camply/providers/going_to_camp/):- Site-level (
Resource): Already decodesallowedEquipmentintopermitted_equipment(e.g.,"RV/Trailer up to 35ft","2 Trailers/RVs up to 40ft") anddefinedAttributesintodecoded_attributes(e.g.,"Equipment Length","Max Vehicle Length","Electrical Service","ADA Accessible"). Extractmax_vehicle_lengthconservatively by inspecting numeric length attributes and RV/trailer/vehicle equipment labels (converting metric"m"strings conservatively downward to whole feet viamath.floor(meters * 3.28084)and takingintfeet from"ft"/"'"patterns). - Discovery-level: GoingToCamp catalog sync fetches bulk
transactionlocation,resourceLocation,bookingcategories, andresourcecategory(it does not fetch per-campgroundresourcelocation/resourcesacross 100+ campgrounds in one sync).populate_databasepopulatescampsite_typesfromresourceCategoryIds+ResourceCategorydisplay names where determinable (e.g., cabin/tent/RV), while preserving any verified site-derived or enriched attributes already observed for the campground rather than blocking catalog sync with hundreds of HTTP requests.
- Site-level (
- ReserveAmerica (
src/camply/providers/reserve_america/):- Site-level (
Site): Already receivesdetails.attributes: list[Attribute](id,name,value) on every availability grid response! Extractmax_vehicle_lengthfrom length attributes (such as max vehicle/driveway/RV/trailer length attributes, positive integer feet only) and normalizepermitted_equipmentfrom equipment/site-type attributes alongside existingis_electric(attr218) andis_accessible(attr104). - Discovery-level: ReserveAmerica's bulk search endpoint (
/search) and facility detail API (facilities/{contract}/{facility}inreserve_america/enrichment.py) expose facility attributes (pets,electric,water,sewer,ada,max_rv_lengthwhere published); map verified attributes duringpopulate_database/ enrichment without inventing unverified amenities.
- Site-level (
3. Length & Filter Matching Semantics
Decision 3: Fail-Closed Filtering & Length Conversion
- Decision:
- User
min_rv_lengthis an optional integer in whole feet (1 <= min_rv_length <= 200,Nonewhen unrestricted). Inputs<= 0or> 200fail Pydantic validation before writes. - Matching rule in
matches_scan_filters:preferred_types: existing rule (not scan.preferred_types or campsite_type in scan.preferred_types).require_electric: existing rule (not scan.require_electric or is_electric is True).require_accessible:not scan.require_accessible or is_accessible is True.min_rv_length:scan.min_rv_length is None or (max_vehicle_length is not None and max_vehicle_length >= scan.min_rv_length).
- Unit conversion: If an upstream provider supplies fractional feet (e.g.
27.5) or meters (e.g.8m), floor conservatively to whole feet (27ft /26ft) so a site never falsely passes a user's length requirement. If upstream supplies0or<= 0, normalize toNone(unknown/not RV-rated).
- User
- Rationale: Matches
FR-007,FR-009,FR-010, and Constitution Principle I (accuracy over false positives). - Alternatives considered: Allowing
max_vehicle_length is Noneto passmin_rv_lengthwith a UI warning — rejected because alerting RV campers on tent-only or unknown-pad-length sites causes real booking failures.
Decision 4: Portable SQLite & PostgreSQL Aggregation for search_rec_area_statement
- Decision: Compute
RecreationAreadiscovery summaries directly inBaseProvider.search_rec_area_statementfrom enabled, reservable childCampgroundrows using portable SQL (func.max(case((Campground.has_electric.is_(True), 1), else_=0)) == 1,func.max(Campground.max_rv_length), and unioningcampsite_typesor storing pre-aggregated capabilities cleanly). - Rationale:
camply-webruns on both SQLite (standalone + tests) and PostgreSQL (distributed). Avoids PostgreSQL-onlyBOOL_ORorARRAY_AGGinBaseProvider, keeping both migration and query paths identical. Note: Because SQLite storesARRAY(String).with_variant(JSON(), "sqlite")as JSON arrays, aggregating distinctcampsite_typesper recreation area in Python or via a lightweight query duringpopulate_search_tableavoids dialect-specific array aggregation SQL completely! - Alternatives considered: Dialect-branched
BOOL_OR/json_group_arraySQL — rejected for unnecessary SQLite/Postgres divergence.
Decision 5: Shared Target Deduplication & Outbox Compatibility
- Decision:
min_rv_lengthandrequire_accessiblelive onUserScanonly and MUST NOT be included inUniqueTargethash orUserScan.definition_hash? Wait: checkdefinition_hash!- Let's verify:
UserScan.definition_hashdeduplicates identical scan definitions per user (provider_id,destination_type,destination_id,start_date,end_date,coverage_mode,selected_ids). Preferences (min_stay_length,preferred_types,require_electric,allowed_weekdays) are NOT indefinition_hashorUniqueTarget.hash! Keepingmin_rv_lengthandrequire_accessiblein the same preference bucket preserves oneUniqueTargetper(provider_id, campground_id, start_date, end_date)across all subscribers.
- Let's verify:
- Backward Compatibility: All new
UserScan,ScanResult, andCampgroundcolumns are nullable or have safe defaults (require_accessible = False,min_rv_length = None,max_vehicle_length = None,permitted_equipment = None). ExistingScanResultrows withoutmax_vehicle_lengthcontinue working for unrestricted scans and fail closed for strict length scans until the next poll refreshes the row.