[Groonga-commit] groonga/gcs [master] Save default search field

Zurück zum Archiv-Index

SHIMODA Hiroshi null+****@clear*****
Tue Aug 14 18:19:52 JST 2012


SHIMODA Hiroshi	2012-08-14 18:19:52 +0900 (Tue, 14 Aug 2012)

  New Revision: 1ef9502cd9e976a2b22f48889b07c2d9752b8bba
  https://github.com/groonga/gcs/commit/1ef9502cd9e976a2b22f48889b07c2d9752b8bba

  Log:
    Save default search field

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

  Modified: lib/database/domain.js (+20 -0)
===================================================================
--- lib/database/domain.js    2012-08-14 18:48:38 +0900 (b84d38c)
+++ lib/database/domain.js    2012-08-14 18:19:52 +0900 (5dc940d)
@@ -180,6 +180,26 @@ Domain.prototype = {
     return fields;
   },
 
+  get defaultSearchField() {
+    var fieldName = this.getConfiguration(this.defaultSearchFieldConfigurationKey);
+    var field = this.getIndexField(fieldName);
+    return field.exists() ? field : null ;
+  },
+  set defaultSearchField(value) {
+    if (!value) {
+      this.deleteConfiguration(this.defaultSearchFieldConfigurationKey);
+    } else {
+      if (typeof value == 'string')
+        value = this.getIndexField(value);
+      if (value.exists())
+        this.setConfiguration(this.defaultSearchFieldConfigurationKey, value.name);
+    }
+    return value;
+  },
+  get defaultSearchFieldConfigurationKey() {
+    return 'default_search_field';
+  },
+
   get id() {
     return this._id === undefined ? DEFAULT_ID : this._id ;
   },

  Modified: lib/database/index-field.js (+29 -6)
===================================================================
--- lib/database/index-field.js    2012-08-14 18:48:38 +0900 (d9dbe95)
+++ lib/database/index-field.js    2012-08-14 18:19:52 +0900 (735983e)
@@ -148,7 +148,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       return false;
 
-    if (!this.column || this._facetEnabled !== undefined)
+    if (!this.exists() || this._facetEnabled !== undefined)
       return !!this._facetEnabled;
 
     var value = this.domain.getConfiguration(this.facetEnabledConfigurationKey);
@@ -158,7 +158,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       throw new Error('facet option cannot be configured for the type ' + this.type + '.');
 
-    this._facetEnabled = value;
+    this._facetEnabled = !!value;
     return value;
   },
   setFacetEnabled: function(value) {
@@ -173,7 +173,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       return true;
 
-    if (!this.column || this._resultEnabled !== undefined)
+    if (!this.exists() || this._resultEnabled !== undefined)
       return !!this._resultEnabled;
 
     var value = this.domain.getConfiguration(this.resultEnabledConfigurationKey);
@@ -183,7 +183,7 @@ IndexField.prototype = {
     if (this.type == 'uint')
       throw new Error('returnable option cannot be configured for the type ' + this.type + '.');
 
-    this._resultEnabled = value;
+    this._resultEnabled = !!value;
     return value;
   },
   setResultEnabled: function(value) {
@@ -198,7 +198,7 @@ IndexField.prototype = {
     if (this.type == 'text' || this.type == 'uint')
       return true;
 
-    if (!this.column || this._searchEnabled !== undefined)
+    if (!this.exists() || this._searchEnabled !== undefined)
       return !!this._searchEnabled;
 
     var value = this.domain.getConfiguration(this.searchEnabledConfigurationKey);
@@ -208,7 +208,7 @@ IndexField.prototype = {
     if (this.type == 'text' || this.type == 'uint')
       throw new Error('searchable option cannot be configured for the type ' + this.type + '.');
 
-    this._searchEnabled = value;
+    this._searchEnabled = !!value;
     return value;
   },
   setSearchEnabled: function(value) {
@@ -219,6 +219,21 @@ IndexField.prototype = {
     return 'column_' + this.name + '_option_search_enabled';
   },
 
+  get defaultSearchField() {
+    if (!this.exists())
+      return false;
+
+    return this == this.domain.defaultSearchField;
+  },
+  set defaultSearchField(value) {
+    this._defaultSearchField = !!value;
+    return value;
+  },
+  setDefaultSearchField: function(value) {
+    this.defaultSearchField = value;
+    return value;
+  },
+
   get options() {
     var options = [];
     if (this.searchEnabled) options.push('Search');
@@ -286,6 +301,11 @@ IndexField.prototype = {
     if (this._searchEnabled !== undefined)
       this.domain.setConfiguration(this.searchEnabledConfigurationKey,
                                    this._searchEnabled);
+
+    if (this._defaultSearchField !== undefined) {
+      delete this._defaultSearchField;
+      this.domain.defaultSearchField = this;
+    }
   },
   deleteSync: function() {
     // backup information for re-creation
@@ -293,6 +313,7 @@ IndexField.prototype = {
     this._facetEnabled = this.facetEnabled;
     this._resultEnabled = this.resultEnabled;
     this._searchEnabled = this.searchEnabled;
+    this._defaultSearchField = this.defaultSearchField;
 
     if (this._type == 'uint' || this._type == 'literal') {
       this.context.commandSync('table_remove', {
@@ -307,6 +328,8 @@ IndexField.prototype = {
     this.domain.deleteConfiguration(this.facetEnabledConfigurationKey);
     this.domain.deleteConfiguration(this.resultEnabledConfigurationKey);
     this.domain.deleteConfiguration(this.searchEnabledConfigurationKey);
+    if (this._defaultSearchField)
+      this.domain.defaultSearchField = null;
   },
   reindexSync: function() {
     var name = this.name;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index