feat: Wikidata engine and Wikipedia knowledge infobox
- Add wikidata engine (wbsearchentities), tests, factory/planner/config - Wikipedia REST summary: infobox from extract, thumbnail, article URL - InfoboxView URL; render infobox list in results_inner + base styles - Preferences Wikidata toggle; engine badge color for wikidata Made-with: Cursor
This commit is contained in:
parent
6e45abb150
commit
24577b27be
13 changed files with 344 additions and 34 deletions
|
|
@ -123,13 +123,13 @@ func (e *WikipediaEngine) Search(ctx context.Context, req contracts.SearchReques
|
|||
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
return contracts.SearchResponse{
|
||||
Query: req.Query,
|
||||
NumberOfResults: 0,
|
||||
Results: []contracts.MainResult{},
|
||||
Answers: []map[string]any{},
|
||||
Corrections: []string{},
|
||||
Infoboxes: []map[string]any{},
|
||||
Suggestions: []string{},
|
||||
Query: req.Query,
|
||||
NumberOfResults: 0,
|
||||
Results: []contracts.MainResult{},
|
||||
Answers: []map[string]any{},
|
||||
Corrections: []string{},
|
||||
Infoboxes: []map[string]any{},
|
||||
Suggestions: []string{},
|
||||
UnresponsiveEngines: [][2]string{},
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -141,9 +141,13 @@ func (e *WikipediaEngine) Search(ctx context.Context, req contracts.SearchReques
|
|||
var api struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Extract string `json:"extract"`
|
||||
Titles struct {
|
||||
Display string `json:"display"`
|
||||
} `json:"titles"`
|
||||
Thumbnail struct {
|
||||
Source string `json:"source"`
|
||||
} `json:"thumbnail"`
|
||||
ContentURLs struct {
|
||||
Desktop struct {
|
||||
Page string `json:"page"`
|
||||
|
|
@ -160,7 +164,7 @@ func (e *WikipediaEngine) Search(ctx context.Context, req contracts.SearchReques
|
|||
// API returned a non-standard payload; treat as no result.
|
||||
return contracts.SearchResponse{
|
||||
Query: req.Query,
|
||||
NumberOfResults: 0,
|
||||
NumberOfResults: 0,
|
||||
Results: []contracts.MainResult{},
|
||||
Answers: []map[string]any{},
|
||||
Corrections: []string{},
|
||||
|
|
@ -175,36 +179,61 @@ func (e *WikipediaEngine) Search(ctx context.Context, req contracts.SearchReques
|
|||
title = api.Title
|
||||
}
|
||||
|
||||
content := api.Description
|
||||
content := strings.TrimSpace(api.Extract)
|
||||
if content == "" {
|
||||
content = strings.TrimSpace(api.Description)
|
||||
}
|
||||
|
||||
urlPtr := pageURL
|
||||
pub := (*string)(nil)
|
||||
|
||||
// Knowledge infobox for HTML (Wikipedia REST summary: title, extract, thumbnail, link).
|
||||
var infoboxes []map[string]any
|
||||
ibTitle := api.Titles.Display
|
||||
if ibTitle == "" {
|
||||
ibTitle = api.Title
|
||||
}
|
||||
body := strings.TrimSpace(api.Extract)
|
||||
if body == "" {
|
||||
body = strings.TrimSpace(api.Description)
|
||||
}
|
||||
imgSrc := strings.TrimSpace(api.Thumbnail.Source)
|
||||
if ibTitle != "" || body != "" || imgSrc != "" {
|
||||
row := map[string]any{
|
||||
"title": ibTitle,
|
||||
"infobox": body,
|
||||
"url": pageURL,
|
||||
}
|
||||
if imgSrc != "" {
|
||||
row["img_src"] = imgSrc
|
||||
}
|
||||
infoboxes = append(infoboxes, row)
|
||||
}
|
||||
|
||||
results := []contracts.MainResult{
|
||||
{
|
||||
Template: "default.html",
|
||||
Title: title,
|
||||
Content: content,
|
||||
URL: &urlPtr,
|
||||
Pubdate: pub,
|
||||
Engine: "wikipedia",
|
||||
Score: 0,
|
||||
Category: "general",
|
||||
Priority: "",
|
||||
Template: "default.html",
|
||||
Title: title,
|
||||
Content: content,
|
||||
URL: &urlPtr,
|
||||
Pubdate: pub,
|
||||
Engine: "wikipedia",
|
||||
Score: 0,
|
||||
Category: "general",
|
||||
Priority: "",
|
||||
Positions: nil,
|
||||
Engines: []string{"wikipedia"},
|
||||
Engines: []string{"wikipedia"},
|
||||
},
|
||||
}
|
||||
|
||||
return contracts.SearchResponse{
|
||||
Query: req.Query,
|
||||
NumberOfResults: len(results),
|
||||
NumberOfResults: len(results),
|
||||
Results: results,
|
||||
Answers: []map[string]any{},
|
||||
Corrections: []string{},
|
||||
Infoboxes: []map[string]any{},
|
||||
Infoboxes: infoboxes,
|
||||
Suggestions: []string{},
|
||||
UnresponsiveEngines: [][2]string{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue