[Groonga-commit] groonga/gcs [master] Implement backend of index field options

Back to archive index

SHIMODA Hiroshi null+****@clear*****
Mon Aug 13 16:27:55 JST 2012


SHIMODA Hiroshi	2012-08-13 16:27:55 +0900 (Mon, 13 Aug 2012)

  New Revision: 83dfe72bf43885f6bdc808c160f4ec83bad9cdc2
  https://github.com/groonga/gcs/commit/83dfe72bf43885f6bdc808c160f4ec83bad9cdc2

  Log:
    Implement backend of index field options

  Modified files:
    lib/database/index-field.js
    test/database-index-field.test.js

  Modified: lib/database/index-field.js (+79 -6)
===================================================================
--- lib/database/index-field.js    2012-08-13 16:09:05 +0900 (4b0dd68)
+++ lib/database/index-field.js    2012-08-13 16:27:55 +0900 (4161eb8)
@@ -134,7 +134,6 @@ IndexField.prototype = {
   set type(type) {
     return this._type = type
   },
-
   setType: function(type) {
     this.type = type;
     return this;
@@ -145,15 +144,70 @@ IndexField.prototype = {
   },
 
   get facetEnabled() {
-    return this.type != 'uint';
+    // uint fields cannot be drilldowned by groonga...
+    if (this.type == 'uint')
+      return false;
+
+    if (this._facetEnabled !== undefined)
+      return !!this._facetEnabled;
+
+    var value = this.domain.getConfiguration(this.facetEnabledConfigurationKey);
+    return !!(this._facetEnabled = value);
+  },
+  set facetEnabled(value) {
+    this._facetEnabled = value;
+    return value;
+  },
+  setFacetEnabled: function(value) {
+    this.facetEnabled = value;
+    return value;
+  },
+  get facetEnabledConfigurationKey() {
+    return 'column_' + this.name + '_option_facet_enabled';
   },
 
   get resultEnabled() {
-    return true;
+    if (this.type == 'uint')
+      return true;
+
+    if (this._resultEnabled !== undefined)
+      return !!this._resultEnabled;
+
+    var value = this.domain.getConfiguration(this.resultEnabledConfigurationKey);
+    return !!(this._resultEnabled = value);
+  },
+  set resultEnabled(value) {
+    this._resultEnabled = value;
+    return value;
+  },
+  setResultEnabled: function(value) {
+    this.resultEnabled = value;
+    return value;
+  },
+  get resultEnabledConfigurationKey() {
+    return 'column_' + this.name + '_option_result_enabled';
   },
 
   get searchEnabled() {
-    return true;
+    if (this.type == 'text' || this.type == 'uint')
+      return true;
+
+    if (this._searchEnabled !== undefined)
+      return !!this._searchEnabled;
+
+    var value = this.domain.getConfiguration(this.searchEnabledConfigurationKey);
+    return !!(this._searchEnabled = value);
+  },
+  set searchEnabled(value) {
+    this._searchEnabled = value;
+    return value;
+  },
+  setSearchEnabled: function(value) {
+    this.searchEnabled = value;
+    return value;
+  },
+  get searchEnabledConfigurationKey() {
+    return 'column_' + this.name + '_option_search_enabled';
   },
 
   get options() {
@@ -203,10 +257,25 @@ IndexField.prototype = {
       type: this.domain.tableName,
       source: this.columnName
     });
+
+    if (this.facetEnabled !== undefined)
+      this.domain.setConfiguration(this.facetEnabledConfigurationKey,
+                                   this.facetEnabled);
+    if (this.resultEnabled !== undefined)
+      this.domain.setConfiguration(this.resultEnabledConfigurationKey,
+                                   this.resultEnabled);
+    if (this.searchEnabled !== undefined)
+      this.domain.setConfiguration(this.searchEnabledConfigurationKey,
+                                   this.searchEnabled);
   },
   deleteSync: function() {
-    var type = this.type;
-    if (type == 'uint' || type == 'literal') {
+    // backup information for re-creation
+    this._type = type;
+    this._facetEnabled = this.facetEnabled;
+    this._resultEnabled = this.resultEnabled;
+    this._searchEnabled = this.searchEnabled;
+
+    if (this._type == 'uint' || this._type == 'literal') {
       this.context.commandSync('table_remove', {
         name: this.indexTableName
       });
@@ -215,6 +284,10 @@ IndexField.prototype = {
       table: this.domain.tableName,
       name: this.columnName
     });
+
+    this.domain.deleteConfiguration(this.facetEnabledConfigurationKey);
+    this.domain.deleteConfiguration(this.resultEnabledConfigurationKey);
+    this.domain.deleteConfiguration(this.searchEnabledConfigurationKey);
   },
   reindexSync: function() {
     var name = this.name;

  Modified: test/database-index-field.test.js (+6 -6)
===================================================================
--- test/database-index-field.test.js    2012-08-13 16:09:05 +0900 (4760466)
+++ test/database-index-field.test.js    2012-08-13 16:27:55 +0900 (3abfe14)
@@ -104,8 +104,8 @@ suite('database', function() {
         state:         field.state,
         options:       field.options
       }, {
-        facetEnabled:  true,
-        resultEnabled: true,
+        facetEnabled:  false,
+        resultEnabled: false,
         searchEnabled: true,
         state:         'Active',
         options:       'Search Facet Result'
@@ -122,7 +122,7 @@ suite('database', function() {
         state:         field.state,
         options:       field.options
       }, {
-        facetEnabled:  false,
+        facetEnabled:  false, // disabled by groonga...
         resultEnabled: true,
         searchEnabled: true,
         state:         'Active',
@@ -140,9 +140,9 @@ suite('database', function() {
         state:         field.state,
         options:       field.options
       }, {
-        facetEnabled:  true,
-        resultEnabled: true,
-        searchEnabled: true,
+        facetEnabled:  false,
+        resultEnabled: false,
+        searchEnabled: false,
         state:         'Active',
         options:       'Search Facet Result'
       });
-------------- next part --------------
HTML����������������������������...
다운로드 



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