meteor-autocomplete icon indicating copy to clipboard operation
meteor-autocomplete copied to clipboard

subscription docs?

Open bowlofudon opened this issue 10 years ago • 27 comments

The subscription param isn't well documented. Would be easier to implement if it was clearer.

bowlofudon avatar May 06 '14 00:05 bowlofudon

What confuses you about it?

mizzao avatar May 06 '14 01:05 mizzao

Trying to figure out how to implement the following using what was provided: "Use of a custom publish function also allows you to use full-text search services outside of Meteor, such as ElasticSearch."

Would be super awesome to get an example here.

bowlofudon avatar May 06 '14 02:05 bowlofudon

I think @queso recently provided an example in #36; I agree the documentation could be improved.

Can you take a look at what he did and suggest how we might write documentation for that? I thought that the publish function in the server code would be enough of an example.

mizzao avatar May 06 '14 02:05 mizzao

For example, it'd be nice if there was an example showing how ElasticSearch would work.

bowlofudon avatar May 06 '14 02:05 bowlofudon

I've never used it. It's just that some user suggested it, and we figured an advanced enough developer would be able to figure out how to send a query to the ElasticSearch cloud and push the results back out into a publication.

mizzao avatar May 06 '14 02:05 mizzao

One problem with ElasticSearch (or the new $text operator in Mongo 2.6) is that searches can't be replicated on the client with the same server selector. This might present problems with more than one server-side collection (#41).

dandv avatar May 07 '14 07:05 dandv

I don't think #41 is a real problem - https://github.com/mizzao/meteor-autocomplete/issues/41#issuecomment-42396252.

mizzao avatar May 07 '14 07:05 mizzao

I mean, I think it would be great if there was any example - elastic search or not - of how this would function. I've managed to make this work with Facebook api data, but it would of been a lot easier if there was an example. You could even demonstrate this using flickr image search for example.

bowlofudon avatar May 07 '14 07:05 bowlofudon

@bowlofudon - I'd love it if you would make one and add it to our examples directory!

mizzao avatar May 07 '14 07:05 mizzao

If you could create an autocomplete box that uses the Flickr image search API and displays image thumbnails in templates, that would be super awesome.

mizzao avatar May 07 '14 19:05 mizzao

Note to self - add a helper for publishing cursors on the server.

mizzao avatar Aug 06 '14 14:08 mizzao

For anyone who is still interested in this, if you check out the new file at

https://github.com/mizzao/meteor-autocomplete/blob/master/autocomplete-server.coffee

You'll see that it's a lot easier to write a publication when you have an existing cursor, using the convenience method.

mizzao avatar Oct 23 '14 01:10 mizzao

Wow :+1: :+1:

queso avatar Oct 23 '14 01:10 queso

Not that much wow, right? Just used a function that already exists.

mizzao avatar Oct 23 '14 02:10 mizzao

I'm really new to meteor and coffee script, as such i don't really understand how to use the Autocomplete.publishCursor interface. I'm attempting to create a service side subscription that exposes all Meteor Users to the AutoComplete client.

With my limited understanding, i've tried:

Server:

    Autocomplete.publishCursor(function() {
        return Meteor.users.find();
    },this);

Client:

AutoCompleteRecords = new Mongo.Collection("autoCompleteRecords")

