[Groonga-commit] groonga/gcs [master] Search only from text type index columns by default

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 11日 (水) 18:59:10 JST


SHIMODA Hiroshi	2012-07-11 18:59:10 +0900 (Wed, 11 Jul 2012)

  New Revision: 29d6583e44807ac313149fea55061d6f424aea51
  https://github.com/groonga/gcs/commit/29d6583e44807ac313149fea55061d6f424aea51

  Log:
    Search only from text type index columns by default

  Modified files:
    lib/api/2011-02-01/search.js
    lib/database.js
    test/batch-processor.test.js

  Modified: lib/api/2011-02-01/search.js (+7 -3)
===================================================================
--- lib/api/2011-02-01/search.js    2012-07-11 18:40:31 +0900 (40ac3b5)
+++ lib/api/2011-02-01/search.js    2012-07-11 18:59:10 +0900 (ca53882)
@@ -37,9 +37,13 @@ exports.createHandler = function(database) {
     var startedAt = new Date();
     var domain = new Domain(request);
     var query = request.query.q || '';
-    var matchColumns = database.ordinalColumnsSync(domain.tableName)
-                         .map(function(column) {
-                           return column.name;
+    var matchIndexFields = database.indexFieldsSync(domain.name);
+    matchIndexFields = matchIndexFields.filter(function(field) {
+      return field.type == 'text';
+    });
+    var matchColumns = matchIndexFields
+                         .map(function(field) {
+                           return field.columnName;
                          })
                          .join('||');
     var size = parseInt(request.query.size || '10', 10);

  Modified: lib/database.js (+33 -0)
===================================================================
--- lib/database.js    2012-07-11 18:40:31 +0900 (aac4848)
+++ lib/database.js    2012-07-11 18:59:10 +0900 (56180a4)
@@ -2,6 +2,7 @@ var nroonga = require('nroonga');
 var Deferred = require('jsdeferred').Deferred;
 var path = require('path');
 var mkdirp = require('mkdirp');
+var Domain = require('../domain').Domain;
 
 var ShortText =
       exports.ShortText =
@@ -101,6 +102,38 @@ Database.prototype = {
       return column.name.charAt(0) !== '_';
     });
     return ordinalColumns;
+  },
+  indexFieldsSync: function(domainName) {
+    var tableName = (new Domain(domainName)).tableName;
+    var columns = this.ordinalColumnsSync(tableName);
+    var fields = columns.map(this.columnToIndexField);
+    return fields;
+  },
+  columnToIndexField: function(column) {
+    // XXX The "name" must be the field name given by the user,
+    // not normalized. Because there is no such information in the
+    // database and currently the column name is luckly equals to the
+    // given field name, we can use the column name.
+    var name = column.name;
+
+    var type;
+    if (column.type == 'var') {
+      if (column.range == ShortText)
+        type = 'text';
+    } else if (column.type == 'fix') {
+      if (column.range == UInt32)
+        type = 'uint';
+      else if (column.range == ShortText)
+        type = 'literal';
+    }
+    if (!type)
+      throw new Error('unknown unfixed column '+column.name);
+
+    return {
+      name: name,
+      columnName: column.name,
+      type: type
+    };
   }
 };
 

  Modified: test/batch-processor.test.js (+60 -2)
===================================================================
--- test/batch-processor.test.js    2012-07-11 18:40:31 +0900 (4d96044)
+++ test/batch-processor.test.js    2012-07-11 18:59:10 +0900 (9714c97)
@@ -48,8 +48,66 @@ suite('batch/processor/Processor (instance methods)', function() {
 
   test('getColumns', function() {
     var columns = processor.getColumns();
-    var expected = ['name', 'address', 'email_address', 'description',
-                    'age', 'product'];
+    var expected = [
+          { id: 0,
+            name: 'address',
+            path: '/path/to/database/file',
+            type: 'var',
+            flags: 
+        ];
+
+
+
+[ { id: 265,
+    name: 'address',
+    path: '/home/piro/gcs/test/tmp/database-1/database.0000109',
+    type: 'var',
+    flags: 'COLUMN_SCALAR|PERSISTENT',
+    domain: 'companies',
+    range: 'ShortText',
+    source: [] },
+  { id: 271,
+    name: 'age',
+    path: '/home/piro/gcs/test/tmp/database-1/database.000010F',
+    type: 'fix',
+    flags: 'COLUMN_SCALAR|PERSISTENT',
+    domain: 'companies',
+    range: 'UInt32',
+    source: [] },
+  { id: 264,
+    name: 'description',
+    path: '/home/piro/gcs/test/tmp/database-1/database.0000108',
+    type: 'var',
+    flags: 'COLUMN_SCALAR|PERSISTENT',
+    domain: 'companies',
+    range: 'ShortText',
+    source: [] },
+  { id: 266,
+    name: 'email_address',
+    path: '/home/piro/gcs/test/tmp/database-1/database.000010A',
+    type: 'var',
+    flags: 'COLUMN_SCALAR|PERSISTENT',
+    domain: 'companies',
+    range: 'ShortText',
+    source: [] },
+  { id: 263,
+    name: 'name',
+    path: '/home/piro/gcs/test/tmp/database-1/database.0000107',
+    type: 'var',
+    flags: 'COLUMN_SCALAR|PERSISTENT',
+    domain: 'companies',
+    range: 'ShortText',
+    source: [] },
+  { id: 267,
+    name: 'product',
+    path: '/home/piro/gcs/test/tmp/database-1/database.000010B',
+    type: 'fix',
+    flags: 'COLUMN_SCALAR|PERSISTENT',
+    domain: 'companies',
+    range: 'companies_product',
+    source: [] } ]
+
+
     assert.deepEqual(columns.sort(), expected.sort());
   });
 
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
下载 



Groonga-commit メーリングリストの案内
Back to archive index