Navigation Menu

Skip to content

Commit

Permalink
Add Domain#facetReturnableIndexFields, Domain#resultReturnableIndexFi…
Browse files Browse the repository at this point in the history
…elds, Domain#searchableIndexFields
  • Loading branch information
piroor committed Aug 22, 2012
1 parent 9f3c11c commit 061928e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/database/domain.js
Expand Up @@ -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);
Expand Down
83 changes: 83 additions & 0 deletions test/database-domain.test.js
Expand Up @@ -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);
Expand Down

0 comments on commit 061928e

Please sign in to comment.