YUKI Hiroshi
null+****@clear*****
Thu Nov 1 12:20:38 JST 2012
YUKI Hiroshi 2012-11-01 12:20:38 +0900 (Thu, 01 Nov 2012) New Revision: f47f012261479d1900fd54785030aabc3aaa6c39 https://github.com/groonga/gcs/commit/f47f012261479d1900fd54785030aabc3aaa6c39 Log: Bind "rank" option for the search API to "--searchby" option for groonga Modified files: lib/api/2011-02-01/search.js lib/select-query.js Modified: lib/api/2011-02-01/search.js (+2 -1) =================================================================== --- lib/api/2011-02-01/search.js 2012-11-01 12:11:29 +0900 (65774de) +++ lib/api/2011-02-01/search.js 2012-11-01 12:20:38 +0900 (c60ecc4) @@ -100,7 +100,7 @@ function createResultBody(options) { 'cpu-time-ms': 0 // TODO }; return { - rank: '-text_relevance', // FIXME + rank: options.rankExpression, 'match-expr': options.matchExpression, hits: { found: options.found, @@ -163,6 +163,7 @@ exports.createHandler = function(context) { } var result = createResultBody({ matchExpression: selectQuery.matchExpression, + rankExpression: selectQuery.rankExpression, found: numFoundRecords, start: selectQuery.start, hit: data, Modified: lib/select-query.js (+24 -0) =================================================================== --- lib/select-query.js 2012-11-01 12:11:29 +0900 (4e648ed) +++ lib/select-query.js 2012-11-01 12:20:38 +0900 (b491e6f) @@ -90,6 +90,27 @@ SelectQuery.prototype = { }); }, + get sortKey() { + if (this._sortKey === undefined) + this,_sortKey = this.prepareSortKey(); + return this._sortKey; + }, + prepareSortKey: function() { + var sortKey = this.request.query.rank; + if (!sortKey) + return null; + + var fieldName = sortKey.replace(/^-/, ''); + if (!this.domain.getIndexField(fieldName).exists()) + return null; + + return sortKey; + }, + + get rankExpression() { + return this.sortKey || '-text_relevance'; + }, + parse: function() { var filters = []; var matchExpression = ''; @@ -219,6 +240,9 @@ SelectQuery.prototype = { output_columns: this.outputColumns.join(', ') }; + if (this.sortKey) + options.sortby = this.sortKey; + if (this.domain.hasSynonymsTableSync()) options.query_expansion = this.domain.synonymsTableName + '.synonyms'; -------------- next part -------------- HTML����������������������������...Download