Meteor-Community-Packages / meteor-autocomplete

Client/server autocompletion designed for Meteor's collections and reactivity.
https://atmospherejs.com/mizzao/autocomplete
MIT License
350 stars 108 forks source link

subscription docs? #40

Open bowlofudon opened 10 years ago

bowlofudon commented 10 years ago

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

mizzao commented 10 years ago

What confuses you about it?

bowlofudon commented 10 years ago

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.

mizzao commented 10 years ago

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.

bowlofudon commented 10 years ago

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

mizzao commented 10 years ago

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.

dandv commented 10 years ago

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).

mizzao commented 10 years ago

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

bowlofudon commented 10 years ago

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.

mizzao commented 10 years ago

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

mizzao commented 10 years ago

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 commented 10 years ago

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

mizzao commented 10 years ago

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.

queso commented 10 years ago

Wow :+1: :+1:

mizzao commented 10 years ago

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

dcworldwide commented 9 years ago

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

mizzao commented 9 years ago

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
                    } ]
            };
        }
});
dcworldwide commented 9 years ago

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

mizzao commented 9 years ago

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.

jota3 commented 8 years ago

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

epileptic commented 8 years ago

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.

mizzao commented 8 years ago

Try subscription: "autocompleteViewers"

On Thu, May 5, 2016, 8:00 PM epileptic notifications@github.com 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

epileptic commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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.

mizzao commented 8 years ago

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

epileptic commented 8 years ago

I did. I just replaced collection by subscription.

aessig commented 7 years ago

Any updates ?