Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/fix 494 #495

Merged
merged 3 commits into from
Sep 26, 2023
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
19 changes: 12 additions & 7 deletions packages/orama/src/methods/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,25 @@ export async function search<T extends AnyOrama, ResultDocument = TypedDocument<

const tokensLength = tokens.length

if (tokensLength) {
if (tokensLength || (properties && properties.length > 0)) {
// Now it's time to loop over all the indices and get the documents IDs for every single term
const indexesLength = propertiesToSearch.length
for (let i = 0; i < indexesLength; i++) {
const prop = propertiesToSearch[i]

const tokensLength = tokens.length
for (let j = 0; j < tokensLength; j++) {
const term = tokens[j]
if (tokensLength !== 0) {
for (let j = 0; j < tokensLength; j++) {
const term = tokens[j]

// Lookup
const scoreList = await orama.index.search(context, index, prop, term)
// Lookup
const scoreList = await orama.index.search(context, index, prop, term)

safeArrayPush(context.indexMap[prop][term], scoreList);
safeArrayPush(context.indexMap[prop][term], scoreList);
}
} else {
context.indexMap[prop][''] = []
const scoreList = await orama.index.search(context, index, prop, '')
safeArrayPush(context.indexMap[prop][''], scoreList);
}

const docIds = context.indexMap[prop]
Expand Down
26 changes: 26 additions & 0 deletions packages/orama/tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,32 @@ t.test('search method', t => {
t.end()
})

t.test('should return all the documents that contains the property on empty search', async t => {
const db = await create({
schema: {
animal: 'string',
}
})

await insertMultiple(db, [
{ animal: 'foo' },
{ },
{ },
{ },
{ },
{ },
])

const result = await search(db, {
term: '',
properties: ['animal']
})

t.equal(result.count, 1)

t.end()
})

t.end()
})

Expand Down