写入搜索
This commit is contained in:
parent
e442d2ae8f
commit
60d8e4de23
17
main.go
17
main.go
|
|
@ -4,10 +4,8 @@ import (
|
|||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"myschools.me/suguo/gofound/global"
|
||||
"myschools.me/suguo/search/exceptionless"
|
||||
"myschools.me/suguo/search/model"
|
||||
"myschools.me/suguo/search/mysql"
|
||||
|
|
@ -36,21 +34,6 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
//搜索初始化
|
||||
service.GoFoundInit(&global.Config{
|
||||
Addr: "192.168.0.254:5678",
|
||||
Data: os.Getenv("gofound_data"),
|
||||
Debug: false,
|
||||
Dictionary: os.Getenv("gofound_dictionary"),
|
||||
EnableAdmin: true,
|
||||
Gomaxprocs: runtime.NumCPU() * 2,
|
||||
Shard: 0,
|
||||
Auth: "",
|
||||
EnableGzip: true,
|
||||
Timeout: 10 * 60,
|
||||
BufferNum: 0,
|
||||
})
|
||||
|
||||
go service.Probe()
|
||||
|
||||
// 服务停止相应
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import "time"
|
|||
|
||||
type Site struct {
|
||||
URL string `gorm:"type:varchar(255);primarykey"`
|
||||
Title string `gorm:"type:varchar(30);not null;"`
|
||||
Title string `gorm:"type:varchar(127);not null;"`
|
||||
Description string `gorm:"type:varchar(255);not null;"`
|
||||
LinkCount uint `gorm:"index"`
|
||||
UpdatedAt time.Time `gorm:"index"`
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"myschools.me/suguo/gofound/global"
|
||||
found "myschools.me/suguo/gofound/sdk"
|
||||
)
|
||||
|
||||
var gofound found.Client
|
||||
|
||||
func GoFoundInit(conf *global.Config) {
|
||||
gofound = *found.NewClient(conf)
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"myschools.me/suguo/search/exceptionless"
|
||||
)
|
||||
|
||||
func indexAdd(id *uint32, uri, title, description *string) {
|
||||
idx := &struct {
|
||||
ID uint32
|
||||
Text string
|
||||
Document map[string]interface{}
|
||||
}{
|
||||
ID: *id,
|
||||
Text: fmt.Sprintf("%s %s %s", *uri, *title, *description),
|
||||
Document: map[string]interface{}{
|
||||
"url": *uri,
|
||||
"title": *title,
|
||||
"description": *description,
|
||||
},
|
||||
}
|
||||
body, _ := json.Marshal(idx)
|
||||
dr := bytes.NewReader(body)
|
||||
if _, err := http.Post("http://admin:123456@192.168.0.254:5678/api/index?database=default", "", dr); err != nil {
|
||||
exceptionless.SubmitAppError("indexAdd", "http.Post", nil, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/PuerkitoBio/goquery"
|
||||
"golang.org/x/net/html"
|
||||
"gorm.io/gorm/clause"
|
||||
found "myschools.me/suguo/gofound/searcher/model"
|
||||
"myschools.me/suguo/search/exceptionless"
|
||||
"myschools.me/suguo/search/model"
|
||||
"myschools.me/suguo/search/mysql"
|
||||
|
|
@ -22,7 +21,8 @@ import (
|
|||
|
||||
func siteAccess(uri *string) error {
|
||||
client := http.Client{Timeout: 3 * time.Second}
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://www.%s", *uri), nil)
|
||||
requestUri := fmt.Sprintf("https://www.%s", *uri)
|
||||
req, err := http.NewRequest("GET", requestUri, nil)
|
||||
if err != nil {
|
||||
exceptionless.SubmitAppError("siteAccess", "http.NewRequest", nil, err)
|
||||
return err
|
||||
|
|
@ -52,22 +52,12 @@ func siteAccess(uri *string) error {
|
|||
})
|
||||
if title != "" {
|
||||
id := uint32(crc32.ChecksumIEEE([]byte(*uri)))
|
||||
go gofound.AddIndex("default", &found.IndexDoc{
|
||||
Id: id,
|
||||
Text: func() string {
|
||||
return fmt.Sprintf("%s %s %s", *uri, title, description)
|
||||
}(),
|
||||
Document: map[string]interface{}{
|
||||
"url": fmt.Sprintf("https://www.%s", *uri),
|
||||
"description": description,
|
||||
"title": title,
|
||||
},
|
||||
})
|
||||
go indexAdd(&id, &requestUri, &title, &description)
|
||||
}
|
||||
|
||||
urls := urlAnalysis(resp.Body)
|
||||
site := &model.Site{
|
||||
URL: *uri,
|
||||
URL: requestUri,
|
||||
Title: title,
|
||||
Description: description,
|
||||
LinkCount: uint(len(urls)),
|
||||
|
|
|
|||
Loading…
Reference in New Issue