@asymmetrik/elastic-querybuilder
Advanced tools
Comparing version 0.9.10 to 0.9.11
@@ -58,3 +58,3 @@ const QueryBuilder = require('../src/index'); | ||
const trackScores = true; | ||
// Set the stractScore | ||
// Set the trackScore | ||
builder.trackScores(trackScores); | ||
@@ -67,3 +67,34 @@ expect(builder._query.track_scores).toEqual(trackScores); | ||
describe('clone', () => { | ||
test('should be able to clone the builder', () => { | ||
const builder = new QueryBuilder(); | ||
const clone = builder.clone(); | ||
expect(clone).toBeInstanceOf(QueryBuilder); | ||
expect(clone).not.toBe(builder); | ||
}); | ||
test('should have the same output on the original and clone but not be the same object', () => { | ||
const builder = new QueryBuilder() | ||
.should('match', 'alias', 'Mysterion') | ||
.from(15) | ||
.size(15); | ||
const clone = builder.clone(); | ||
expect(clone.build()).toEqual(builder.build()); | ||
}); | ||
test('should be able to modify them separately after cloning them', () => { | ||
const builder = new QueryBuilder().from(15).size(15); | ||
const clone = builder.clone(); | ||
expect(clone).not.toBe(builder); | ||
expect(clone.build()).toEqual(builder.build()); | ||
builder.should('match', 'alias', 'Mysterion'); | ||
expect(clone.build()).not.toEqual(builder.build()); | ||
}); | ||
}); | ||
describe('build', () => { | ||
@@ -70,0 +101,0 @@ |
{ | ||
"name": "@asymmetrik/elastic-querybuilder", | ||
"version": "0.9.10", | ||
"version": "0.9.11", | ||
"description": "A query builder for Elasticsearch.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -70,2 +70,13 @@ const BaseBuilder = require('./BaseBuilder'); | ||
/** | ||
* @description Clone the current builder | ||
* @return {QueryBuilder} this | ||
*/ | ||
clone () { | ||
return Object.assign( | ||
Object.create(Object.getPrototypeOf(this)), | ||
JSON.parse(JSON.stringify(this)) | ||
); | ||
} | ||
/** | ||
* @description Build our boolean ES query | ||
@@ -72,0 +83,0 @@ * @param {Object} options |
160160
2211