Navigation Menu

Skip to content

Commit

Permalink
Implement backend of index field options
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 13, 2012
1 parent 098a03c commit 83dfe72
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 12 deletions.
85 changes: 79 additions & 6 deletions lib/database/index-field.js
Expand Up @@ -134,7 +134,6 @@ IndexField.prototype = {
set type(type) {
return this._type = type
},

setType: function(type) {
this.type = type;
return this;
Expand All @@ -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() {
Expand Down Expand Up @@ -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
});
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions test/database-index-field.test.js
Expand Up @@ -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'
Expand All @@ -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',
Expand All @@ -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'
});
Expand Down

0 comments on commit 83dfe72

Please sign in to comment.