Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #124 from Financial-Times/perf-n-bugs
Browse files Browse the repository at this point in the history
Perf n bugs
  • Loading branch information
wheresrhys committed Mar 23, 2015
2 parents 5e1488b + cf066de commit ea04bc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/api/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = function (term, opts) {
}

var requestBody = {
queryString: term,
queryString: term.replace(':', ':='),
queryContext: {
curations: ["ARTICLES", "BLOGS"]
},
Expand Down
26 changes: 20 additions & 6 deletions lib/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var _ = require('lodash');
// body text processing
var cheerio = require('cheerio');
var dom = require('../utils/dom');
var readingSpeed = 300; // wpm

function Article (obj) {
if (obj && obj.item) {
Expand All @@ -23,13 +24,7 @@ Article.prototype.parse = function (obj) {
this.id = obj.item.id;
this.raw = obj;

var readingSpeed = 300; // wpm

if (!this.raw.item.body) return;

// FIXME - move to defineProperty getters
this.wordCount = this.body.split(' ').length;
this.readingTime = Math.round(this.wordCount / readingSpeed);
};

/**
Expand Down Expand Up @@ -61,6 +56,25 @@ Object.defineProperty(Article.prototype, 'outboundLinks', {
}
});


/**
* Returns the article body wordcount
*/
Object.defineProperty(Article.prototype, 'wordCount', {
get: function () {
return this.body.split(' ').length;
}
});

/**
* Returns an estimate of the reading time for the article
*/
Object.defineProperty(Article.prototype, 'readingTime', {
get: function () {
return Math.round(this.wordCount / readingSpeed);
}
});

/**
* Returns the article headline
*/
Expand Down

0 comments on commit ea04bc3

Please sign in to comment.