refactor: clean up verbose and redundant comments
Trim or remove comments that: - State the obvious (function names already convey purpose) - Repeat what the code clearly shows - Are excessively long without adding value Keep comments that explain *why*, not *what*.
This commit is contained in:
parent
805e7ffdc2
commit
5b942a5fd6
11 changed files with 16 additions and 102 deletions
|
|
@ -30,11 +30,7 @@ import (
|
|||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
// QwantEngine implements a `qwant` (web) adapter using
|
||||
// Qwant v3 endpoint: https://api.qwant.com/v3/search/web.
|
||||
//
|
||||
// Qwant's API is not fully documented; this implements parsing logic
|
||||
// for the `web` category.
|
||||
// QwantEngine implements the Qwant v3 API (web and web-lite modes).
|
||||
type QwantEngine struct {
|
||||
client *http.Client
|
||||
category string // "web" (JSON API) or "web-lite" (HTML fallback)
|
||||
|
|
@ -53,8 +49,6 @@ func (e *QwantEngine) Search(ctx context.Context, req contracts.SearchRequest) (
|
|||
return contracts.SearchResponse{Query: req.Query}, nil
|
||||
}
|
||||
|
||||
// For API parity we use web defaults: count=10, offset=(pageno-1)*count.
|
||||
// The engine's config field exists so we can expand to news/images/videos later.
|
||||
count := e.resultsPerPage
|
||||
if count <= 0 {
|
||||
count = 10
|
||||
|
|
@ -271,9 +265,7 @@ func (e *QwantEngine) searchWebLite(ctx context.Context, req contracts.SearchReq
|
|||
results := make([]contracts.MainResult, 0)
|
||||
seen := map[string]bool{}
|
||||
|
||||
// Pattern 1: legacy/known qwant-lite structure.
|
||||
doc.Find("section article").Each(func(_ int, item *goquery.Selection) {
|
||||
// ignore randomly interspersed advertising adds
|
||||
if item.Find("span.tooltip").Length() > 0 {
|
||||
return
|
||||
}
|
||||
|
|
@ -307,19 +299,14 @@ func (e *QwantEngine) searchWebLite(ctx context.Context, req contracts.SearchReq
|
|||
})
|
||||
})
|
||||
|
||||
// Pattern 2: broader fallback for updated lite markup:
|
||||
// any article/list item/div block containing an external anchor.
|
||||
// We keep this conservative by requiring non-empty title + URL.
|
||||
doc.Find("article, li, div").Each(func(_ int, item *goquery.Selection) {
|
||||
if len(results) >= 20 {
|
||||
return
|
||||
}
|
||||
// Skip ad-like blocks in fallback pass too.
|
||||
if item.Find("span.tooltip").Length() > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Skip obvious nav/footer blocks.
|
||||
classAttr, _ := item.Attr("class")
|
||||
classLower := strings.ToLower(classAttr)
|
||||
if strings.Contains(classLower, "nav") || strings.Contains(classLower, "footer") {
|
||||
|
|
@ -368,13 +355,10 @@ func (e *QwantEngine) searchWebLite(ctx context.Context, req contracts.SearchReq
|
|||
}
|
||||
seen[href] = true
|
||||
|
||||
// Best-effort snippet extraction from nearby paragraph/span text.
|
||||
content := strings.TrimSpace(item.Find("p").First().Text())
|
||||
if content == "" {
|
||||
content = strings.TrimSpace(item.Find("span").First().Text())
|
||||
}
|
||||
// If there is no snippet, still keep clearly external result links.
|
||||
// Qwant-lite frequently omits rich snippets for some entries.
|
||||
|
||||
u := href
|
||||
results = append(results, contracts.MainResult{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue