JKHeadley / JKHeadley/rest-hapi

[Question] I'm having trouble using $text or $term

Open
#237 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.2k
Forks
155
PR merge metrics
No merged PRs in 30d

Description

I'm trying to implement "free text search with autocomplete" on my front end using `$text` or `$term` while having a "custom default" query in a list pre middleware and cant get it to work as expected.

Could also be that I'm missing something.

I'm setting this in my list pre middleware
``` javascript
query = {
...query,
isDeleted: { $ne: true },
$where: {
$or: [
{
objects: {
_id: {
$in: user.company.objects.map(o => o._id)
}
}
},
{ createdBy: user._id },
{ company: user.company },
]
}
};
```

When I'm using `$text` I have to sent a word that matches one word -1 letter to return any matching data.
Example `$text=Awesom` will return
``` text
Awesome Frozen Sausages
Awesome Concrete Bacon
Awesome Fresh Tuna
```
Example `$text=Aweso` will return nothing.
The data return matches my "default query" as `$text AND "myDefault"`

Next if i use `$term` data is returned even if I use `$term=A` witch is more of a result I'm after.
The only problem is that it totally ignores my "default query" using it as `$term OR "myDefault"`
This is a big problem for me do to a user aren't allowed to see data that aren't "connected" to a user...

I'm i missing something here?
I have tried turning on and of `config.enableTextSearch` but it doesn't seem to do any difference.

Contributor guide

Open the contributing guide

Research direction

Start at the list pre middleware and the query handling for `$text` and `$term`; reproduce the examples using the `enableTextSearch` configuration. Determine how the default visibility query is combined with each search operator, and document or correct the behavior so results remain limited to connected users.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
api, authorization, backend, search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.