index

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: BSD-2-Clause Imports: 14 Imported by: 0

README

Notification Index

This package provides Bleve-based search indexing for notifications in the trading system.

Features

  • Full-text search on notification messages
  • Filtered search by notification type, target, broker, account, stage
  • Date range queries for time-based searches
  • Efficient indexing with Bleve search engine

Components

Index Mapping
  • NewIndexMapping() - Creates the Bleve index mapping configuration
  • NewNotificationDocumentMapping() - Defines field mappings for notification documents
Notification Entry
  • NotificationEntry - Represents a notification document in the index
  • Contains all searchable fields: type, message, target, broker, account, stage, timestamps
Indexing
  • NotificationIndexer - Adds/removes notifications from the index
  • NewNotificationIndexer(index) - Creates a new indexer instance
Searching
  • NotificationIndexSearcher - Searches the index with various filters
  • NewNotificationIndexSearcher(bleveIndex) - Creates a new searcher instance
Finding
  • NotificationFinder - High-level interface that combines searching with data retrieval
  • NewNotificationFinder(getter, searcher) - Creates a finder that returns full notification objects

Usage Example

// Create index
mapping := index.NewIndexMapping()
bleveIndex, err := bleve.New("notifications.bleve", mapping)
if err != nil {
    return err
}

// Create components
indexer := index.NewNotificationIndexer(libindex.NewIndex(bleveIndex))
searcher := index.NewNotificationIndexSearcher(bleveIndex)
finder := index.NewNotificationFinder(notificationGetter, searcher)

// Add notification to index
err = indexer.Add(ctx, notification)

// Search notifications
notifications, err := finder.Find(ctx, tx, 
    nil, // from date
    nil, // until date
    core.NotificationTypes{core.NotificationType("signal")}, // types
    nil, // targets
    nil, // brokers
    nil, // accounts
    nil, // stages
    "EURUSD", // query string
    10, // limit
)

Search Capabilities

  • Date Range: Filter by creation date
  • Type Filter: Filter by notification type (signal, test, etc.)
  • Target Filter: Filter by notification target (Discord channel, etc.)
  • Broker Filter: Filter by broker identifier
  • Account Filter: Filter by account identifier
  • Stage Filter: Filter by trading stage (demo, live, etc.)
  • Text Search: Full-text search in notification messages
  • Sorting: Results sorted by creation date (newest first)

Testing

Run tests with:

go test ./pkg/index/...

Tests include:

  • Basic indexing and searching
  • Type-based filtering
  • Message content search
  • Date range queries
  • Index removal

Documentation

Index

Constants

View Source
const NotificationType = "notification"

Variables

This section is empty.

Functions

func NewIndexMapping

func NewIndexMapping() mapping.IndexMapping

func NewNotificationDocumentMapping

func NewNotificationDocumentMapping() *mapping.DocumentMapping

Types

type NotificationEntry

type NotificationEntry struct {
	Created           time.Time
	Modified          time.Time
	NotificationType  core.NotificationType
	Message           core.NotificationMessage
	Target            *core.NotificationTarget
	BrokerIdentifier  string
	AccountIdentifier string
	Stage             string
}

func (NotificationEntry) Type

func (a NotificationEntry) Type() string

type NotificationFinder

type NotificationFinder interface {
	Find(
		ctx context.Context,
		tx libkv.Tx,
		from *libtime.DateTime,
		until *libtime.DateTime,
		types core.NotificationTypes,
		targets []core.NotificationTarget,
		brokerIdentifiers []string,
		accountIdentifiers []string,
		stages []string,
		query string,
		limit int,
	) ([]core.Notification, error)
}

func NewNotificationFinder

func NewNotificationFinder(
	notificationGetterTx core.NotificationGetterTx,
	notificationIndex NotificationIndexSearcher,
) NotificationFinder

type NotificationIndexSearcher

type NotificationIndexSearcher interface {
	Search(
		ctx context.Context,
		from *libtime.DateTime,
		until *libtime.DateTime,
		types core.NotificationTypes,
		targets []core.NotificationTarget,
		brokerIdentifiers []string,
		accountIdentifiers []string,
		stages []string,
		query string,
		limit int,
	) (base.Identifiers, error)
}

func NewNotificationIndexSearcher

func NewNotificationIndexSearcher(
	index bleve.Index,
) NotificationIndexSearcher

type NotificationIndexer

type NotificationIndexer interface {
	Add(ctx context.Context, notification core.Notification) error
	Remove(ctx context.Context, notificationIdentifier base.Identifier) error
}

func NewNotificationIndexer

func NewNotificationIndexer(index index.Index) NotificationIndexer

Jump to

Keyboard shortcuts

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