some bug fixes

This commit is contained in:
ston1th 2019-08-29 19:29:53 +02:00
commit 577cf4d482
10 changed files with 83 additions and 17 deletions

View file

@ -28,6 +28,10 @@ GOOS=openbsd make vendor
## Install
**Requirements:**
* tesseract
* pdftotext
See the `scripts/` directory on how to install docstore on Linux or OpenBSD.
## Config
@ -53,6 +57,7 @@ See the `scripts/` directory on how to install docstore on Linux or OpenBSD.
## Features
* Fulltext indexing of documents
* Query Syntax: https://github.com/bcampbell/qs/blob/master/syntax.md
* The `Index All` button tries add every file not already indexed to the index
* Custom regex based tags (see https://golang.org/pkg/regexp/syntax/)
* The `Retag All` button will reapply the current tags to all indexed documents

1
go.mod
View file

@ -6,6 +6,7 @@ require (
git.giftfish.de/ston1th/godrop/v2 v2.1.0
git.giftfish.de/ston1th/jwt/v3 v3.2.0
github.com/RoaringBitmap/roaring v0.4.17 // indirect
github.com/bcampbell/qs v0.0.0-20161004022730-15caa99abd01
github.com/blevesearch/bleve v0.8.0
github.com/blevesearch/blevex v0.0.0-20180227211930-4b158bb555a3 // indirect
github.com/blevesearch/go-porterstemmer v1.0.2 // indirect

2
go.sum
View file

@ -4,6 +4,8 @@ git.giftfish.de/ston1th/jwt/v3 v3.2.0 h1:V6Lh7OjXn4D3HPd/LoDf7w5N7cyiSXEPAQCIfSV
git.giftfish.de/ston1th/jwt/v3 v3.2.0/go.mod h1:jDALrW7OKeIaqYuMxs3GWyPRnQZmk/R+Lu9p/Em3Ziw=
github.com/RoaringBitmap/roaring v0.4.17 h1:oCYFIFEMSQZrLHpywH7919esI1VSrQZ0pJXkZPGIJ78=
github.com/RoaringBitmap/roaring v0.4.17/go.mod h1:D3qVegWTmfCaX4Bl5CrBE9hfrSrrXIr8KVNvRsDi1NI=
github.com/bcampbell/qs v0.0.0-20161004022730-15caa99abd01 h1:ZkEYngtmNszw0BJt4GoWW5rdn5U6MaFlLAUD4S3KEas=
github.com/bcampbell/qs v0.0.0-20161004022730-15caa99abd01/go.mod h1:ZgSGz2VRprXTqsfbn6HAH1ePnGiVCrlA3kflJ6Sjxqg=
github.com/blevesearch/bleve v0.8.0 h1:DCoCrxscCXrlzVWK92k7Vq4d28lTAFuigVmcgIX0VCo=
github.com/blevesearch/bleve v0.8.0/go.mod h1:Y2lmIkzV6mcNfAnAdOd+ZxHkHchhBfU/xroGIp61wfw=
github.com/blevesearch/blevex v0.0.0-20180227211930-4b158bb555a3 h1:U6vnxZrTfItfiUiYx0lf/LgHjRSfaKK5QHSom3lEbnA=

View file

@ -125,6 +125,30 @@ func loadConfig() error {
if err != nil {
return err
}
if config.RunDir == "" {
config.RunDir = defRunDir
}
if config.User == "" {
config.User = defRunUser
}
if config.Group == "" {
config.Group = defRunGroup
}
if config.ListenAddr == "" {
config.ListenAddr = defListen
}
if config.LogFile == "" {
config.LogFile = defLogFile
}
if config.CMDTimeout == 0 {
config.CMDTimeout = defTimeout
}
if config.TesseractThreads == 0 {
config.TesseractThreads = tesseractThreads
}
if config.TesseractOEM == 0 {
config.TesseractOEM = tesseractOEM
}
return file.Close()
}

View file

@ -17,7 +17,7 @@ type User struct {
type Result struct {
ID string
Path string
Tags string
Tags []string
HTML template.HTML
}

View file

@ -5,6 +5,7 @@ package index
import (
"errors"
"git.giftfish.de/ston1th/docstore/pkg/core"
"github.com/bcampbell/qs"
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/document"
"github.com/blevesearch/bleve/mapping"
@ -107,7 +108,11 @@ func (i *Index) Delete(id string) error {
}
func (i *Index) Search(search string) (results core.Results, err error) {
req := bleve.NewSearchRequest(bleve.NewQueryStringQuery(search))
q, err := qs.Parse(search)
if err != nil {
return
}
req := bleve.NewSearchRequest(q)
req.Highlight = bleve.NewHighlightWithStyle("html")
req.Size = maxSearchResult
res, err := i.i.Search(req)
@ -129,7 +134,7 @@ func (i *Index) Search(search string) (results core.Results, err error) {
for _, f := range frags {
t += f
}
r.Tags = strings.ReplaceAll(strings.ReplaceAll(t, "<mark>", ""), "</mark>", "")
r.Tags = append(r.Tags, strings.ReplaceAll(strings.ReplaceAll(t, "<mark>", ""), "</mark>", ""))
}
if fragField == textField || fragField == createdField {
for _, f := range frags {

View file

@ -297,6 +297,13 @@ const (
<h2>{{.BodyTitle}}</h2>
</div>
</div>
<div class="row mt-3">
<div class="col col-nopad">
<div class="alert alert-primary">
<p>This log will display error information about batch operations such as <code>Retag All</code> or <code>Index All</code>.</p>
</div>
</div>
</div>
<div class="row mt-3">
<textarea class="form-control input-sm md-text mono" rows="30" spellcheck="false" autofocus>{{.Data}}</textarea>
</div>
@ -451,20 +458,22 @@ const (
<thead>
<tr>
<th>File</th>
<th>Tag</th>
<th>Tags</th>
</tr>
</thead>
<tbody>
{{range $item := .Data}}
<tr>
<td>
<a class="mono" href="{{$item.Path}}"><b>{{$item.Path}}</b></a>
{{if $item.HTML}}
<br><pre class="wrap">{{$item.HTML}}</pre>
{{end}}
<a class="mono" href="{{$item.Path}}"><b>{{$item.Path}}</b></a>
{{if $item.HTML}}
<br><pre class="wrap">{{$item.HTML}}</pre>
{{end}}
</td>
<td>
{{if $item.Tags}}<a href="/search?query=tags:{{$item.Tags}}" class="btn badge btn-primary">{{$item.Tags}}</a>{{end}}
{{range $t := $item.Tags}}
<a href="/search?query=tags:{{$t}}" class="btn badge btn-primary">{{$t}}</a>
{{end}}
</td>
</tr>
{{end}}
@ -477,9 +486,14 @@ const (
<div class="col col-nopad">
<div class="alert alert-primary">
<h4>Query Syntax</h4>
<p>Documentation: <a target="_blank" rel="noopener noreferrer" href="https://github.com/bcampbell/qs/blob/master/syntax.md">https://github.com/bcampbell/qs/blob/master/syntax.md</a></p>
<p>Fields</p>
<pre><code>tags:insurance
tags:insurance or tags:invoice
tags:insurance OR tags:invoice
# combine tags
tags:insurance AND tags:invoice
# exclude tags
tags:insurance -tags:invoice
created:&lt;="2016-09-21"</code></pre>
<p>Fulltext</p>
<pre><code>some text here</code></pre>

View file

@ -1,4 +1,5 @@
#!/bin/sh
apt install -y poppler-utils tesseract-ocr tesseract-ocr-deu tesseract-ocr-eng
groupadd docstore
useradd -g docstore docstore
mkdir /var/lib/docstore

View file

@ -4,6 +4,13 @@
<h2>{{.BodyTitle}}</h2>
</div>
</div>
<div class="row mt-3">
<div class="col col-nopad">
<div class="alert alert-primary">
<p>This log will display error information about batch operations such as <code>Retag All</code> or <code>Index All</code>.</p>
</div>
</div>
</div>
<div class="row mt-3">
<textarea class="form-control input-sm md-text mono" rows="30" spellcheck="false" autofocus>{{.Data}}</textarea>
</div>

View file

@ -25,20 +25,22 @@
<thead>
<tr>
<th>File</th>
<th>Tag</th>
<th>Tags</th>
</tr>
</thead>
<tbody>
{{range $item := .Data}}
<tr>
<td>
<a class="mono" href="{{$item.Path}}"><b>{{$item.Path}}</b></a>
{{if $item.HTML}}
<br><pre class="wrap">{{$item.HTML}}</pre>
{{end}}
<a class="mono" href="{{$item.Path}}"><b>{{$item.Path}}</b></a>
{{if $item.HTML}}
<br><pre class="wrap">{{$item.HTML}}</pre>
{{end}}
</td>
<td>
{{if $item.Tags}}<a href="/search?query=tags:{{$item.Tags}}" class="btn badge btn-primary">{{$item.Tags}}</a>{{end}}
{{range $t := $item.Tags}}
<a href="/search?query=tags:{{$t}}" class="btn badge btn-primary">{{$t}}</a>
{{end}}
</td>
</tr>
{{end}}
@ -51,9 +53,14 @@
<div class="col col-nopad">
<div class="alert alert-primary">
<h4>Query Syntax</h4>
<p>Documentation: <a target="_blank" rel="noopener noreferrer" href="https://github.com/bcampbell/qs/blob/master/syntax.md">https://github.com/bcampbell/qs/blob/master/syntax.md</a></p>
<p>Fields</p>
<pre><code>tags:insurance
tags:insurance or tags:invoice
tags:insurance OR tags:invoice
# combine tags
tags:insurance AND tags:invoice
# exclude tags
tags:insurance -tags:invoice
created:&lt;="2016-09-21"</code></pre>
<p>Fulltext</p>
<pre><code>some text here</code></pre>