Engines

Engines contain the core functionality of EasySearch. They can be re-used for multiple indexes, as long as it doesn’t hold configuration specific to an index. The default set of engines all use mongo, either on the client or server side. Engines that search on the server do not conflict with existing publications, as EasySearch creates fake collections to synchronize data. Every engine allows you to pass in an optional configuration object to change it’s behaviour.

import { Index, MongoDBEngine } from 'meteor/easy:search'

// Client and Server
const index = new Index({
  ...
  engine: new MongoDBEngine({
    sort: () => { score: 1 },
  }),
});

List of engines

The following engines are available to use with EasySearch. Having a look at the core code might also give you an idea of how engines work and what configurable values there are.

MongoDB

The MongoDB engine searches the specified collection directly with MongoDB on the server and uses subscriptions to retrieve reactive data. It uses a simple regex that matches the string that’s searched for inside the specified fields.

Configuration

You might notice that there is a searchObject parameter for selector and a searchString for selectorPerField. That’s because MongoDB allows you to search only in specified fields. That means if you use search with a string it gets converted into an object where the keys are all the configured fields on your index and the value is the search string used.

import { Index } from 'meteor/easy:search'

const index = new Index({
  ...
  fields: ['name', 'fullName', 'address'],
});

index.search('Peter')
// transforms into: { name: 'Peter', fullName: 'Peter', address: 'Peter' }

index.search({ name: 'Peter', address: 'Awesomestreet' })
// stays the same: { name: 'Peter', address: 'Awesomestreet' }

Minimongo

This engine inherits the exact same configuration as MongoDB but does the search only on the client and thus is only useable on the client. You can still create the index on both environments though. It makes sense to use it when you’re transitioning your app or you want to manage the searchable documents through your own publications.

Configuration

MongoTextIndex

The MongoTextIndex engine inherits the same configuration as MongoDB but uses a more modern feature of MongoDB which are text indexes. This offers a more mature approach to searching. It does only support searching with strings, not by specific fields (with search objects). That is because the $text operator searches on all text-indexed fields for the collection.

Configuration

ElasticSearch

ElasticSearch is a mature search engine that’s capable of advanced searching techniques. It is not part of the core but you can add easysearch:elasticsearch to your app and read the documentation to get started.