node search for text added
This commit is contained in:
parent
506107286d
commit
1cb2b042ac
3 changed files with 128 additions and 51 deletions
|
@ -13,10 +13,11 @@ var (
|
|||
|
||||
func handleSearchTextMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
|
@ -24,6 +25,8 @@ func handleSearchTextMessage(msg Message) {
|
|||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-text request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchTextResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
|
@ -33,13 +36,21 @@ func handleSearchTextMessage(msg Message) {
|
|||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "search-results",
|
||||
Type: "text-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
err = sendMessage(msg.ID, responseMsg)
|
||||
// Log the address to be used for sending the response
|
||||
log.Printf("Sending text search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending search results to %s: %v", msg.ID, err)
|
||||
log.Printf("Error sending text search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue