Take the 2-minute tour ×

I have attempted implementing search in Telescope using pure javascript, since it looks like FTS is a while off for Meteor to implement and I couldn't get 2.4 playing nicely with Meteor yet.

I'm using the existing pagination model that is already implemented in Telescope to display the Top/New/Best posts, plus a Session variable for the search keyword that is set in the Router when you navigate to e.g. /search/foobar.

However, it doesn't quite seem to be working; when I have, say, 100 posts, the regular paginated subscription only comes back with 25 of these and my search results only show the posts in the first 25.

I've been banging my head against a wall for days trying to debug this one: sometimes it works, sometimes it doesn't!

Here's the code (I've included all additional search code for reference):


var resultsPostsSubscription = function() {
  var handle = paginatedSearchSubscription( 10, 'searchResults' );
  handle.fetch = function() {
    return limitDocuments( searchPosts( Session.get( 'keyword' ) ), handle.loaded() );
  return handle;

var resultsPostsHandle = resultsPostsSubscription();


I duplicated the existing paginatedSubscription because I can't pass a Session var in as an arg; it needs to be dynamic. I'll probably refactor later.

paginatedSearchSubscription = function (perPage/*, name, arguments */) {
  var handle = new PaginatedSubscriptionHandle(perPage);
  var args = Array.prototype.slice.call(arguments, 1);

  Meteor.autosubscribe(function() {
    var subHandle = Meteor.subscribe.apply(this, args.concat([
      Session.get( 'keyword' ), handle.limit(), function() { handle.done(); }
    handle.stop = subHandle.stop;

  return handle;

search.js: (new file, in /common directory)

// get all posts where headline, categories, tags or body are LIKE %keyword%
searchPosts = function( keyword ) {
  var query = new RegExp( keyword, 'i' );
  var results = Posts.find( { $or: [ { 'headline': query }, { 'categories': query }, { 'tags': query }, { 'body': query } ] } );
  return results;


Meteor.publish( 'searchResults', searchPosts );


<template name="posts_results">
  {{> posts_list resultsPostsHandle}}


Template.posts_results.resultsPostsHandle = function() { 
  return resultsPostsHandle;

router.js: there's a search bar in the nav that redirects to here

posts_results = function( keyword ) {
  Session.set( 'keyword' , keyword );
  return 'posts_results';


Any help would be greatly appreciated!

share|improve this question
we've been struggling a lot with these complex subscriptions ourselves. Perhaps it would be more fruitful to contact Sacha + I directly and we can collectively try to figure it out. I think you can figure out our email addresses :) –  Tom Coleman Apr 8 '13 at 13:38
Would you mind cloning Telescope on GitHub and pushing all your exact changes to it? I've made a very simple search test ( gist.github.com/yeputons/8807589 ) with two subscriptions and it works as expected. –  yeputons Feb 4 at 16:51
add comment


Your Answer



Browse other questions tagged or ask your own question.