added text indexing

This commit is contained in:
ston1th 2022-09-21 20:04:33 +02:00
commit 569812c855
2 changed files with 49 additions and 32 deletions

View file

@ -108,11 +108,23 @@ func (s *Scanner) Scan(file string) (filename, text string, err error) {
file = fs.Clean(file)
scanfile := filepath.Join(s.base, file)
var pdffile string
pdf := isPDF(scanfile)
if !pdf {
if !isImage(scanfile) {
err = errors.New("error: input file is not an image")
return
ft := s.newFileType(scanfile)
if !ft.pdf {
if !ft.image {
if ft.text {
log.V(2).Info("indexing plaintext file", "file", scanfile)
var buf []byte
buf, err = os.ReadFile(scanfile)
if err != nil {
return
}
filename = file
text = string(nlr.ReplaceAll(wsr.ReplaceAll(buf, ws), nl))
return
} else {
err = errors.New("error: input: no image, pdf or text file")
return
}
}
var (
pdf []byte
@ -154,7 +166,7 @@ func (s *Scanner) Scan(file string) (filename, text string, err error) {
return
}
text = string(nlr.ReplaceAll(wsr.ReplaceAll(txt, ws), nl))
if !pdf {
if !ft.pdf {
err = os.Remove(scanfile)
}
return