Add additional fields to search request
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/blevesearch/bleve/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Indexer interface {
|
||||
Index(entry *Entry) error
|
||||
Search(q string) (*bleve.SearchResult, error)
|
||||
}
|
||||
|
||||
type indexer struct {
|
||||
@@ -40,3 +42,17 @@ func NewIndexer(conf *Config) (Indexer, error) {
|
||||
func (i *indexer) Index(entry *Entry) error {
|
||||
return i.idx.Index(entry.Hash(), entry)
|
||||
}
|
||||
|
||||
func (i *indexer) Search(q string) (*bleve.SearchResult, error) {
|
||||
query := bleve.NewMatchQuery(q)
|
||||
searchRequest := bleve.NewSearchRequest(query)
|
||||
searchRequest.Fields = []string{"URL", "Title", "Author", "Summary", "Length"}
|
||||
searchResults, err := i.idx.Search(searchRequest)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("error searching index")
|
||||
return nil, fmt.Errorf("error searching index: %w", err)
|
||||
}
|
||||
log.Debug(searchResults)
|
||||
|
||||
return searchResults, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user