sdk

package
v0.0.0-...-683a4be Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Overview

package sdk provides the elasthink SDK which allows you to run all elasthink's core functionality in your service

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateIndexSpec

type CreateIndexSpec struct {
	DocumentType string
	DocumentName string
	DocumentID   int64
}

CreateIndexSpec is the spec of CreateIndex function DocumentType is the type of the document DocumentName is the name of the document DocumentID is the id of the document

type ElasthinkSDK

type ElasthinkSDK struct {
	Redis *redis.Redis
	// contains filtered or unexported fields
}

ElasthinkSDK is the main struct of elasthink SDK, initialized using initalize function

func Initialize

func Initialize(initializeSpec InitializeSpec) ElasthinkSDK

Initialize is the function that return ElasthinkSDK

func (*ElasthinkSDK) CreateIndex

func (es *ElasthinkSDK) CreateIndex(spec CreateIndexSpec) (bool, error)

CreateIndex is a function to create new index based on documentType, documentID, and document name documentType is the type of the document, to categorize documents. For example: campaign documentID, is the ID of document, the key of document. For example: 1 documentName, is the name of documennt, the value which will be indexed. For example: "we want to eat seafood on a restaurant"

func (*ElasthinkSDK) GetKeywordSuggestion

func (es *ElasthinkSDK) GetKeywordSuggestion(spec GetKeywordSuggestionSpec) ([]string, error)

GetKeywordSuggestion is the core function to get keyword suggestion from a given keyword prefix and document type

func (*ElasthinkSDK) Search

func (es *ElasthinkSDK) Search(spec SearchSpec) (SearchResult, error)

Search is the core function of searching a document

func (*ElasthinkSDK) UpdateIndex

func (es *ElasthinkSDK) UpdateIndex(spec UpdateIndexSpec) (bool, error)

UpdateIndex is function to update previously created index

type GetKeywordSuggestionSpec

type GetKeywordSuggestionSpec struct {
	DocumentType string
	Prefix       string
}

GetKeywordSuggestionSpec is the spec of Getting Keyword Suggestion function

type InitializeSpec

type InitializeSpec struct {
	RedisConfig RedisConfig
	SdkConfig   SdkConfig
}

InitializeSpec is the payload to initialize Elasthink SDK

type RankByShowCount

type RankByShowCount []SearchResultRankData

RankByShowCount is the additional struct for document ranking purpose based on its ShowCount

func (RankByShowCount) Len

func (r RankByShowCount) Len() int

Len overrides Len function of RankByShowCount

func (RankByShowCount) Less

func (r RankByShowCount) Less(i, j int) bool

Less overrides Less function of RankByShowCount

func (RankByShowCount) Swap

func (r RankByShowCount) Swap(i, j int)

Swap overrides Swap function of RankByShowCount

type RedisConfig

type RedisConfig struct {
	Address   string
	MaxActive int
	MaxIdle   int
	Timeout   int
}

RedisConfig is the basic configuration to initialize a redis connection Address is the address of the redis will be used, for localhost with port 6379 (default redis port), just use "localhost:6379" MaxActive is the maximum of access to the redis, example value is 30 MaxIdle is the maximum idle access to the redis, example value is 10 Timeout is the timeout of accessing redis (in second), example value is 10

type SdkConfig

type SdkConfig struct {
	IsUsingStopWordsRemoval bool
	StopWordRemovalData     []string
	AvailableDocumentType   []string
}

SdkConfig is the configuration to initialize Elasthink SDK IsUsingStopWordsRemoval enables Elasthink to remove stop words StopWordRemovalData define the stop words AvailableDocumentType the document type available, for example "campaign"

type SearchResult

type SearchResult struct {
	RankedResultList RankByShowCount
}

SearchResult is the result of Search, it have array of search result datum

type SearchResultRankData

type SearchResultRankData struct {
	ID        int64
	ShowCount int
	Rank      int
}

SearchResultRankData is the search result datum

type SearchSpec

type SearchSpec struct {
	DocumentType string
	SearchTerm   string
}

SearchSpec is the spec of Search function

type UpdateIndexSpec

type UpdateIndexSpec struct {
	DocumentType    string
	OldDocumentName string
	NewDocumentName string
	DocumentID      int64
}

UpdateIndexSpec is the spec of UpdateIndex function OldDocumentName is the name of the old document which will be replaced by new document NewDocumentName is the name of the new document DocumentID is the id of the document

Jump to

Keyboard shortcuts

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