Comments (42)
I think if we can index multiple collections and use the resultset
to search off of, then there might be minimal changes to make this work
from meteor-easy-search.
But that would mean that you'd get 2 different sets of data back, and you'd have to filter out if the doc is from either of the several collections you specified.
I'd make the collection a possible array field, eg:
EasySearch.createSearchIndex('mixedSearch', {
'collection' : [Cars, Fruits, Roles], // instanceof Meteor.Collection
'fields' : ['name', 'price']
});
Price wouldn't be a field in the Roles collection which means inconsistent data. Did you have that in mind? If not, what would you like? I see that having a facet search over several collections would be nice. B eing able to define the 'es' fields which are being indexed would be another option.
from meteor-easy-search.
Yes I would specify for each collection the fields to search over. I don't think that would be redundant.
In a webapp you want one general search bar that searches all collections. Today's internet user is used to the google search bar that looks across multiple types of docs.
from meteor-easy-search.
sorry for the late reply.
from meteor-easy-search.
@matteodem I like that approach of identifying the collection as an option when making the index. I think it would be nice to filter out inconsistent data at runtime and let the user make that decision.
from meteor-easy-search.
How would you filter out inconsistent data? I'd probably split up the results by collection (index).
from meteor-easy-search.
@matteodem Yea as long as the index is tagged with which collection, then I can get the information returned based on each index. Will this cause problems ?
from meteor-easy-search.
It's not problematic, but it'll most probably need some overhaul of the current logic. I'll start in the next weeks with it.
from meteor-easy-search.
I implemented it with a rather simple approach, please give me feedback and re-open if you miss anything https://github.com/matteodem/meteor-easy-search#searching-over-several-collections.
from meteor-easy-search.
I would like to use it via Blaze Components, but i'm not sure i fully understand that documentation :
"If you want to use it with the Blaze Components, you can simply change the index parameter to an array and define one esEach loop for each index defined."
Can you please provide an exemple of how and where to declare things to make it work ?
Thanks
from meteor-easy-search.
Added an example to the REAME.md which looks like this:
<div class="search-input">
<!-- indexes is a javascript array which holds 'players' and 'cars' -->
{{> esInput index=indexes placeholder="Search..." }}
</div>
<div class="results-wrapper">
{{#esEach index="players"}}
{{> player}}
{{/esEach}}
{{#esEach index="cars"}}
{{> car}}
{{/esEach}}
</div>
For further clarification, you'd have to declare the variable like this:
Template.yourTemplate.indexes = ['players', 'cars'];
from meteor-easy-search.
Thanks a lot ! ;)
from meteor-easy-search.
I am also trying to use Blaze Components for multi-collection searching (e.g., dogs, cats and birds). I have created the search index for each collection separately, each having multiple fields, and searching each collection separately works well. I am using those same individual search indices for the multi-collection searching according to @matteodem 's example code two posts above. It doesn't show any results when I am searching. Should I not use the same search indices and create a new one? If so, how do I create a search index for multi-collection? Thanks!
from meteor-easy-search.
@artitw It doesn't work at the moment and there's a bug #72. I'll have a look this week
from meteor-easy-search.
Thank you, @matteodem !
Great stuff so far. Multi-collection search would be beyond awesome. I really look forward to it.
from meteor-easy-search.
It worked at some time, bugs me that it doesn't anymore. A CI would be great but I'll have to find the time for it. Thanks!
from meteor-easy-search.
hi, is the code example you posted above still the best way to do this? I am trying to search over 2 collections using elastic search.
from meteor-easy-search.
yep should work, this is also useable in the easy-search-leaderboard example.
from meteor-easy-search.
Hi @matteodem! My table contains multiple fields of multiple collections through some helpers. I don't want to separate search results by index, but each table row must contains all collections fields. Can I do it?
from meteor-easy-search.
Hello @alearcy What do you mean? You can create an index for each collection and pass in an array of indexes for the search. I'll add a Recipe section about it, if that could help you.
from meteor-easy-search.
@matteodem I can't find docs about search in multiple collections anymore, is it added somewhere?
I already found examples how to do that in this issue but think, that example must be added into documentation.
from meteor-easy-search.
http://matteodem.github.io/meteor-easy-search/docs/blaze-components/, see "Components with multiple indexes"
from meteor-easy-search.
The above link results in a 404. What is the current status on search across multiple indexes?
from meteor-easy-search.
Please have a closer look at the docs, components here show that some accept multiple indexes http://matteodem.github.io/meteor-easy-search/docs/components/ and with the new API in v2 you can search through multiple indexes by using the search
method on all the indexes you want to search.
from meteor-easy-search.
I saw that part of the doc. That gives me the answer to my question, indeed.
from meteor-easy-search.
Is there any documentation on how to implement it? I tried earlier following the above example (index=indexes
, declaring indexes in the template helper), but got errors about no index or array of indexes being passed on (if I recall correctly).
For the record: It seems to me that the above examples are outdated in terms of syntax by now (got a warning when trying to use Template.yourTemplate.indexes = ['players', 'cars'];"
, suggesting to set this up in the template helper).
from meteor-easy-search.
Yes they are, because they refer to the v1 API. It should be indexes=indexes
if you want to use multiple indexes. I'll add a new section about searching with multiple indexes
on the components page.
from meteor-easy-search.
I get the following error when trying to search on multiple indexes:
Error: Did not receive an index or an array of indexes: "[object Object],[object Object]" [invalid-configuration]
I am trying with this code:
MyTemplate.html
{{> EasySearch.Input index=indexes }}
MyTemplate.js
Template.MyTemplateName.helpers({
indexes: () => [firstIndex, secondIndex]
});
Both indexes are declared via new EasySearch.Index()
.
What is it I'm missing/doing wrong?
from meteor-easy-search.
The parameters should be indexes
instead of index
on your input.
{{> EasySearch.Input indexes=indexes }}
from meteor-easy-search.
I don't quite get what you are hinting at, sorry.
Assuming I have:
firstIndex = new EasySearch.Index({
collection: FirstCollection,
fields: ['field1', 'field2'],
engine: new EasySearch.MongoDB()
});
and
secondIndex = new EasySearch.Index({
collection: SecondCollection,
fields: ['field1', 'field2'],
engine: new EasySearch.MongoDB()
});
What should my template and my helpers look like?
from meteor-easy-search.
I also can't get search over multiple indexes to work, and would be very grateful if you can explain what I need to do. I'm using this in my template:
{{> EasySearch.Input indexes=indexes attributes=attributes }}
I get this error on the client: "Error: Can only specify one index [only-single-index]"
The rest of my code is:
client and server:
PatternsIndex = new EasySearch.Index({
collection: Patterns,
fields: ['name', 'tags'],
engine: new EasySearch.Minimongo(),
defaultSearchOptions: {
limit: 8
}
});
ColorsIndex = new EasySearch.Index({
collection: Colors,
fields: ['name'],
engine: new EasySearch.Minimongo(),
defaultSearchOptions: {
limit: 8
}
});
and client only:
Template.search.indexes = [PatternsIndex, ColorsIndex];
from meteor-easy-search.
FYI, I also tried assigning a name to each Index like this:
PatternsIndex = new EasySearch.Index({
name: 'patternsIndex',
collection: Patterns,
fields: ['name', 'tags'],
engine: new EasySearch.Minimongo(),
defaultSearchOptions: {
limit: 8
}
});
and changing my helper to this:
Template.search.indexes = ["patternsIndex", "testIndex"];
But I get the error "Error: Did not receive an index or an array of indexes: "patternsIndex,testIndex" [invalid-configuration]"
Easy Search is an awesome package and I'd really like to get this working!
from meteor-easy-search.
firstIndex = new EasySearch.Index({
collection: FirstCollection,
fields: ['field1', 'field2'],
engine: new EasySearch.MongoDB()
});
secondIndex = new EasySearch.Index({
collection: SecondCollection,
fields: ['field1', 'field2'],
engine: new EasySearch.MongoDB()
});
Template.myTemplate.helpers({
indexes: function () {
return [firstIndex, secondIndex];
},
firstIndex: function () {
return firstIndex;
},
secondIndex: function () {
return secondIndex;
}
});
<template name="myTemplate">
{{> EasySearch.Input indexes=indexes}}
{{#EasySearch.Each index=firstIndex}}
...
{{/EasySearch.Each}}
{{#EasySearch.Each index=secondIndex}}
...
{{/EasySearch.Each}}
</template>
from meteor-easy-search.
Having the above in the docs would be super helpful, got it working but the syntax is easy to get wrong.. thanks for this - the example you posted is great.
from meteor-easy-search.
you're right. I'll add an issue for that
from meteor-easy-search.
Thank you! I agree the syntax is tricky - I could only get it to work by copying your example and then changing one name at a time, but it is now working, awesome!
Is there any way to do IfSearching, IfNoResults across multiple indexes? Or do I need to construct nested statements in my template?
How will LoadMore work with multiple indexes? I don't want multiple buttons...
from meteor-easy-search.
please create new issues for these questions.
from meteor-easy-search.
Thank you. I've created three new issues:
- IfSearching and IfNoResults with multiple indexes
#378 - LoadMore with multiple indexes
#379 - Single list of results
#380
from meteor-easy-search.
Just a quick comment for anyone viewing this. There is a typo in @matteodem code example.
{{/EasySarch.Each}}
instead of
{{/EasySearch.Each}}
just missing an "e"
from meteor-easy-search.
thanks, changed it.
from meteor-easy-search.
added examples for multiple indexes here http://matteodem.github.io/meteor-easy-search/docs/components/ (Using multiple indexes)
from meteor-easy-search.
It's not working for me though i followed the documentation step by step. Here are my configurations (sorry for the very long post, but to make everything clear):-
Indexes
ProductsIndex = new Index({
collection: Products,
fields: ['name', 'brand', 'category'],
engine: new EasySearch.MongoDB({
transform(doc){
try{
let imageFile = Images.findOne({_id: doc.picture});
doc.imageFile = imageFile;
return doc;
}
catch(ex){
console.log(ex);
return doc;
}
}
}),
defaultSearchOptions: {
limit: 25
}
});
CategoriesIndex = new Index({
collection: Categories,
fields: ['name'],
engine: new EasySearch.MongoDB(),
defaultSearchOptions: {
limit: 25
}
});
JS
Template.MyTemplate.helpers({
productsIndex: function(){
return ProductsIndex;
},
categoriesIndex: function(){
return CategoriesIndex;
},
searchIndexes: function(){
return [ProductsIndex, CategoriesIndex];
},
searchInputAtts: {
class: 'form-control search-input',
placeholder: (Session.get('lang') == 'ar')? 'بحث...' : 'Search...'
},
loadMoreAtts: {
class: 'btn load-more-btn'
},
loadMoreContent: function(){
/*return '<i class="fa fa-spinner"></i> ' +
'<span>' +
((Session.get('lang') == 'ar')? 'المزيد...' : 'More...') +
'</span>';*/
return 'More...';
},
empty_text: () => {
return (Session.get('lang') == 'ar')? 'أدخل كلمات للبحث...' : 'Enter search text...';
},
no_result_text: () => {
return (Session.get('lang') == 'ar')? 'لا توجد نتائج للبحث...' : 'No matches...';
},
searching_text: () => {
return (Session.get('lang') == 'ar')? 'جاري البحث...' : 'Searching...';
},
notInSearchRoute: () => {
return !Session.get('inSearch');
}
});
HTML
<template name="MyTemplate">
{#if Template.subscriptionsReady}}
<div class="form-group search-form">
{{> EasySearch.Input indexes=searchIndexes attributes=searchInputAtts }}
{{#if notInSearchRoute}}
{{#EasySearch.IfInputEmpty indexes=searchIndexes}}
<div class="no-results">{{empty_text}}</div>
{{else}}
{{#EasySearch.IfNoResults indexes=searchIndexes logic="AND" }}
<div class="no-results">searchIndexes {{no_result_text}}</div>
{{else}}
{{#EasySearch.IfNoResults index=productsIndex}}
<div class="no-results">productsIndex {{no_result_text}}</div>
{{/EasySearch.IfNoResults}}
<ul class="quick-search-list">
{{#EasySearch.Each index=productsIndex}}
...
</div>
{{/if}}
</template>
Now the only result i get is: searchIndexes No Matches... no matter the query is.
PS: it used to work with one index smoothly
PS2: When I try from chrome devTools console, this is what I get (first time no results, second time has results):-
ProductsIndex.search('a');
>Cursor {_mongoCursor: L…n.Cursor, _count: 0, _isReady: false, _publishHandle: null}
ProductsIndex.search('a');
>Cursor {_mongoCursor: L…n.Cursor, _count: 8, _isReady: true, _publishHandle: Object}
CategoriesIndex.search('a');
>Cursor {_mongoCursor: L…n.Cursor, _count: 0, _isReady: false, _publishHandle: null}
CategoriesIndex.search('a');
>Cursor {_mongoCursor: L…n.Cursor, _count: 2, _isReady: true, _publishHandle: Object}
Please advise...
from meteor-easy-search.
Related Issues (20)
- Collation feature of MongoDB HOT 4
- Top-level dependency conflict when moving to Meteor 1.6.1 HOT 5
- "Match error: Expected Collection", path: "" HOT 2
- Compatibilty with Elasticsearch 6.3 HOT 1
- Does this still work with collection-helpers for composite fields? HOT 6
- "namespace is too long" HOT 2
- Documentation missing for elastic search HOT 5
- ifSearching doesn't seem to work HOT 2
- limiting the number of returned values HOT 3
- multiple index search with ElasticSearch? HOT 1
- Error in documentation for selectors HOT 1
- Is it possible to get ifSearching directly from the index? HOT 1
- facets that only show results that valid values HOT 1
- populating easy search input and getting search results on page render HOT 1
- Easy-search nested fields as props HOT 1
- Trying to access 'resultsHandle' variable before initialization. HOT 13
- After upgrade to [email protected] new Index fails with "Match error: Expected particular constructor" when using Meteor.users HOT 5
- Exclude html from search
- How to search from the start of the searchString? HOT 2
- Support for Meteor 3.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-easy-search.