https://github.com/apiko-dev/meteor-anti-search-source
Flexible search in collections based on publish/subscribe
https://github.com/apiko-dev/meteor-anti-search-source
Last synced: 10 months ago
JSON representation
Flexible search in collections based on publish/subscribe
- Host: GitHub
- URL: https://github.com/apiko-dev/meteor-anti-search-source
- Owner: apiko-dev
- License: mit
- Created: 2015-12-15T09:32:38.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-13T08:35:30.000Z (over 8 years ago)
- Last Synced: 2025-03-27T08:45:08.172Z (over 1 year ago)
- Language: JavaScript
- Size: 46.9 KB
- Stars: 5
- Watchers: 11
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## jss:anti-search-source
Flexible search in collections based on publish/subscribe
### Features
* Search by multiple fields
* Searched fields transform
* Search in local or global mode
* High security level in global mode
* Search in relatives collections
### Search configuration
* `collection` - instance of collection to search in;
* `searchMode` - where search: `"global"` (server) or `"local"` (client);
* `fields` - fields to search by. Also, support search in related collections;
* `mongoQuery` - additional Mongo query;
* `limit` - count of documents in result.
### Client methods
* `search('stringToSearch')` - changes search string;
* `searchResult([options])` - return search result as Mongo.Cursor (Array for 'global' search). `options` work similarly to Meteor collection `find()`'s. Reactive data source;
* `setMongoQuery(newMongoQuery)` - replaces Mongo query from configuration
* `setLimit(newLimit)` - change limit;
* `incrementLimit([increment=10])` - increase limit on `value`;
* `isDataReady` - reactive state which shows if data is returned.
### Usage example
```js
Persons = new Mongo.Collection('persons');
if (Meteor.isClient) {
Template.hello.onCreated(function () {
this.searchSource = this.AntiSearchSource({
collection: Persons,
searchMode: 'global',
fields: ['name', 'email', {
collection: 'groups',
referenceField: 'groupId',
fields: ['groupDescription']
}, {
collection: 'home',
referenceField: 'homeId',
fields: ['homeDescription','otherField']
}],
mongoQuery: {
age: {$gte: 30}
},
limit: 10
});
});
Template.hello.helpers({
searchResult: function () {
return Template.instance().searchSource.searchResult();
}
});
Template.hello.events({
'keyup input': _.throttle(function (event, tmpl) {
tmpl.searchSource.search($('input').val())
}, 1500)
});
}
if (Meteor.isServer) {
AntiSearchSource.allow('persons', {
maxLimit: 20,
securityCheck (userId, configs) {
return !!userId;
},
allowedFields: ['name', 'email']
});
}
```
### Todos
- [ ] Remove Blaze dependency
### Changelog
* 1.4.3 - Fix server side sort issue.
* 1.3.0 - Translated to ES6, fully refactored, added search by related documents.
Made by [](http://jssolutionsdev.com) - [Professional Meteor Development Company](http://jssolutionsdev.com)