From db17ac42beda68a3c10de8a62a6dc8f0ca52d91b Mon Sep 17 00:00:00 2001 From: Sven Schmalle Date: Tue, 24 Dec 2019 13:37:28 +0100 Subject: [PATCH] Hervorhebung der gesuchten Begriffe in der Volltextsuche eingebaut --- main.go | 43 ++++++++++++++++++++++++++++++++++++++++--- web/index.html | 9 +++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 2426ac4..aa08176 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "time" "github.com/blevesearch/bleve" + "github.com/blevesearch/bleve/search/highlight/highlighter/html" "github.com/gorilla/mux" "github.com/mandolyte/mdtopdf" "gopkg.in/src-d/go-git.v4" @@ -87,7 +88,14 @@ func main() { if !info.IsDir() && !strings.HasPrefix(tmpPath, ".git") { b, err := ioutil.ReadFile(path.Join(config.DataPath, tmpPath)) check(err) - err = index.Index(tmpPath, string(b)) + + indexData := struct { + Text string + }{ + string(b), + } + + err = index.Index(tmpPath, indexData) check(err) fmt.Println("Indexed: " + info.Name()) } @@ -99,6 +107,29 @@ func main() { } } + /* + repo, err := git.PlainOpen(config.DataPath) + check(err) + + ref, err := repo.Head() + check(err) + + // ... retrieves the commit history + //since := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC) + //until := time.Date(2019, 7, 30, 0, 0, 0, 0, time.UTC) + var filename = "playground.md" + cIter, err := repo.Log(&git.LogOptions{From: ref.Hash(), FileName: &filename}) //, Since: &since, Until: &until}) + check(err) + + // ... just iterates over the commits, printing it + err = cIter.ForEach(func(c *object.Commit) error { + fmt.Println(c.Files()) + fmt.Println(c.Committer.When) + + return nil + }) + */ + router := mux.NewRouter() router.HandleFunc("/_api/md/{pagename:.*}", getRawPage).Methods("GET") router.HandleFunc("/_api/pdf/{pagename:.*}", getPDFPage).Methods("GET") @@ -259,7 +290,7 @@ func getFTS(w http.ResponseWriter, r *http.Request) { query := bleve.NewQueryStringQuery(pSearchterm) search := bleve.NewSearchRequest(query) - search.Highlight = bleve.NewHighlight() + search.Highlight = bleve.NewHighlightWithStyle(html.Name) search.Size = 30 searchResults, err := index.Search(search) index.Close() @@ -389,7 +420,13 @@ func BleveIndex(PageName string) { b, err := ioutil.ReadFile(path.Join(config.DataPath, PageName)) check(err) - err = index.Index(PageName, string(b)) + + indexData := struct { + Text string + }{ + string(b), + } + err = index.Index(PageName, indexData) check(err) index.Close() } diff --git a/web/index.html b/web/index.html index 40058ee..e9962ce 100644 --- a/web/index.html +++ b/web/index.html @@ -94,7 +94,10 @@ list-style-type: square; } - +mark { + background-color: lightblue; + color: black; +} @@ -261,7 +264,9 @@ content.forEach(function (item, index) { console.log(item.id); var page = item.id.replace(/.md/, ''); - $("#outputdiv").append("/"+page+"
"); + $("#outputdiv").append((index+1)+". Seite: /"+page+"
"); + $("#outputdiv").append(item.fragments.Text+"
"); + }); } });