<commit_before>module.exports = {

  show: function(req, res) {
    var term = req.param('q').trim(),
      resultTypes = req.param('include'),
      limit = req.param('limit') || 10,
      offset = req.param('offset') || 0;

    var findCommunityIds = Promise.method(function() {
      if (req.param('communityId')) {
        return [parseInt(req.param('communityId'))];
      } else {
        return Membership.activeCommunityIds(req.session.userId);
      }
    });

    return findCommunityIds().then(function(communityIds) {

      return Promise.join(
        (!_.contains(resultTypes, 'seeds') ? [] :
          Search.forSeeds({
            term: term,
            limit: limit,
            offset: offset,
            communities: communityIds
          }).fetchAll({withRelated: PostPresenter.relations(req.session.userId)})
        ),
        (!_.contains(resultTypes, 'people') ? [] :
          Search.forUsers({
            term: term,
            limit: limit,
            offset: offset,
            communities: communityIds
          }).fetchAll({withRelated: ['skills', 'organizations']})
        )
      );

    }).spread(function(seeds, people) {

      res.ok({
        seeds_total: (seeds.length > 0 ? parseInt(seeds.first().get('total')) : 0),

        seeds: seeds.map(function(seed) {
          return PostPresenter.present(seed);
        }),

        people_total: (people.length > 0 ? parseInt(people.first().get('total')) : 0),

        people: people.map(function(user) {
          return _.chain(user.attributes)
          .pick([
            'id', 'name', 'avatar_url', 'bio'
          ])
          .extend({
            skills: Skill.simpleList(user.relations.skills),
            organizations: Organization.simpleList(user.relations.organizations)
          }).value();
        })

      });

    }).catch(res.serverError.bind(res));

  }

};<commit_msg>sort seed results by creation date<commit_after>module.exports = {

  show: function(req, res) {
    var term = req.param('q').trim(),
      resultTypes = req.param('include'),
      limit = req.param('limit') || 10,
      offset = req.param('offset') || 0;

    var findCommunityIds = Promise.method(function() {
      if (req.param('communityId')) {
        return [parseInt(req.param('communityId'))];
      } else {
        return Membership.activeCommunityIds(req.session.userId);
      }
    });

    return findCommunityIds().then(function(communityIds) {

      return Promise.join(
        (!_.contains(resultTypes, 'seeds') ? [] :
          Search.forSeeds({
            term: term,
            limit: limit,
            offset: offset,
            communities: communityIds,
            sort: 'post.creation_date'
          }).fetchAll({withRelated: PostPresenter.relations(req.session.userId)})
        ),
        (!_.contains(resultTypes, 'people') ? [] :
          Search.forUsers({
            term: term,
            limit: limit,
            offset: offset,
            communities: communityIds
          }).fetchAll({withRelated: ['skills', 'organizations']})
        )
      );

    }).spread(function(seeds, people) {

      res.ok({
        seeds_total: (seeds.length > 0 ? parseInt(seeds.first().get('total')) : 0),

        seeds: seeds.map(function(seed) {
          return PostPresenter.present(seed);
        }),

        people_total: (people.length > 0 ? parseInt(people.first().get('total')) : 0),

        people: people.map(function(user) {
          return _.chain(user.attributes)
          .pick([
            'id', 'name', 'avatar_url', 'bio'
          ])
          .extend({
            skills: Skill.simpleList(user.relations.skills),
            organizations: Organization.simpleList(user.relations.organizations)
          }).value();
        })

      });

    }).catch(res.serverError.bind(res));

  }

};
{'fraction_non_alphanumeric': 0.1546284224250326, 'fraction_numerical': 0.003650586701434159, 'mean_word_length': 2.111111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5506955', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1083, 'n_words': 185}