Skip to content

Commit

Permalink
Feat/fix 494 (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
allevo authored Sep 26, 2023
1 parent a43ca35 commit bcb63da
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
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

1 comment on commit bcb63da

@vercel
Copy link

@vercel vercel bot commented on bcb63da Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.