Autocomplete and distinct feature?


#1

Hi,
I have a collection Songs which contains data in the following format:

{artist:"Dream Theater", title: "Pull me under"}, {artist:"Dream Theater", title: "Finally free"}

I am using the package mizzao-autocomplete There are more than 5000 entries, so I definetely need server-side autocompletion.
On server I published the collection:

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

Client subscription looks like:

Template.home.helpers({
    settings: function() {
        return {
            position: "top",
            limit: 5,
            rules: [{
                collection: 'Songs',
                subscription: 'autocompleteArtists',
                field: "artist",
                template: Template.songItem
            }]
        };
    }
});

Should I have both collection and subscription in the settings() function?

Last part, the client template:

{{> inputAutocomplete settings=settings id="artistInput" type="text" placeholder="Artist" length="20"}}

My purpose is to look for an artist and when I select it, to subscribe to a simple server publish which returns all songs belonging to that artist. The thing is, if I have multiple entries with the same artist, of course, the list of results is showing the artist multiple times. I would need to to somehow a “distinct” publish which would return all artists, but there’s no such a feature in Meteor. I found some things implementing the aggregation and distinct, but I don’t see how to use Autocomplete publishCursor function… My temporary solution was to denormalize and add a Artists collection, but I should not do that.

Is there a simpler way?


#2

Anybody?I feel like I am definitely missing something trivial :slight_smile: