Skip to content

Commit c066d0a

Browse files
authored
Merge pull request #31 from microsoft/eleretzk/fulltext/plumb-limit
Plumb limit to full text search function
2 parents c090d2a + 72b02c0 commit c066d0a

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/objectstoreprovider",
3-
"version": "0.6.35",
3+
"version": "0.6.36",
44
"description": "A cross-browser object store library",
55
"author": "Mukundan Kavanur Kidambi <[email protected]>",
66
"scripts": {

src/ObjectStoreProvider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ export abstract class DbProvider {
397397
indexName: string,
398398
searchPhrase: string,
399399
resolution: FullTextTermResolution = FullTextTermResolution.And,
400-
_limit?: number
400+
limit?: number
401401
): Promise<ItemType[]> {
402402
return this._getStoreIndexTransaction(storeName, false, indexName).then(
403403
(index) => {
404-
return index.fullTextSearch(searchPhrase, resolution);
404+
return index.fullTextSearch(searchPhrase, resolution, limit);
405405
}
406406
);
407407
}

src/tests/ObjectStoreProvider.spec.ts

+77-1
Original file line numberDiff line numberDiff line change
@@ -4519,7 +4519,7 @@ describe("ObjectStoreProvider", function () {
45194519
});
45204520
}
45214521

4522-
it("Full Text Index", (done) => {
4522+
it("Full Text Index - Happy path", (done) => {
45234523
openProvider(
45244524
provName,
45254525
{
@@ -4879,6 +4879,82 @@ describe("ObjectStoreProvider", function () {
48794879
(err) => done(err)
48804880
);
48814881
});
4882+
4883+
it("Full Text Index - Returns only the limit passed for OR resolution", async () => {
4884+
return openProvider(
4885+
provName,
4886+
{
4887+
version: 2,
4888+
stores: [
4889+
{
4890+
name: "test",
4891+
primaryKeyPath: "id",
4892+
indexes: [
4893+
{
4894+
name: "i",
4895+
keyPath: "txt",
4896+
fullText: true,
4897+
unique: false,
4898+
},
4899+
],
4900+
},
4901+
],
4902+
},
4903+
true
4904+
).then((prov) => {
4905+
const itemsToPut = [];
4906+
for (var i = 0; i < 100; i++) {
4907+
itemsToPut.push({ id: `a${i}`, txt: `aaaaaa${i}` });
4908+
}
4909+
4910+
prov.put("test", itemsToPut).then(() => {
4911+
prov
4912+
.fullTextSearch("test", "i", "a", FullTextTermResolution.Or, 10)
4913+
.then((results) => {
4914+
assert.equal(results.length, 10);
4915+
prov.close();
4916+
});
4917+
});
4918+
});
4919+
});
4920+
4921+
it("Full Text Index - Returns only the limit passed for AND resolution", async () => {
4922+
return openProvider(
4923+
provName,
4924+
{
4925+
version: 2,
4926+
stores: [
4927+
{
4928+
name: "test",
4929+
primaryKeyPath: "id",
4930+
indexes: [
4931+
{
4932+
name: "i",
4933+
keyPath: "txt",
4934+
fullText: true,
4935+
unique: false,
4936+
},
4937+
],
4938+
},
4939+
],
4940+
},
4941+
true
4942+
).then((prov) => {
4943+
const itemsToPut = [];
4944+
for (var i = 0; i < 100; i++) {
4945+
itemsToPut.push({ id: `a${i}`, txt: `aaaaaa${i}` });
4946+
}
4947+
4948+
prov.put("test", itemsToPut).then(() => {
4949+
prov
4950+
.fullTextSearch("test", "i", "a", FullTextTermResolution.And, 10)
4951+
.then((results) => {
4952+
assert.equal(results.length, 10);
4953+
prov.close();
4954+
});
4955+
});
4956+
});
4957+
});
48824958
});
48834959
});
48844960
});

0 commit comments

Comments
 (0)