Skip to content

Commit 6bf2297

Browse files
committed
feat(FilteredBooleanQuery): must_not
1 parent 4fd284f commit 6bf2297

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

layout/FilteredBooleanQuery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Layout(){
66
}
77

88
Layout.prototype.score = function( view, operator ){
9-
this._score.push([ view, operator === 'must' ? 'must': 'should' ]);
9+
this._score.push([ view, ( operator === 'must' || operator === 'must_not' ) ? operator: 'should' ]);
1010
return this;
1111
};
1212

@@ -23,7 +23,7 @@ Layout.prototype.sort = function( view ){
2323
Layout.prototype.render = function( vs ){
2424
var q = Layout.base( vs );
2525

26-
// handle scoring views under 'query' section (both 'must' & 'should')
26+
// handle scoring views under 'query' section (for 'must', 'must_not' & 'should')
2727
if( this._score.length ){
2828
this._score.forEach( function( condition ){
2929
var view = condition[0], operator = condition[1];

test/layout/FilteredBooleanQuery.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,23 @@ module.exports.tests.scores = function(test, common) {
5151
return { 'score field 4': 'score value 4' };
5252
};
5353

54+
var score_view5 = function(vs) {
55+
console.assert(vs !== null);
56+
return { 'score field 5': 'score value 5' };
57+
};
58+
59+
var score_view6 = function(vs) {
60+
console.assert(vs !== null);
61+
return { 'score field 6': 'score value 6' };
62+
};
63+
5464
var query = new FilteredBooleanQuery();
5565
query.score(score_view1, 'must');
5666
query.score(score_view2, 'should');
57-
query.score(score_view3, 'must');
58-
query.score(score_view4, 'should');
67+
query.score(score_view3, 'must_not');
68+
query.score(score_view4, 'must');
69+
query.score(score_view5, 'should');
70+
query.score(score_view6, 'must_not');
5971

6072
var vs = new VariableStore();
6173
vs.var('size', 'size value');
@@ -68,12 +80,16 @@ module.exports.tests.scores = function(test, common) {
6880
bool: {
6981
must: [
7082
{ 'score field 1': 'score value 1'},
71-
{ 'score field 3': 'score value 3'}
83+
{ 'score field 4': 'score value 4'}
7284
],
7385
should: [
7486
{ 'score field 2': 'score value 2'},
75-
{ 'score field 4': 'score value 4'}
76-
]
87+
{ 'score field 5': 'score value 5'}
88+
],
89+
must_not: [
90+
{ 'score field 3': 'score value 3'},
91+
{ 'score field 6': 'score value 6'}
92+
],
7793
}
7894
},
7995
size: { $: 'size value' },
@@ -119,7 +135,7 @@ module.exports.tests.scores = function(test, common) {
119135

120136
});
121137

122-
test('score with non-must or -should operator specified should be added as \'should\'', function(t) {
138+
test('score with non-must or -must_not or -should operator specified should be added as \'should\'', function(t) {
123139
var score_view = function(vs) {
124140
console.assert(vs !== null);
125141
return { 'score field': 'score value' };

0 commit comments

Comments
 (0)