From de767d4a2bb3e26a8af6e14381f46e96872ad8a5 Mon Sep 17 00:00:00 2001 From: Zemyatin Date: Fri, 30 Oct 2026 09:18:36 +0100 Subject: [PATCH 1/2] feat(search): keep summary with latLong in semantic item format --- hub3/fragments/resource.go | 4 ++++ hub3/fragments/resource_test.go | 12 ++++++++++++ hub3/server/http/handlers/search.go | 20 ++++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/hub3/fragments/resource.go b/hub3/fragments/resource.go index 7b76e8fb..dd87a576 100644 --- a/hub3/fragments/resource.go +++ b/hub3/fragments/resource.go @@ -2132,6 +2132,10 @@ func (sum *ResultSummary) AddEntry(entry *ResourceEntry, langs ...string) { if sum.Date == "" { sum.Date = entry.Value } + case "latLong": + if sum.LatLong == "" { + sum.LatLong = entry.LatLong + } } } } diff --git a/hub3/fragments/resource_test.go b/hub3/fragments/resource_test.go index 6bc83521..bc8cdd78 100644 --- a/hub3/fragments/resource_test.go +++ b/hub3/fragments/resource_test.go @@ -305,6 +305,18 @@ var _ = Describe("Resource", func() { Expect(sum.Title).To(Equal("test1")) Expect(sum.Thumbnail).To(BeEmpty()) }) + + It("should set latLong from a latLong tagged entry", func() { + entry := &ResourceEntry{ + Value: "52.54081312693048,5.058354400324099", + LatLong: "52.54081312693048,5.058354400324099", + Tags: []string{"latLong"}, + } + sum := &ResultSummary{} + Expect(sum.LatLong).To(BeEmpty()) + sum.AddEntry(entry) + Expect(sum.LatLong).To(Equal("52.54081312693048,5.058354400324099")) + }) }) }) diff --git a/hub3/server/http/handlers/search.go b/hub3/server/http/handlers/search.go index 02349ee6..1ec64ab7 100644 --- a/hub3/server/http/handlers/search.go +++ b/hub3/server/http/handlers/search.go @@ -814,11 +814,17 @@ func ProcessSearchRequest(w http.ResponseWriter, r *http.Request, searchRequest case fragments.ItemFormatType_SEMANTIC: for _, rec := range records { rec.Semantic = rec.GenerateSemantic() - // Clear other formats to reduce payload + // Summary is not stored in the index, so it has to be generated here — + // and before Resources is cleared, since it is built by walking them. + // It carries latLong, which the semantic tree cannot: nave:DelvingResource + // is a blank node no triple points at, so a walk from the entry URI never + // reaches it. + rec.NewResultSummary(searchRequest.Language...) + // Clear the other formats to reduce payload. Summary is the exception: + // it is small, and carries the geo values the tree cannot reach. rec.Resources = nil rec.Fields = nil rec.JSONLD = nil - rec.Summary = nil rec.ProtoBuf = nil rec.Item = nil } @@ -1486,11 +1492,17 @@ func getSearchRecord(w http.ResponseWriter, r *http.Request) { record.Resources = nil case "semantic": record.Semantic = record.GenerateSemantic() - // Clear other formats to reduce payload + // Summary is not stored in the index, so it has to be generated here — + // and before Resources is cleared, since it is built by walking them. + // It carries latLong, which the semantic tree cannot: nave:DelvingResource + // is a blank node no triple points at, so a walk from the entry URI never + // reaches it. + record.NewResultSummary(lang) + // Clear the other formats to reduce payload. Summary is the exception: + // it is small, and carries the geo values the tree cannot reach. record.Resources = nil record.Fields = nil record.JSONLD = nil - record.Summary = nil record.ProtoBuf = nil record.Item = nil case "summary": From 2d5cc30734de2513a473d2efd6a856b48030e7ed Mon Sep 17 00:00:00 2001 From: Sjoerd Siebinga Date: Wed, 11 Nov 2026 17:01:09 +0100 Subject: [PATCH 2/2] feat(search): related items in the semantic format carry a summary too More-like-this items now have the same {meta, semantic, summary} as the main item, so they get latLong as well. Built by FragmentGraph.SemanticRelatedItem, which has a test. --- hub3/fragments/graph.go | 11 +++++++++++ hub3/fragments/semantic_test.go | 25 ++++++++++++++++++++++++- hub3/server/http/handlers/search.go | 8 ++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/hub3/fragments/graph.go b/hub3/fragments/graph.go index 29d33b8a..a678b31e 100644 --- a/hub3/fragments/graph.go +++ b/hub3/fragments/graph.go @@ -89,6 +89,17 @@ func (fg *FragmentGraph) AddMoreLikeThis(item *ItemV1) { fg.MoreLikeThis.Items = append(fg.MoreLikeThis.Items, item) } +// SemanticRelatedItem is fg as a related item in the semantic item format: +// the same {meta, semantic, summary} as the main item, so related items carry +// latLong too. +func (fg *FragmentGraph) SemanticRelatedItem(langs ...string) *FragmentGraph { + return &FragmentGraph{ + Meta: fg.Meta, + Semantic: fg.GenerateSemantic(), + Summary: fg.NewResultSummary(langs...), + } +} + func (fg *FragmentGraph) AddSemanticMoreLikeThis(related *FragmentGraph) { if fg.MoreLikeThis == nil { fg.MoreLikeThis = &RelatedItems{} diff --git a/hub3/fragments/semantic_test.go b/hub3/fragments/semantic_test.go index f9c945d2..88bdb05f 100644 --- a/hub3/fragments/semantic_test.go +++ b/hub3/fragments/semantic_test.go @@ -977,4 +977,27 @@ func TestCycleDetection(t *testing.T) { _, hasRefType := expandedMap["hub3:referenceType"] assert.False(t, hasRefType, "fully expanded resource should not have hub3:referenceType") }) -} \ No newline at end of file +} +func TestSemanticRelatedItem(t *testing.T) { + // The coordinates sit on a blank node no triple points at, as + // nave:DelvingResource does in Narthex-mapped records. + fg := &FragmentGraph{ + Meta: &Header{EntryURI: "http://example.org/record/1"}, + Resources: []*FragmentResource{ + {ID: "http://example.org/record/1", Entries: []*ResourceEntry{ + {Predicate: "http://purl.org/dc/elements/1.1/title", Value: "Kaart", Tags: []string{"title"}}, + }}, + {ID: "_:b0", Entries: []*ResourceEntry{ + {Value: "52.54,5.05", LatLong: "52.54,5.05", Tags: []string{"latLong"}}, + }}, + }, + } + + rel := fg.SemanticRelatedItem("nl") + + require.NotNil(t, rel.Summary) + assert.Equal(t, "52.54,5.05", rel.Summary.LatLong) + assert.Same(t, fg.Meta, rel.Meta) + assert.NotNil(t, rel.Semantic) + assert.Nil(t, rel.Resources) +} diff --git a/hub3/server/http/handlers/search.go b/hub3/server/http/handlers/search.go index 1ec64ab7..1f6d1374 100644 --- a/hub3/server/http/handlers/search.go +++ b/hub3/server/http/handlers/search.go @@ -1545,13 +1545,9 @@ func getSearchRecord(w http.ResponseWriter, r *http.Request) { // Use semantic format for MLT when itemFormat is semantic // This ensures consistent field names between parent and related items - // Related items have same structure as main item: {meta, semantic} + // Related items have same structure as main item: {meta, semantic, summary} if itemFormat == "semantic" { - relatedItem := &fragments.FragmentGraph{ - Meta: fg.Meta, - Semantic: fg.GenerateSemantic(), - } - record.AddSemanticMoreLikeThis(relatedItem) + record.AddSemanticMoreLikeThis(fg.SemanticRelatedItem(lang)) } else { // Use ItemV1 format for other itemFormats fg.NewV1Fields()