引入标签搜索

This commit is contained in:
2023-11-20 03:26:46 +08:00
parent 9cd4f917cc
commit fdb3edfb61
5 changed files with 120 additions and 13 deletions

View File

@@ -191,21 +191,11 @@ func main() {
return
}
// test ocr
//client := gosseract.NewClient()
//defer client.Close()
//client.SetLanguage("chi_sim")
//client.SetImage("/home/stori/webp/data/tt.jpeg")
//text, _ := client.Text()
//fmt.Println(text)
//fmt.Println("=======================================")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
w.Write([]byte("Hello World!"))
})
// 屏蔽 /favicon.ico
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
http.Error(w, "Not Found", http.StatusNotFound)
@@ -288,6 +278,27 @@ func main() {
return list
}
// 如果是查询 text, 直接从 Elasticsearch 返回结果
if text := QueryConditions("text"); len(text) > 0 {
rest := models.ElasticsearchSearch(strings.Join(text, " "))
// 获取图片列表
// 是否有下一页
//images.Next = images.Total > images.Page*images.PageSize
// 将对象转换为有缩进的JSON输出
data, err := json.MarshalIndent(rest, "", " ")
if err != nil {
log.Println("转换图片列表失败", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.Write(data)
return
}
// 拼接查询条件
var addCondition = func(conditions *strings.Builder, key, column string) {
if values := QueryConditions(key); len(values) > 0 {