Template.testTemplate.helpers({
     addMemberAutoCompleteSettings: function() {
            return {
                position: "top",
                limit: 5,
                rules: [
                    {
                        token: '@',
                        collection: 'autoCompleteRecords',
                        field: "username",
                        template: Template.addTemplate
                    } ]
            };
        }

Could you please point me in the right direction? Thanks

dcworldwide avatar Mar 10 '15 07:03 dcworldwide

Try this:

Server (add appropriate security features as in the example):

Meteor.publish("autocompleteUsers", function(selector, options) {
  Autocomplete.publishCursor(Meteor.users.find(selector, options), this);
  this.ready();
});

Client:

Template.testTemplate.helpers({
     addMemberAutoCompleteSettings: function() {
            return {
                position: "top",
                limit: 5,
                rules: [
                    {
                        token: '@',
                        subscription: 'autocompleteUsers',
                        field: "username",
                        template: Template.addTemplate
                    } ]
            };
        }
});

mizzao avatar Mar 10 '15 14:03 mizzao

Thanks. It works :+1: But i had to add collection: 'autocompleteRecords', to my settings.

dcworldwide avatar Mar 11 '15 03:03 dcworldwide

Ah, that was a bug. That string is completely meaningless, as the collection is determined by what you do in the subscription. You won't need to do this in the next release.

mizzao avatar Mar 11 '15 16:03 mizzao

Hi, I've tried to make the autocomplete work from a subscription as you mentioned (see below) but I get an error from the validateRule method : 'ReferenceError: Can't find variable: Match'. Can you tell me what I am missing ? Thanks !

//Server
Meteor.publish('autocomplete-test', function(selector, options) {
     Autocomplete.publishCursor(Categories.find(selector, options), this);
     return this.ready();
});
//Client
autoCompleteSettings: function() {
    return {
      position: "bottom",
      limit: 10,
      rules: [
        {
          token: '@',
          subscription: "autocomplete-test",
          field: "name",
          template: Template.searchPill
        }
      ]
    };
  }

Edit : I was missing the check module from meteor. If you get the same error just do a meteor add check

jota3 avatar Apr 13 '16 16:04 jota3

Hello,

I've tried the code above but I keep getting this error:

Exception from sub autocomplete-recordset id vRAdRMiPfmbGdCmov Error: autocompleteViewers is not defined on the global namespace of the server

Here's my server code: Meteor.publish("autocompleteViewers", function(selector, options) { Autocomplete.publishCursor(viewers.find(selector, options), this); this.ready(); });

And the client: getSettings: function() { return { position: 'bottom', limit: 5, rules: [{ collection: 'autocompleteViewers', field: '_id', matchAll: false, options: '', template: Template.dLegend }], }; },

Am I missing something? Any pointers would be greatly appreciated.

epileptic avatar May 06 '16 00:05 epileptic

Try subscription: "autocompleteViewers"

On Thu, May 5, 2016, 8:00 PM epileptic [email protected] wrote:

Hello,

I've tried the code above but I keep getting this error:

Exception from sub autocomplete-recordset id vRAdRMiPfmbGdCmov Error: autocompleteViewers is not defined on the global namespace of the server

Here's my server code: Meteor.publish("autocompleteViewers", function(selector, options) { Autocomplete.publishCursor(viewers.find(selector, options), this); this.ready(); });

And the client: getSettings: function() { return { position: 'bottom', limit: 5, rules: [{ collection: 'autocompleteViewers', field: '_id', matchAll: false, options: '', template: Template.dLegend }], }; },

Am I missing something? Any pointers would be greatly appreciated.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/mizzao/meteor-autocomplete/issues/40#issuecomment-217313707

mizzao avatar May 06 '16 00:05 mizzao

Thanks. I don't get an error on the server anymore but the client triggers an exception: Error: Collection name must be specified as string for server-side search at validateRule

epileptic avatar May 06 '16 00:05 epileptic

Is there a minimum working example featuring server-side autocompletion using a custom publish function somewhere? I could go from there and try to figure out what's wrong. The examples provided in the package only work with the insecure package which isn't really a typical scenario.

epileptic avatar May 07 '16 00:05 epileptic

When I inspect the code that's triggering the exception, this is what I see:

validateRule = function(rule) {
  if ((rule.subscription != null) && !Match.test(rule.collection, String)) {
    throw new Error(Collection name must be specified as string for server-side search);
  }
};

And in the package source, validateRule starts out like this:

validateRule = (rule) ->
  ...
  unless rule.subscription? or Match.test(rule.collection, Match.OneOf(String, Mongo.Collection))
    throw new Error("Collection to search must be either a Mongo collection or server-side name")

This doesn't look right to me.

epileptic avatar May 07 '16 09:05 epileptic

Oh, I meant remove collection: ... entirely and just use subscription: ...

mizzao avatar May 07 '16 15:05 mizzao

I did. I just replaced collection by subscription.

epileptic avatar May 07 '16 19:05 epileptic

Any updates ?

aessig avatar Aug 30 '17 22:08 aessig