add quant text results
This commit is contained in:
parent
cdbde2919c
commit
c8cf762222
4 changed files with 144 additions and 56 deletions
|
@ -1,24 +1,16 @@
|
|||
// text-google.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
type TextSearchResult struct {
|
||||
URL string
|
||||
Header string
|
||||
Description string
|
||||
}
|
||||
|
||||
func PerformTextSearch(query, safe, lang string) ([]TextSearchResult, error) {
|
||||
func PerformGoogleTextSearch(query, safe, lang string) ([]TextSearchResult, error) {
|
||||
var results []TextSearchResult
|
||||
|
||||
client := &http.Client{}
|
||||
|
@ -73,41 +65,3 @@ func PerformTextSearch(query, safe, lang string) ([]TextSearchResult, error) {
|
|||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func handleTextSearchGoogle(w http.ResponseWriter, query, safe, lang string) {
|
||||
// Perform the text search
|
||||
results, err := PerformTextSearch(query, safe, lang)
|
||||
if err != nil {
|
||||
log.Printf("Error performing text search: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Assuming you have a separate template for text search results
|
||||
tmpl, err := template.ParseFiles("templates/text.html") // Ensure this path matches your templates' location
|
||||
if err != nil {
|
||||
log.Printf("Error parsing template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data := struct {
|
||||
Results []TextSearchResult // Ensure this type matches the structure expected by your template
|
||||
Query string
|
||||
Fetched string
|
||||
LanguageOptions []LanguageOption
|
||||
CurrentLang string
|
||||
}{
|
||||
Results: results,
|
||||
Query: query,
|
||||
Fetched: fmt.Sprintf("%.2f seconds", time.Since(time.Now()).Seconds()), // Example fetched time, adjust as necessary
|
||||
LanguageOptions: languageOptions, // Assuming this is defined globally or elsewhere
|
||||
CurrentLang: lang,
|
||||
}
|
||||
|
||||
err = tmpl.Execute(w, data)
|
||||
if err != nil {
|
||||
log.Printf("Error executing template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue