fix(tours): search along a tour through the places index along the line, and name what could not be searched (PLN-02, CW-05)

The search along a tour found nothing. It asked the places index for all
kinds of a stretch at once, above the 100 rows and 200 characters of terms
the index takes, so the index refused and every stretch went to the public
Overpass mirrors, which do not answer from this server. Now the index is
asked in small circles strung along the line, one request per kind and
circle within its limits, and an empty circle counts as an answer, so a
city walk lists its sights, museums, parks, cafes, restaurants and markets
in well under a second. The kinds the index does not know (viewpoints,
huts, drinking water, toilets and the like) are asked of Overpass along the
whole line at the same time, one query per stretch of up to 50 km, three at
a time, each with a short deadline of its own; a line past 400 km is
searched along its start and says so. When the index answers no circle at
all, its kinds go to Overpass beside the others instead of after them. A
kind no source could be searched for is named in a calm notice above the
list instead of reporting nothing found, and the reason is written to the
log. Unnamed taps, toilets, shelters, picnic spots, viewpoints, summits,
slipways and repair stands stay in the list and on the map under the name
of their kind; an unnamed garden, cafe or memorial is left out. The places
nearest the line are kept when there are more than sixty, listed from the
start, with the opening hours the source has.

A walk's parks are parks and gardens only, and its museums are museums
and galleries only, no longer the beaches, summits, theatres and cinemas of
the map's explore buttons; a water park the index files under parks is not
one of them. The index also answers markets and summits. The explore
buttons keep their single request, and a search of several kinds that
would exceed the index limits is asked one kind at a time instead of being
refused. The MCP tool search_tour_pois and its wiki row describe the walk
kinds and the new unavailable list, and the OVERPASS_TIMEOUT_MS row says
the search along a tour keeps its own shorter deadline.
This commit is contained in:
Maurice
2026-10-19 22:34:10 +00:00
parent 9ed944c1e6
commit 3c823e07f4
55 changed files with 1841 additions and 236 deletions
@@ -152,7 +152,11 @@ function ThemeGrid({
);
}
/** What the search answered beyond its places: out of date, offline, failed, partly searched, cut, or empty. */
/**
* What the search answered beyond its places: out of date, offline, failed,
* kinds that could not be searched, partly searched, cut, or empty. Nothing
* found is said only when every kind was searched.
*/
function SearchNotices({ search, unit }: { search: TourPoiSearch; unit: Unit }) {
const { t } = useTranslation();
const { status, answer, outdated } = search;
@@ -166,7 +170,9 @@ function SearchNotices({ search, unit }: { search: TourPoiSearch; unit: Unit })
);
if (!answer) return null;
// Out of date is no fault, the route was just changed (often by adding a place from here): said plainly.
const unavailable = answer.unavailable.map((category) => t(TOUR_POI_LOOKS[category].labelKey)).join(', ');
const notes = [
unavailable && t('tours.poi.unavailable', { kinds: unavailable }),
answer.partial && t('tours.poi.partial'),
answer.capped && t('tours.poi.capped'),
answer.truncated && t('tours.poi.truncated'),
@@ -179,7 +185,7 @@ function SearchNotices({ search, unit }: { search: TourPoiSearch; unit: Unit })
{note}
</TourNotice>
))}
{answer.pois.length === 0 && (
{answer.pois.length === 0 && answer.unavailable.length === 0 && (
<p className="m-0 text-content-muted" style={fs(12, 'body')}>
{t('tours.poi.empty', { distance: formatDistance(km(search.corridorM), unit) })}
</p>
@@ -2,6 +2,7 @@ import { act, renderHook, waitFor } from '@testing-library/react';
import type { TourPoi, TourPoiSearchResponse } from '@trek/shared';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen, within } from '../../../../tests/helpers/render';
import { TranslationProvider } from '../../../i18n/TranslationContext';
import { OnlineOnlyError } from '../../../repo/onlineOnly';
import { tourPoiSearchRepo } from '../../../repo/tourPoiSearchRepo';
import { useTourPoiStore } from '../../../store/tourPoiStore';
@@ -9,9 +10,10 @@ import type { TourPlannerWaypoint } from '../planner/tourPlannerWaypoints';
import type { TourPlannerController } from '../planner/useTourPlanner';
import { TourPoiSearchCard } from './TourPoiSearchCard';
import { usePoiInsertion, type PoiInsertionPlanner } from './usePoiInsertion';
import { useTourPoiMarkers } from './useTourPoiMarkers';
import { useTourPoiSearch } from './useTourPoiSearch';
// FE-TOUR-POI-001 to FE-TOUR-POI-008
// FE-TOUR-POI-001 to FE-TOUR-POI-010
vi.mock('../planner/useWaypointPlaceNames', () => ({ useWaypointPlaceNames: () => ({}) }));
@@ -39,7 +41,13 @@ const SPRING: TourPoi = {
distance_m: 80,
along_m: 1650,
};
const ANSWER: TourPoiSearchResponse = { pois: [SPRING], truncated: false, partial: false, capped: false };
const ANSWER: TourPoiSearchResponse = {
pois: [SPRING],
truncated: false,
partial: false,
capped: false,
unavailable: [],
};
let search: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
@@ -203,4 +211,38 @@ describe('TourPoiSearchCard', () => {
fireEvent.click(within(row).getByTestId('tour-poi-add'));
await waitFor(() => expect(planner.editWaypoints).toHaveBeenCalledTimes(1));
});
it('FE-TOUR-POI-009: names the kinds that could not be searched, and does not claim nothing was found', async () => {
search.mockResolvedValue({ ...ANSWER, pois: [], unavailable: ['viewpoint', 'shelter'] });
render(<TourPoiSearchCard planner={searchPlanner()} />);
fireEvent.click(screen.getByTestId('tour-poi-search'));
expect(
await screen.findByText('Could not be searched right now: Viewpoints, Huts and shelters. Try again in a moment.')
).toBeInTheDocument();
expect(screen.queryByText(/Nothing found/)).not.toBeInTheDocument();
});
it('FE-TOUR-POI-010: an unnamed place is named by its kind in the list, on the map and once taken in', async () => {
const tap: TourPoi = { ...SPRING, id: 'node:2', name: '' };
search.mockResolvedValue({ ...ANSWER, pois: [tap] });
const planner = { ...searchPlanner(), ...insertionPlanner() } as unknown as TourPlannerController;
render(<TourPoiSearchCard planner={planner} />);
fireEvent.click(screen.getByTestId('tour-poi-search'));
const row = await screen.findByTestId('tour-poi-node:2');
expect(within(row).getByRole('button', { name: /Drinking water/ })).toBeInTheDocument();
const markers = renderHook(() => useTourPoiMarkers(), { wrapper: TranslationProvider });
expect(markers.result.current.pois.map((poi) => poi.name)).toEqual(['Drinking water']);
let taking = insertionPlanner();
const { result, rerender } = renderHook(() => usePoiInsertion(taking), { wrapper: TranslationProvider });
act(() => {
result.current.insert(tap);
});
const added = vi.mocked(taking.setSelectedWaypointId).mock.calls[0]?.[0] as string;
const withPoint = [PA, PB, { id: added, lat: tap.lat, lng: tap.lng, role: 'via' as const }, PC];
taking = insertionPlanner({ waypoints: withPoint, routeCurrent: false, status: 'routing' });
rerender();
expect(result.current.outcome).toEqual({ kind: 'measuring', name: 'Drinking water' });
});
});
@@ -1,7 +1,9 @@
import type { TourPoi } from '@trek/shared';
import { useCallback, useState } from 'react';
import { useTranslation } from '../../../i18n';
import { useTourPoiStore } from '../../../store/tourPoiStore';
import { randomId } from '../../../utils/randomId';
import { TOUR_POI_LOOKS } from '../../Map/poiCategories';
import type { TourPlannerWaypoint } from '../planner/tourPlannerWaypoints';
import type { TourPlannerController, TourPlannerStatus } from '../planner/useTourPlanner';
import { defaultAfterId, insertionBlock, withPointAfter } from './poiInsertion';
@@ -57,6 +59,7 @@ function measuresOf(planner: PoiInsertionPlanner): Measures | null {
* hand or a fixed line is never cut: the point after which it would go says why.
*/
export function usePoiInsertion(planner: PoiInsertionPlanner) {
const { t } = useTranslation();
const select = useTourPoiStore((state) => state.select);
const [afterChoice, setAfterChoice] = useState<{ poiId: string; afterId: string } | null>(null);
const [inserted, setInserted] = useState<Inserted | null>(null);
@@ -88,11 +91,13 @@ export function usePoiInsertion(planner: PoiInsertionPlanner) {
const before = measuresOf(planner);
planner.editWaypoints((current) => withPointAfter(current, afterId, point) ?? current);
planner.setSelectedWaypointId(point.id);
setInserted({ pointId: point.id, name: poi.name, before, pointCount: next.length });
// An unnamed place (a tap, a bench) is told by its kind, as the list names it.
const name = poi.name || t(TOUR_POI_LOOKS[poi.category].labelKey);
setInserted({ pointId: point.id, name, before, pointCount: next.length });
select(null);
return true;
},
[afterIdFor, planner, select]
[afterIdFor, planner, select, t]
);
const dismiss = useCallback(() => setInserted(null), []);
@@ -1,19 +1,22 @@
import { useMemo } from 'react';
import { useTranslation } from '../../../i18n';
import { useTourPoiStore } from '../../../store/tourPoiStore';
import type { Poi } from '../../Map/poiCategories';
import { TOUR_POI_LOOKS, type Poi } from '../../Map/poiCategories';
/**
* PLN-02: the places found along the tour as the planner map draws POIs, each
* in its category's look, and a click on one that picks it in the card.
* in its category's look, and a click on one that picks it in the card. An
* unnamed place (a tap, a bench) is named by its kind, as the list names it.
*/
export function useTourPoiMarkers(): { pois: Poi[]; onPoiClick: (poi: Poi) => void } {
const { t } = useTranslation();
const found = useTourPoiStore((state) => state.pois);
const select = useTourPoiStore((state) => state.select);
const pois = useMemo(
() =>
found.map((poi): Poi => ({
osm_id: poi.id,
name: poi.name,
name: poi.name || t(TOUR_POI_LOOKS[poi.category].labelKey),
lat: poi.lat,
lng: poi.lng,
category: poi.category,
@@ -25,7 +28,7 @@ export function useTourPoiMarkers(): { pois: Poi[]; onPoiClick: (poi: Poi) => vo
cuisine: null,
source: poi.source,
})),
[found]
[found, t]
);
return { pois, onPoiClick: (poi: Poi) => select(poi.osm_id) };
}