matteodem / meteor-easy-search

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

Selector doesn't always clean old ones #544

Closed ilan-schemoul closed 7 years ago

ilan-schemoul commented 7 years ago

When one changes the URL the selector of category is changed

this.autorun(() => {
    if (localWorksheets.isReady.get()) {
      worksheetsSearch.set(new EasySearch.Index({
        collection: localWorksheets,
        specialCollection: 'RGround',
        fields: ['title', 'content'],
        engine: new EasySearch.Minimongo({
          transform(doc) {
            const userContent = findUserWorksheet(doc._id);
            if (userContent) {
              doc.content = userContent;
              doc.isModified = true;
            }
            return doc;
          },
          selector(searchObject, options, aggregation) {
            const selector =
            this.defaultConfiguration().selector(searchObject, options, aggregation);
            if (options.search.props.category) selector.category = options.search.props.category;
            if (options.search.props.isFree) selector.isFree = options.search.props.isFree;
            return selector;
          },
          sort: () => ({ updatedAt: -1 }),
        }),
      }));
    }
  });

onRendered

  this.autorun(() => {
    FlowRouter.watchPathChange();
    if (localWorksheets.isReady.get() && localUser.isReady.get() && worksheetsSearch.get()) {
      const method = categories.findAType(localWorksheets, 'method');
      const specialty = categories.findAType(localWorksheets, 'specialty');
      setTimeout(() => {
        if (FlowRouter.getRouteName() === 'method') {
          worksheetsSearch.get().getComponentMethods().addProps('category', method);
        } else if (FlowRouter.getRouteName() === 'specialty') {
          worksheetsSearch.get().getComponentMethods().addProps('category', specialty);
        } else if (FlowRouter.getRouteName() === 'extra') {
          worksheetsSearch.get().getComponentMethods().addProps('category', '9');
        }
      }, 100);
    }
  });

But sometimes when I switch between two URL (which change the selector "categorie") everything is mixed up.

ilan-schemoul commented 7 years ago

Anyway I'm now creating my own custom search engine, thanks for past support anyway.

matteodem commented 7 years ago

I'm really going to reserve next week to resolve some open conflicts + documentation. I feel like most problems can be resolved by having a clearer description of what EasySearch does / provides. Sorry for that