← All repositories

reportage

A life-logging app for iPhone

git clone https://code.inqk.net/reportage.git


commit afa9bec0b07beefb78fe99ecec80ff72f48fca5d
parent ec27c00574d6b4a1c79863d7975f67a79dca97c9
Author: Michael Camilleri <[email protected]>
Date:   Thu, 22 Oct 2026 15:07:13 +0900

Match narrative forms when searching tokens

A token whose name is in another script, such as a person written in
kanji, could only be found by typing that script, even when the user
had given it an English narrative form.

This commit matches the search text against a token's narrative form
as well as its name and the names of tokens merged into it. The check
is shared, so it applies to survey token lists, the place picker and
the vocabulary settings alike. Vocabulary entries now carry the
narrative form for this.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Diffstat

MShared/Persistence/ReportStore.swift | 3++-
MShared/Persistence/Vocabulary.swift | 8++++++--
MTests/Unit/SurveyModelTests.swift | 9+++++++++

3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/Shared/Persistence/ReportStore.swift b/Shared/Persistence/ReportStore.swift

@@ -275,7 +275,8 @@ struct ReportStore: Sendable {
                     text: token.text,
                     useCount: 0,
                     coordinate: token.place?.coordinate,
-                    externalID: token.place?.externalID
+                    externalID: token.place?.externalID,
+                    narrativeForm: token.narrativeForm
                 )
             }
             return entries

diff --git a/Shared/Persistence/Vocabulary.swift b/Shared/Persistence/Vocabulary.swift

@@ -16,14 +16,17 @@ struct VocabularyEntry: Identifiable, Hashable, Sendable {
     /// For places: the locality of the most recent report that used it,
     /// which tells apart places with the same name.
     var locality: String?
+    /// How the token reads in a narrative, when that differs from `text`.
+    var narrativeForm: String?
     /// The tokens merged into this one, directly or along a chain, most
     /// used first. Their names still find it.
     var merged: [MergedToken] = []
 
-    /// Whether the token's name, or the name of a token merged into it,
-    /// contains `text`.
+    /// Whether the token's name, its narrative form or the name of a token
+    /// merged into it contains `text`.
     func matches(_ text: String) -> Bool {
         self.text.localizedStandardContains(text)
+            || narrativeForm?.localizedStandardContains(text) == true
             || merged.contains { $0.text.localizedStandardContains(text) }
     }
 }
@@ -142,6 +145,7 @@ enum Vocabulary {
                     coordinate: token.place?.coordinate ?? centre,
                     externalID: token.place?.externalID,
                     locality: localities[token.id],
+                    narrativeForm: token.narrativeForm,
                     merged: (merged[token.id] ?? []).sorted { lhs, rhs in
                         lhs.useCount != rhs.useCount
                             ? lhs.useCount > rhs.useCount

diff --git a/Tests/Unit/SurveyModelTests.swift b/Tests/Unit/SurveyModelTests.swift

@@ -327,6 +327,15 @@ struct TokenPickerTests {
         #expect(picker.selection == ["2"])
     }
 
+    @Test("Searching finds an entry by its narrative form")
+    func narrativeForm() {
+        var person = VocabularyEntry(id: "1", text: "山田花子", useCount: 1)
+        person.narrativeForm = "Hanako"
+        let picker = TokenPicker(questionID: "Q", allowsMultiple: true, entries: [person])
+        picker.query = "hana"
+        #expect(picker.visibleEntries.map(\.id) == ["1"])
+    }
+
     @Test("Adding text that names an entry selects the entry")
     func addExisting() {
         let picker = makePicker()