ftsindex

package
v0.0.0-...-4f40287 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuchIndex = errors.New("No such index")

ErrNoSuchIndex is used when trying to find an index name by lang and no matching index is found for this lang

View Source
var PupilFieldScores = FieldScores{
	"first_name": 10.0,
	"last_name":  9.0,
}

PupilFieldScores are the scores for each field of the Pupil Schema used for a full text search query from the search bar

View Source
var SkillFieldScores = FieldScores{
	"name":        10.0,
	"description": 9.0,
}

SkillFieldScores are the scores for each field of the Skill Schema used for a full text search query from the search bar

Functions

func PrepareQueryWildcard

func PrepareQueryWildcard(q string, s FieldScores) (resList []elastic.Query)

PrepareQueryWildCard is used to prepare an elastic query using wildcards from a web query. It uses field scores to boost each field according to its score

Types

type FieldScores

type FieldScores map[string]float64

FieldScores is a type alias used to pass a map of floats representing the score of each field

type FtsPupil

type FtsPupil struct {
	ID        int64
	Lang      string
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

FtsPupil is a pupil struct for fulltext indexing

type FtsSkill

type FtsSkill struct {
	ID          int64
	Lang        string
	Name        string `json:"name"`
	Description string `json:"description"`
}

FtsSkill is a skill struct for fulltext indexing

type PupilSearchResult

type PupilSearchResult struct {
	Pupils []model.Pupil
	Scores SearchScores
}

PupilSearchResult wraps a list to implement the sort interface on it bases on the search score

func (PupilSearchResult) Len

func (s PupilSearchResult) Len() int

Len implements the sort interface

func (PupilSearchResult) Less

func (s PupilSearchResult) Less(j, i int) bool

Less implements the sort interface

func (PupilSearchResult) Swap

func (s PupilSearchResult) Swap(i, j int)

Swap implements the sort interface

type SearchScores

type SearchScores map[int64]float64

searchScores is a type alias for search scores mapping item ID to scores

type SearchService

type SearchService struct {
	Client *elastic.Client

	Enabled bool
	// contains filtered or unexported fields
}

SearchService is a thin wrapper around olivere/elastic.v5 client

func NewSearchService

func NewSearchService(m *model.Model, db *yago.DB, traceQueries bool, logger hermes.Logger) *SearchService

NewSearchService returns an Indexer with no client configured you must call setup on it to setup the client conn until then the Enabled field is set to false

func (*SearchService) CreateIndices

func (i *SearchService) CreateIndices(languages static.LanguageList) (err error)

CreateIndices creates all indices in elastic

func (*SearchService) DropIndices

func (i *SearchService) DropIndices(languages static.LanguageList) (err error)

DropIndices will try to drop the indexes related to the given. Other indexes will be not be affected. The function will return an error if the operation was not successful. The function will ignore indexes that don't exist.

func (*SearchService) GetIndexMappingName

func (i *SearchService) GetIndexMappingName(lang string) (string, error)

GetIndexMappingName returns the index mapping name according to the desired language

func (*SearchService) GetIndexName

func (i *SearchService) GetIndexName(lang string) (string, error)

GetIndexName returns the index name according to the desired language

func (*SearchService) GetPupilScoresAndIDs

func (i *SearchService) GetPupilScoresAndIDs(res *elastic.SearchResult) (scores SearchScores, IDs []interface{})

GetPupilScoresAndIDs produces a map of all obtained IDs with corresponding scores it also return the ID list for convenience

func (*SearchService) GetSkillScoresAndIDs

func (i *SearchService) GetSkillScoresAndIDs(res *elastic.SearchResult) (scores SearchScores, IDs []interface{})

GetSkillScoresAndIDs produces a map of all obtained IDs with corresponding scores it also return the ID list for convenience

func (*SearchService) IndexPupilsInFts

func (i *SearchService) IndexPupilsInFts() error

IndexPupilsInFts tells the indexer to index all pupils that are marked as dirty

func (*SearchService) IndexSkillsInFts

func (i *SearchService) IndexSkillsInFts() error

IndexSkillsInFts tells the indexer to index all skills that are marked as dirty

func (*SearchService) Printf

func (i *SearchService) Printf(format string, v ...interface{})

Printf implements the elastic.Logger interface, is used to trace queries

func (*SearchService) RemovePupil

func (i *SearchService) RemovePupil(ID int) error

RemovePupil is used to remove the pupil denoted by its ID from the index

func (*SearchService) RemoveSkill

func (i *SearchService) RemoveSkill(ID int) error

RemoveSkill is used to remove the skill denoted by its ID from the index

func (*SearchService) SetAllPupilsDirty

func (i *SearchService) SetAllPupilsDirty() (err error)

SetAllPupilsDirty is used to set all pupils as dirty in the database in preparation of reindexing the whole database

func (*SearchService) SetAllSkillsDirty

func (i *SearchService) SetAllSkillsDirty() (err error)

SetAllSkillsDirty is used to set all skills as dirty in the database in preparation of reindexing the whole database

func (*SearchService) Setup

func (i *SearchService) Setup(url string, sniff bool) (err error)

Setup is used to verify initial connection and index presence. url: is a full url in the form of scheme://host:port ex:"http://localhost:9200" for elasticsearch server listening on 9200. if everything goes well the service.Enabled flag will be set to true automatically if something fails you'll receive an error in return of this call

func (*SearchService) URL

func (i *SearchService) URL() string

URL returns the URL currently setup in the index this will be equal to "" if you did not call Setup() yet...

type SkillSearchResult

type SkillSearchResult struct {
	Skills []model.Skill
	Scores SearchScores
}

SkillSearchResult wraps a list to implement the sort interface on it bases on the search score

func (SkillSearchResult) Len

func (s SkillSearchResult) Len() int

Len implements the sort interface

func (SkillSearchResult) Less

func (s SkillSearchResult) Less(j, i int) bool

Less implements the sort interface

func (SkillSearchResult) Swap

func (s SkillSearchResult) Swap(i, j int)

Swap implements the sort interface

Jump to

Keyboard shortcuts

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