Skip to content

Commit 829aa08

Browse files
authored
Merge pull request #75 from weaviate/add-autocut-support
Add support for autocut
2 parents e8dacab + bdffc92 commit 829aa08

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/graphql/getter.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ test('a simple query with a group', () => {
7575
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
7676
});
7777

78+
test('a simple query with autocut', () => {
79+
const mockClient: any = {
80+
query: jest.fn(),
81+
};
82+
83+
const expectedQuery = `{Get{Person(where:{operator:Equal,valueText:"hawaii",path:["name"]},autocut:10){name}}}`;
84+
85+
new Getter(mockClient)
86+
.withClassName('Person')
87+
.withAutocut(10)
88+
.withWhere({
89+
operator: 'Equal',
90+
valueText: 'hawaii',
91+
path: ['name'],
92+
})
93+
.withFields('name')
94+
.do();
95+
96+
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
97+
});
98+
7899
describe('query with consistency level', () => {
79100
test('One', () => {
80101
const mockClient: any = {

src/graphql/getter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class GraphQLGetter extends CommandBase {
3737
private consistencyLevel?: ConsistencyLevel;
3838
private groupByString?: string;
3939
private tenant?: string;
40+
private autocut?: number;
4041

4142
constructor(client: Connection) {
4243
super(client);
@@ -172,6 +173,11 @@ export default class GraphQLGetter extends CommandBase {
172173
return this;
173174
};
174175

176+
withAutocut = (autocut: number) => {
177+
this.autocut = autocut;
178+
return this;
179+
};
180+
175181
withSort = (args: SortArgs[]) => {
176182
this.sortString = new Sort(args).toString();
177183
return this;
@@ -265,6 +271,10 @@ export default class GraphQLGetter extends CommandBase {
265271
args = [...args, `offset:${this.offset}`];
266272
}
267273

274+
if (this.autocut) {
275+
args = [...args, `autocut:${this.autocut}`];
276+
}
277+
268278
if (this.sortString) {
269279
args = [...args, `sort:[${this.sortString}]`];
270280
}

src/graphql/journey.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,22 @@ describe('the graphql journey', () => {
311311
});
312312
});
313313

314+
test('graphql get nearText with autocut', () => {
315+
return client.graphql
316+
.get()
317+
.withClassName('Article')
318+
.withNearText({ concepts: ['Article'] })
319+
.withAutocut(3)
320+
.withFields('_additional { id }')
321+
.do()
322+
.then((res: any) => {
323+
expect(res.data.Get.Article.length).toBe(3);
324+
})
325+
.catch((e: any) => {
326+
throw new Error('it should not have errord' + e);
327+
});
328+
});
329+
314330
test('graphql get hybrid with query (no vector, alpha 0)', () => {
315331
return client.graphql
316332
.get()

0 commit comments

Comments
 (0)