matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
435 stars 68 forks source link

FieldInput doesn't work together with EsInput #476

Closed alexandersingleton closed 7 years ago

alexandersingleton commented 8 years ago

I've currently got an EasySearch Input working fine and as expected but when I add a FieldInput to modify the search results ( in this case to also search by location) I don't get the expected result where the FieldInput search seems to override the original search in the Input.

Not sure if this is a bug or if I am using it incorrectly? I've also tried the fix in issue #223 and the api has changed since then, so any solution on how to use two inputs to refine a search would be much appreciated.

Thanks

Alex

{{> EasySearch.Input index=jobsIndex attributes=inputAttributes}} 
 {{> EasySearch.FieldInput field="jobLocation" index=jobsIndex}}

jobsIndex = new EasySearch.Index({
  collection: Posts,
  fields: ['title', 'jobLocation', 'text', 'companyName', 'contractType', 'jobCategory', 'jobTags'],
  engine: new EasySearch.Minimongo({

    sort: function () {
      return { timeCreated: -1 }
},

defaultSearchOptions: {
    limit: 200 
  }
    })
});
matteodem commented 8 years ago

This is expected as the Input component searches in all fields. Maybe it makes sense to make it possible to give the FieldInput an array of fields?

alexandersingleton commented 8 years ago

Thanks for the prompt reply,

Adding an array of fields doesn't appear to give me what I'm after.

The use case would be that someone searches for a keyword then in a separate input refines that search by location.

Is there a some way of modifying the search result/cursor with a custom keyup event so that it only returns results based on that second input?

Best,

matteodem commented 8 years ago

What do you mean by keyword? What an array of fields would allow you is to set all the fields but location in that FieldInput and the other one only searching for location.

alexandersingleton commented 8 years ago

I think setting an array of fields would work if that's the case.

In this example I'd want to be able to search for keywords like 'web developer' in the input and then narrow the search results down by location in the FieldInput or vice versa.

Is there a workaround I could use in the meantime which would allow the functionality I'm after? I've managed to use props on a keyup event but that requires the full word before the results get filtered and it's also case sensitive which isn't ideal.

Thanks,

Template.home.events({
  'keyup .location-input': function (e) {

   jobsIndex.getComponentMethods(/* optional name */)

      .addProps('locationFilter', e.target.id);

  }
});
matteodem commented 8 years ago

I'd also for now use props. You can either analyze the string yourself and create a suitable mongodb selector or use a more comprehensive and mature solution like ElasticSearch with this library.