|
|
|
@ -199,6 +199,8 @@ func (s *searchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
q := bleve.NewQueryStringQuery(r.URL.Query().Get("q"))
|
|
|
|
|
sr := bleve.NewSearchRequest(q)
|
|
|
|
|
sr.IncludeLocations = false
|
|
|
|
|
sr.Size = 25
|
|
|
|
|
sr.Fields = []string{"page", "title", "text"}
|
|
|
|
|
sr.Highlight = bleve.NewHighlightWithStyle("html")
|
|
|
|
|
sr.Highlight.AddField("text")
|
|
|
|
@ -219,6 +221,7 @@ type pageBlock struct {
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Page string `json:"page"`
|
|
|
|
|
Text string `json:"text"`
|
|
|
|
|
Link string `json:"link"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p pageBlock) Type() string {
|
|
|
|
@ -239,12 +242,30 @@ func createSearchObjects(rootBlockID string) ([]pageBlock, error) {
|
|
|
|
|
current := queue[0]
|
|
|
|
|
queue = queue[1:]
|
|
|
|
|
|
|
|
|
|
pageBlocks = append(pageBlocks, pageBlock{
|
|
|
|
|
ID: current,
|
|
|
|
|
Title: blocks.Texts[blocks.PageID],
|
|
|
|
|
Page: blocks.PageID,
|
|
|
|
|
Text: blocks.Texts[current],
|
|
|
|
|
})
|
|
|
|
|
links, err := ParseLinks(current, blocks.Texts[current])
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(links) == 0 {
|
|
|
|
|
pageBlocks = append(pageBlocks, pageBlock{
|
|
|
|
|
ID: current,
|
|
|
|
|
Title: blocks.Texts[blocks.PageID],
|
|
|
|
|
Page: blocks.PageID,
|
|
|
|
|
Text: blocks.Texts[current],
|
|
|
|
|
Link: "",
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
for _, link := range links {
|
|
|
|
|
pageBlocks = append(pageBlocks, pageBlock{
|
|
|
|
|
ID: current,
|
|
|
|
|
Title: blocks.Texts[blocks.PageID],
|
|
|
|
|
Page: blocks.PageID,
|
|
|
|
|
Text: blocks.Texts[current],
|
|
|
|
|
Link: link.Name,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue = append(queue, blocks.Children[current]...)
|
|
|
|
|
}
|
|
|
|
|