|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"github.com/gorilla/mux"
|
|
|
"github.com/huichen/wukong/types"
|
|
|
"net/http"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
@@ -15,13 +16,13 @@ var (
|
|
|
)
|
|
|
|
|
|
type ParamIndex struct {
|
|
|
- DocId string `json:"docId"`
|
|
|
+ DocId string `json:"docId"`
|
|
|
Content string `json:"content"`
|
|
|
ForceUpdate bool `json:"forceUpdate"`
|
|
|
}
|
|
|
|
|
|
type ParamDelete struct {
|
|
|
- DocId string `json:"docId"`
|
|
|
+ DocId string `json:"docId"`
|
|
|
ForceUpdate bool `json:"forceUpdate"`
|
|
|
}
|
|
|
|
|
|
@@ -40,7 +41,8 @@ func startHttp(addr string) error {
|
|
|
v1.HandleFunc("/index", index_v1).Methods("POST")
|
|
|
v1.HandleFunc("/index", delete_index_v1).Methods("DELETE")
|
|
|
v1.HandleFunc("/delete_index", delete_index_v1).Methods("POST")
|
|
|
- v1.HandleFunc("/search", search_v1).Methods("GET").Queries("keywords", "{keywords}")
|
|
|
+ v1.HandleFunc("/search", search_v1).Methods("GET").Queries("keywords", "{keywords}",
|
|
|
+ "offset", "{offset:[0-9]+}", "limit", "{offset:[0-9]+}")
|
|
|
v1.HandleFunc("/shutdown", shutdown).Methods("POST")
|
|
|
router.Use(mux.CORSMethodMiddleware(router))
|
|
|
|
|
|
@@ -109,8 +111,16 @@ func delete_index_v1(w http.ResponseWriter, r *http.Request) {
|
|
|
func search_v1(w http.ResponseWriter, r *http.Request) {
|
|
|
params := mux.Vars(r)
|
|
|
keywords := params["keywords"]
|
|
|
- fmt.Println("searching:", params, keywords)
|
|
|
- resp := searcher.Search(types.SearchRequest{Text: keywords})
|
|
|
+ offset, _ := strconv.ParseInt(params["offset"], 10, 64)
|
|
|
+ limit, _ := strconv.ParseInt(params["limit"], 10, 64)
|
|
|
+ fmt.Println("searching:", params)
|
|
|
+ resp := searcher.Search(types.SearchRequest{
|
|
|
+ Text: keywords,
|
|
|
+ RankOptions: &types.RankOptions{
|
|
|
+ OutputOffset: int(offset),
|
|
|
+ MaxOutputs: int(limit),
|
|
|
+ },
|
|
|
+ })
|
|
|
sresp, err := json.Marshal(resp)
|
|
|
if err != nil {
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|