Documentation
¶
Overview ¶
Package index contains the implementation of the indexation and the search engine. This is for sure not the best performant search engine produced until that day. So, if someone would like to rewrite it by using a better algorithme or a third party libraries, here is few key concepts you will need to respect:
1. You will need to take care about the permissions. It won't be wise to first through everything and then filter by the permission. You should do the opposite. First filter the amount of data based of the permission and then search through the rest.
2. The indexation is done by the API server. It means that the indexation is done in memory and not persisted in the database. If your third party library is using a database, makes sure it worth it.
3. The goal of this search engine is also to provide more information to display in the UI. The most wanted thing is the display name of the resource instead of the plain name contained in the metadata. Makes sure you are keeping that in mind when you are implementing your own search engine.
4. Makes sure to have something a bit generic so you can search through Dashboards, Projects, Datasources.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// List is listing all the documents in the index for the given kind and project.
// The project parameter can be empty, in that case, the list will be done through all the projects.
List(ctx echo.Context, kind v1.Kind, project string) ([]*SearchResult, error)
// Search is searching through the index for the given kind and project.
// The project parameter can be empty, in that case, the search will be done through all the projects.
Search(ctx echo.Context, kind v1.Kind, project string, txt string) ([]*SearchResult, error)
// Refresh is refreshing the index by reloading all the documents from the database.
Refresh() error
// Add is adding a document to the index. If it already exists, it will be updated. If it doesn't exist, it will be created.
Add(entity api.Entity) error
// Delete is deleting a document from the index.
Delete(kind v1.Kind, metadata api.Metadata)
}
func New ¶
func New(conf config.Search, authz authorization.Authorization, dao model.DAO) Client
type MatchingInterval ¶
type MatchingInterval struct {
From uint64 `json:"from"`
// To is always superior to From
To uint64 `json:"to"`
}
MatchingInterval represents the start and the end position of the continuous characters that is matching the pattern. For example, for the pattern `bc`, with the string `abcd`, the corresponding interval will be [{from: 1, to: 2}] Another example, for the pattern `fuz`, with the string `fzduzf`, the corresponding intervals will be: [ { from: 0, to: 0 }, { from: 3, to: 4 } ]
func (MatchingInterval) Size ¶
func (m MatchingInterval) Size() uint64
type SearchResult ¶
type SearchResult struct {
// Metadata is the metadata of the resource that matches the query.
Metadata api.Metadata `json:"metadata" yaml:"metadata"`
// DisplayName is the string that will be used for the search display.
DisplayName string `json:"displayName" yaml:"displayName"`
// The original string that matches the query.
// It can be empty if the query is empty.
Original string `json:"original,omitempty"`
// The list of intervals that match the query.
// It can be empty if the query is empty.
Intervals []MatchingInterval `json:"intervals,omitempty"`
// Score is the score of the match, the higher the score, the better the match.
// When there is a perfect match, then the number is infinite.
// It can be equal to 0 if the query is empty.
Score uint64 `json:"score,omitempty"`
}
SearchResult is the result of a search query. It contains the metadata of the resource that matches the query, the original string that matches the query, and the list of intervals that gives you the position of the characters that match the query in the original string. Note for developers: this struct is not in the pkg/model/api/v1/search package to avoid generating them with cuelang and facing issues with cuelang when generating the package pkg/model/api.