fix: regexp.DotAll flag in google engine and Metadata field removal
- google.go: use inline (?s) flag instead of regexp.DotAll second arg - youtube.go: remove Metadata field (not in MainResult contract) - config_test.go: fix expected engine count from 9 to 11 (google+youtube)
This commit is contained in:
parent
b499db68f7
commit
f1436310eb
3 changed files with 3 additions and 7 deletions
|
|
@ -14,8 +14,8 @@ func TestLoadDefaults(t *testing.T) {
|
||||||
if cfg.Server.Port != 8080 {
|
if cfg.Server.Port != 8080 {
|
||||||
t.Errorf("expected default port 8080, got %d", cfg.Server.Port)
|
t.Errorf("expected default port 8080, got %d", cfg.Server.Port)
|
||||||
}
|
}
|
||||||
if len(cfg.Engines.LocalPorted) != 9 {
|
if len(cfg.Engines.LocalPorted) != 11 {
|
||||||
t.Errorf("expected 9 default engines, got %d", len(cfg.Engines.LocalPorted))
|
t.Errorf("expected 11 default engines, got %d", len(cfg.Engines.LocalPorted))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ func extractGoogleSnippet(block string) string {
|
||||||
func extractGoogleSuggestions(body string) []string {
|
func extractGoogleSuggestions(body string) []string {
|
||||||
var suggestions []string
|
var suggestions []string
|
||||||
// SearXNG xpath: //div[contains(@class, "ouy7Mc")]//a
|
// SearXNG xpath: //div[contains(@class, "ouy7Mc")]//a
|
||||||
suggestionPattern := regexp.MustCompile(`<div[^>]*class="[^"]*ouy7Mc[^"]*"[^>]*>.*?<a[^>]*>([^<]+)</a>`, regexp.DotAll)
|
suggestionPattern := regexp.MustCompile(`(?s)<div[^>]*class="[^"]*ouy7Mc[^"]*"[^>]*>.*?<a[^>]*>([^<]+)</a>`)
|
||||||
matches := suggestionPattern.FindAllStringSubmatch(body, -1)
|
matches := suggestionPattern.FindAllStringSubmatch(body, -1)
|
||||||
seen := map[string]bool{}
|
seen := map[string]bool{}
|
||||||
for _, m := range matches {
|
for _, m := range matches {
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,6 @@ func (e *YouTubeEngine) Search(ctx context.Context, req contracts.SearchRequest)
|
||||||
Score: 1.0,
|
Score: 1.0,
|
||||||
Category: "videos",
|
Category: "videos",
|
||||||
Engines: []string{"youtube"},
|
Engines: []string{"youtube"},
|
||||||
Metadata: map[string]any{
|
|
||||||
"channel": item.Snippet.ChannelTitle,
|
|
||||||
"video_id": item.Snippet.ResourceID.VideoID,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue