Add link operator to search
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
39dd45b65d
commit
47d504903d
4
main.go
4
main.go
|
@ -954,6 +954,10 @@ func createSearchIndex(dataDir, indexName string) (bleve.Index, error) {
|
|||
titleFieldMapping.Store = true
|
||||
documentMapping.AddFieldMappingsAt("title", titleFieldMapping)
|
||||
|
||||
linkFieldMapping := bleve.NewTextFieldMapping()
|
||||
linkFieldMapping.Store = true
|
||||
documentMapping.AddFieldMappingsAt("link", linkFieldMapping)
|
||||
|
||||
indexMapping.AddDocumentMapping("block", documentMapping)
|
||||
|
||||
searchIndex, err := bleve.New(indexDir, indexMapping)
|
||||
|
|
33
search.go
33
search.go
|
@ -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]...)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user