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: Provide optional to exclude "private" fields from wildcard searches to improve usability #42

Merged
merged 5 commits into from
Dec 15, 2024
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ filter($q('age:[0 TO 80]'), data);
filter($q('gender:*ale OR age:>55'), data);
```

#### Private Fields

In certain scenarios, you may want to exclude specific fields from being matched unless explicitly specified. For example, without additional configuration, a query like `luxury` would match both the `name` and `description` fields:

```typescript
const data = [
{ id: 2, name: 'Luxury Car Model AC', description: 'Car Model AC stands out with its unique features.', age: 15 },
{ id: 3, name: 'Car Model AD', description: 'Experience the luxury of Car Model AD.', age: 30 },
];
```

This package provides a method to ignore private fields by prefixing their names with an underscore and enabling the feature over a config. Private fields are excluded from wildcard matches but can still be explicitly queried when needed.

```typescript
const data = [
{ id: 2, name: 'Luxury Car Model AC', _description: 'Car Model AC stands out with its unique features.', age: 15 },
{ id: 3, name: 'Car Model AD', _description: 'Experience the luxury of Car Model AD.', age: 30 },
];

const $q = (q) => new QueryParser(q);

filter($q('luxury'), data, {..., featureEnablePrivateField: true});
filter($q('description:luxury'), data, {..., featureEnablePrivateField: true});
```

In this example, a generic query like `luxury` would only match the `name` field. However, if you need to target the private field, you can do so explicitly, such as with `description:luxury`.

### Serializer Usage

```typescript
Expand Down Expand Up @@ -394,6 +421,7 @@ The following Lucene features are not currently supported but may be added in th
The following filters are not yet supported:

- ~~Iterating over Array Object key without index like (e.g., `field.key_in_array`, working `field.*.key_in_array`)~~ (Supported since v1.1.0)
- The private field feature doesn't work for trailing queries (e.g. `field.private*`)

## Contributing

Expand Down
Loading
Loading