meteorhacks / search-source

Reactive Data Source for Search
MIT License
146 stars 33 forks source link

Weird behavior of getData() #15

Open woniesong92 opened 9 years ago

woniesong92 commented 9 years ago

Demo page: http://cornellcoursereview.meteor.com/

My code:

if (Meteor.isServer) {
  SearchSource.defineSource('courses', function(searchText, options) {
    var options = {
      fields: {'catalog':1, 'titleLong':1, 'catalogNbr':1},
      limit: 10
    };

    if(searchText) {
      var regExp = buildRegExp(searchText);

      var selector = {$or: [
        {titleLong: { $regex: regExp } },
        {catalog: { $regex: regExp } },
        {catalogNbr: { $regex: regExp } }
      ]}

      return Courses.find(selector, options).fetch();
    } else {
      console.log("couldn't find anything that suits the query");
      console.log("query:", searchText);
      return Courses.find({}, options).fetch();
    }
  });

  function buildRegExp(searchText) {
    var words = searchText.trim().split(/[ \-\:]+/);
    var exps = _.map(words, function(word) {
      return "(?=.*" + word + ")";
    });
    var fullExp = exps.join('') + ".+";
    return new RegExp(fullExp, "i");
  }
}

query = "intro algo" matches with "introduction to analysis of algorithms" If you go to the demo url, you will see that although the document is found, it's rendered in a weird way.

Type into algo first, then press any function key like alt, cmd, or ctrl. You will see that the result disappears and appears intermittently.

Set breakpoints inside getData() and you will see that it returns an empty object even though there's fetch data.

woniesong92 commented 9 years ago

https://github.com/meteorhacks/search-source/issues/7

this seems to be the same issue.