es

package module
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

Elasticsearch Engine (preview)

The default Answer uses a built-in database such as MySQL as its search engine. However, when dealing with large amounts of data, the speed and accuracy of searches can be affected. Therefore, we provide a plugin that uses Elasticsearch as the search engine, which greatly improves search speed and accuracy.

How to use

Build
./answer build --with github.com/apache/incubator-answer-plugins/search-elasticsearch
Configuration
  • Endpoints - Elasticsearch connection address, such as http://127.0.0.1:9200 or multiple addresses separated by ','
  • Username - Elasticsearch username
  • Password - Elasticsearch password

Note

  • Only support Elasticsearch 7.x
  • Index name is answer_post. It will create automatically if not exists.
  • You also can create index manually if you want to specify search_analyzer or other settings(replicas and shards).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrLogger

func NewErrLogger() elastic.Logger

Types

type AnswerPostDoc

type AnswerPostDoc struct {
	Id          string   `json:"id"`
	ObjectID    string   `json:"object_id"`
	Title       string   `json:"title"`
	Type        string   `json:"type"`
	Content     string   `json:"content"`
	UserID      string   `json:"user_id"`
	QuestionID  string   `json:"question_id"`
	Answers     int64    `json:"answers"`
	Status      int64    `json:"status"`
	Views       int64    `json:"views"`
	Created     int64    `json:"created"`
	Active      int64    `json:"active"`
	Score       int64    `json:"score"`
	HasAccepted bool     `json:"has_accepted"`
	Tags        []string `json:"tags"`
}

func CreateDocFromSearchContent

func CreateDocFromSearchContent(id string, content *plugin.SearchContent) (doc *AnswerPostDoc)

type ErrLogger

type ErrLogger struct {
}

func (ErrLogger) Printf

func (l ErrLogger) Printf(format string, v ...interface{})

type LoggingHttpClient

type LoggingHttpClient struct {
	// contains filtered or unexported fields
}

func (LoggingHttpClient) Do

type Operator

type Operator struct {
	C *elastic.Client
}

Operator elasticsearch client only support basic functions, not support bulk operations

func NewOperator

func NewOperator(urls []string, username, password string) (c *Operator, err error)

func (*Operator) CreateIndex

func (op *Operator) CreateIndex(ctx context.Context, indexName string, mapping string) (err error)

func (*Operator) DeleteDoc

func (op *Operator) DeleteDoc(ctx context.Context, indexName string, id string) (err error)

func (*Operator) QueryDoc

func (op *Operator) QueryDoc(ctx context.Context, indexName string,
	query elastic.Query, sort *elastic.FieldSort, cols *elastic.FetchSourceContext,
	page, size int) (
	result *elastic.SearchResult, err error)

func (*Operator) SaveDoc

func (op *Operator) SaveDoc(ctx context.Context, indexName string, id string, doc interface{}) (err error)

type SearchContent

type SearchContent struct {
	ObjectID    string   `json:"objectID"`
	Title       string   `json:"title"`
	Type        string   `json:"type"`
	Content     string   `json:"content"`
	Answers     int64    `json:"answers"`
	Status      int64    `json:"status"`
	Tags        []string `json:"tags"`
	QuestionID  string   `json:"questionID"`
	UserID      string   `json:"userID"`
	Views       int64    `json:"views"`
	Created     int64    `json:"created"`
	Active      int64    `json:"active"`
	Score       int64    `json:"score"`
	HasAccepted bool     `json:"hasAccepted"`
}

type SearchEngine

type SearchEngine struct {
	Config   *SearchEngineConfig
	Operator *Operator
	// contains filtered or unexported fields
}

func (*SearchEngine) ConfigFields

func (s *SearchEngine) ConfigFields() []plugin.ConfigField

func (*SearchEngine) ConfigReceiver

func (s *SearchEngine) ConfigReceiver(config []byte) error

func (*SearchEngine) DeleteContent

func (s *SearchEngine) DeleteContent(ctx context.Context, contentID string) error

func (*SearchEngine) Description

func (s *SearchEngine) Description() plugin.SearchDesc

func (*SearchEngine) Info

func (s *SearchEngine) Info() plugin.Info

func (*SearchEngine) RegisterSyncer

func (s *SearchEngine) RegisterSyncer(ctx context.Context, syncer plugin.SearchSyncer)

func (*SearchEngine) SearchAnswers

func (s *SearchEngine) SearchAnswers(
	ctx context.Context, cond *plugin.SearchBasicCond) (
	res []plugin.SearchResult, total int64, err error)

func (*SearchEngine) SearchContents

func (s *SearchEngine) SearchContents(
	ctx context.Context, cond *plugin.SearchBasicCond) (
	res []plugin.SearchResult, total int64, err error)

func (*SearchEngine) SearchQuestions

func (s *SearchEngine) SearchQuestions(
	ctx context.Context, cond *plugin.SearchBasicCond) (
	res []plugin.SearchResult, total int64, err error)

func (*SearchEngine) UpdateContent

func (s *SearchEngine) UpdateContent(ctx context.Context, content *plugin.SearchContent) error

type SearchEngineConfig

type SearchEngineConfig struct {
	Endpoints string `json:"endpoints"`
	Username  string `json:"username"`
	Password  string `json:"password"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL