[Groonga-commit] groonga/gcs [master] Add Domain#facetReturnableIndexFields, Domain#resultReturnableIndexFields, Domain#searchableIndexFields

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Aug 22 17:00:30 JST 2012


YUKI Hiroshi	2012-08-22 17:00:30 +0900 (Wed, 22 Aug 2012)

  New Revision: 061928e562dad57d002a092e1bf8dbc21e40cf50
  https://github.com/groonga/gcs/commit/061928e562dad57d002a092e1bf8dbc21e40cf50

  Log:
    Add Domain#facetReturnableIndexFields, Domain#resultReturnableIndexFields, Domain#searchableIndexFields

  Modified files:
    lib/database/domain.js
    test/database-domain.test.js

  Modified: lib/database/domain.js (+15 -0)
===================================================================
--- lib/database/domain.js    2012-08-22 16:40:49 +0900 (9421d2c)
+++ lib/database/domain.js    2012-08-22 17:00:30 +0900 (0a87fa3)
@@ -179,6 +179,21 @@ Domain.prototype = {
                  }, this);
     return fields;
   },
+  get facetReturnableIndexFields() {
+    return this.indexFields.filter(function(field) {
+      return field.facetEnabled;
+    });
+  },
+  get resultReturnableIndexFields() {
+    return this.indexFields.filter(function(field) {
+      return field.resultEnabled;
+    });
+  },
+  get searchableIndexFields() {
+    return this.indexFields.filter(function(field) {
+      return field.searchEnabled;
+    });
+  },
 
   get defaultSearchField() {
     var fieldName = this.getConfiguration(this.defaultSearchFieldConfigurationKey);

  Modified: test/database-domain.test.js (+83 -0)
===================================================================
--- test/database-domain.test.js    2012-08-22 16:40:49 +0900 (b2f7254)
+++ test/database-domain.test.js    2012-08-22 17:00:30 +0900 (cab9c88)
@@ -256,6 +256,89 @@ suite('database', function() {
         assert.deepEqual(fields.sort(sortFields), expected.sort(sortFields));
       });
 
+      test('facetReturnableIndexFields', function() {
+        domain.getIndexField('address').facetEnabled = false;
+        domain.getIndexField('description').facetEnabled = false;
+        domain.getIndexField('email_address').facetEnabled = true;
+        domain.getIndexField('name').facetEnabled = true;
+        domain.getIndexField('product').facetEnabled = true;
+        var fields = domain.facetReturnableIndexFields;
+        fields = fields.map(function(field) {
+          return {
+            name: field.name,
+            type: field.type
+          };
+        });
+        var expected = [
+              { name: 'email_address',
+                type: 'text'},
+              { name: 'name',
+                type: 'text'},
+              { name: 'product',
+                type: 'literal'}
+            ];
+        function sortFields(a, b) {
+          return a.name - b.name;
+        }
+        assert.deepEqual(fields.sort(sortFields), expected.sort(sortFields));
+      });
+
+      test('resultReturnableIndexFields', function() {
+        domain.getIndexField('address').resultEnabled = true;
+        domain.getIndexField('description').resultEnabled = true;
+        domain.getIndexField('email_address').resultEnabled = true;
+        domain.getIndexField('name').resultEnabled = false;
+        domain.getIndexField('product').resultEnabled = false;
+        var fields = domain.resultReturnableIndexFields;
+        fields = fields.map(function(field) {
+          return {
+            name: field.name,
+            type: field.type
+          };
+        });
+        var expected = [
+              { name: 'address',
+                type: 'text'},
+              { name: 'age',
+                type: 'uint'},
+              { name: 'description',
+                type: 'text'},
+              { name: 'email_address',
+                type: 'text'}
+            ];
+        function sortFields(a, b) {
+          return a.name - b.name;
+        }
+        assert.deepEqual(fields.sort(sortFields), expected.sort(sortFields));
+      });
+
+      test('searchableIndexFields', function() {
+        domain.getIndexField('product').searchEnabled = false;
+        var fields = domain.resultReturnableIndexFields;
+        fields = fields.map(function(field) {
+          return {
+            name: field.name,
+            type: field.type
+          };
+        });
+        var expected = [
+              { name: 'address',
+                type: 'text'},
+              { name: 'age',
+                type: 'uint'},
+              { name: 'description',
+                type: 'text'},
+              { name: 'email_address',
+                type: 'text'},
+              { name: 'name',
+                type: 'text'}
+            ];
+        function sortFields(a, b) {
+          return a.name - b.name;
+        }
+        assert.deepEqual(fields.sort(sortFields), expected.sort(sortFields));
+      });
+
       test('setting default search field (instance)', function() {
         assert.isTrue(domain.defaultSearchField === null,
                       domain.defaultSearchField);
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index