feat(search): PDF content via own ES index and oo index (#42)
Release Please / Release Please (push) Skipped
Release / GoReleaser (push) Skipped
Tests / Secret scan (gitleaks) (push) Skipped
Tests / Test (Go 1.25) (push) Skipped
Tests / Test (Go stable) (push) Skipped
Tests / Secret scan (gitleaks) (pull_request) Successful in 4s
Tests / Test (Go stable) (pull_request) Successful in 18s
Tests / Test (Go 1.25) (pull_request) Successful in 18s

This commit is contained in:
2026-09-16 17:20:54 +00:00
parent 72c7cd5173
commit 7c3a0b8b6e
12 changed files with 1412 additions and 8 deletions
+21 -2
View File
@@ -1,6 +1,9 @@
package main
import (
"fmt"
"strings"
onlyoffice "github.com/eslider/go-onlyoffice"
"github.com/spf13/cobra"
)
@@ -17,6 +20,7 @@ func searchCmd() *cobra.Command {
content bool
folder string
limit int
backend string
asJSON bool
)
cmd := &cobra.Command{
@@ -26,6 +30,9 @@ func searchCmd() *cobra.Command {
"By default only file names are matched. With --content the query also\n" +
"matches extracted document text (document.attachment.content); this covers\n" +
"Office formats (docx/xlsx/pptx) and is slower.\n\n" +
"--backend own queries the separate index populated by `oo index`\n" +
"(ONLYOFFICE_ES_TEXT_INDEX, default oo_docs_text) instead, which also holds\n" +
"PDFs and scans (see docs/elasticsearch.md).\n\n" +
"Requires ONLYOFFICE_ES_URL (and optionally ONLYOFFICE_ES_INDEX,\n" +
"ONLYOFFICE_TENANT). See docs/elasticsearch.md for the tunnel setup.",
Args: cobra.ExactArgs(1),
@@ -33,11 +40,22 @@ func searchCmd() *cobra.Command {
if asJSON {
outputFormat = "json"
}
es, err := onlyoffice.NewESSearcher(onlyoffice.ESConfigFromEnv())
var (
searcher onlyoffice.Searcher
err error
)
switch strings.ToLower(strings.TrimSpace(backend)) {
case "", "oo", "elasticsearch":
searcher, err = onlyoffice.NewESSearcher(onlyoffice.ESConfigFromEnv())
case "own", "es-text":
searcher, err = onlyoffice.NewESTextIndex(onlyoffice.ESTextConfigFromEnv())
default:
return fmt.Errorf("unknown search backend %q (want oo|own)", backend)
}
if err != nil {
return err
}
hits, err := es.Search(cmd.Context(), onlyoffice.SearchQuery{
hits, err := searcher.Search(cmd.Context(), onlyoffice.SearchQuery{
Text: args[0],
InContent: content,
FolderID: folder,
@@ -67,6 +85,7 @@ func searchCmd() *cobra.Command {
cmd.Flags().BoolVar(&content, "content", false, "also match extracted document content")
cmd.Flags().StringVar(&folder, "folder", "", "limit to a Documents folder id")
cmd.Flags().IntVar(&limit, "limit", 20, "maximum number of results")
cmd.Flags().StringVar(&backend, "backend", "oo", "index to query: oo (OnlyOffice) | own (oo index)")
cmd.Flags().BoolVar(&asJSON, "json", false, "shorthand for --output json")
return cmd
}