Hervorhebung der gesuchten Begriffe in der Volltextsuche eingebaut
This commit is contained in:
parent
70ae601fb2
commit
db17ac42be
43
main.go
43
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()
|
||||
}
|
||||
|
@ -94,7 +94,10 @@
|
||||
list-style-type: square;
|
||||
}
|
||||
|
||||
|
||||
mark {
|
||||
background-color: lightblue;
|
||||
color: black;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -261,7 +264,9 @@
|
||||
content.forEach(function (item, index) {
|
||||
console.log(item.id);
|
||||
var page = item.id.replace(/.md/, '');
|
||||
$("#outputdiv").append("<a href='/"+page+"'>/"+page+"</a><br>");
|
||||
$("#outputdiv").append((index+1)+". Seite: <a href='/"+page+"'>/"+page+"</a><br>");
|
||||
$("#outputdiv").append(item.fragments.Text+"<hr>");
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user