-
Notifications
You must be signed in to change notification settings - Fork 31
/
RavenDB_5669.ts
103 lines (82 loc) · 2.82 KB
/
RavenDB_5669.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import * as assert from "assert";
import { testContext, disposeTestDocumentStore } from "../../Utils/TestUtil";
import {
IDocumentStore,
} from "../../../src";
import { AbstractJavaScriptIndexCreationTask } from "../../../src/Documents/Indexes/AbstractJavaScriptIndexCreationTask";
describe("Issue RavenDB-5669", function () {
let store: IDocumentStore;
let index;
beforeEach(async function () {
index = new Animal_Index();
store = await testContext.getDocumentStore();
await store.executeIndex(index);
await storeAnimals(store);
});
afterEach(async () =>
await disposeTestDocumentStore(store));
it("working with different search term order", async () => {
const session = store.openSession();
const query = session.query(Animal, Animal_Index);
query.openSubclause()
.whereEquals("type", "Cat")
.orElse()
.search("name", "Peter*")
.andAlso()
.search("name", "Pan*")
.closeSubclause();
const results = await query.all();
assert.strictEqual(results.length, 1);
});
it("working with subclause", async () => {
const session = store.openSession();
const query = session.query(Animal, Animal_Index);
query.openSubclause()
.whereEquals("type", "Cat")
.orElse()
.openSubclause()
.search("name", "Peter*")
.andAlso()
.search("name", "Pan*")
.closeSubclause()
.closeSubclause();
const results = await query.all();
assert.strictEqual(results.length, 1);
});
});
async function storeAnimals(store: IDocumentStore) {
{
const session = store.openSession();
const animal1 = new Animal();
animal1.name = "Peter Pan";
animal1.type = "Dog";
const animal2 = new Animal();
animal2.name = "Peter Poo";
animal2.type = "Dog";
const animal3 = new Animal();
animal3.name = "Peter Foo";
animal3.type = "Dog";
await session.store(animal1);
await session.store(animal2);
await session.store(animal3);
await session.saveChanges();
}
await testContext.waitForIndexing(store, store.database);
}
class Animal {
public type: string;
public name: string;
}
class Animal_Index extends AbstractJavaScriptIndexCreationTask<Animal, Pick<Animal, "name" | "type">> {
public constructor() {
super();
this.map(Animal, a => {
return {
name: a.name,
type: a.type
}
});
this.analyze("name", "StandardAnalyzer");
this.index("name", "Search");
}
}