Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions packages/search/lib/commands/SEARCH.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,84 @@ describe('FT.SEARCH', () => {
}
);
}, GLOBAL.SERVERS.OPEN);

testUtils.testWithClient('properly parse content/nocontent scenarios', async client => {

const indexName = 'foo';
await client.ft.create(
indexName,
{
itemOrder: {
type: 'NUMERIC',
SORTABLE: true,
},
name: {
type: 'TEXT',
},
},
{
ON: 'HASH',
PREFIX: 'item:',
}
);

await client.hSet("item:1", {
itemOrder: 1,
name: "First item",
});

await client.hSet("item:2", {
itemOrder: 2,
name: "Second item",
});

await client.hSet("item:3", {
itemOrder: 3,
name: "Third item",
});

// Search with SORTBY and LIMIT
let result = await client.ft.search(indexName, "@itemOrder:[0 10]", {
SORTBY: {
BY: "itemOrder",
DIRECTION: "ASC",
},
LIMIT: {
from: 0,
size: 1, // only get first result
},
});

assert.equal(result.total, 3, "Result's `total` value reflects the total scanned documents");
assert.equal(result.documents.length, 1);
let doc = result.documents[0];
assert.equal(doc.id, 'item:1');
assert.equal(doc.value.itemOrder, '1');
assert.equal(doc.value.name, 'First item');

await client.del("item:3");

// Search again after removing item:3
result = await client.ft.search(indexName, "@itemOrder:[0 10]", {
SORTBY: {
BY: "itemOrder",
DIRECTION: "ASC",
},
LIMIT: {
from: 0,
size: 1, // only get first result
},
});

assert.equal(result.total, 2, "Result's `total` value reflects the total scanned documents");
assert.equal(result.documents.length, 1);
doc = result.documents[0];
assert.equal(doc.id, 'item:1');
assert.equal(doc.value.itemOrder, '1');
assert.equal(doc.value.name, 'First item');


}, GLOBAL.SERVERS.OPEN);

});
});
3 changes: 2 additions & 1 deletion packages/search/lib/commands/SEARCH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export default {
},
transformReply: {
2: (reply: SearchRawReply): SearchReply => {
const withoutDocuments = (reply[0] + 1 == reply.length)
// if reply[2] is array, then we have content/documents. Otherwise, only ids
const withoutDocuments = reply.length > 2 && !Array.isArray(reply[2]);

const documents = [];
let i = 1;
Expand Down
Loading