https://github.com/nextcloud-libraries/search
Unified search helpers for Nextcloud apps and libraries
https://github.com/nextcloud-libraries/search
Last synced: 3 months ago
JSON representation
Unified search helpers for Nextcloud apps and libraries
- Host: GitHub
- URL: https://github.com/nextcloud-libraries/search
- Owner: nextcloud-libraries
- License: gpl-3.0
- Created: 2024-07-28T12:24:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-28T12:24:06.000Z (over 1 year ago)
- Last Synced: 2024-10-31T22:52:06.824Z (over 1 year ago)
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @nextcloud/search
Unified search helpers for Nextcloud apps and libraries.
## Installation
```bash
npm install @nextcloud/search
```
## Usage
### FilterBuilder
Build search filters with a fluent API:
```typescript
import { FilterBuilder } from '@nextcloud/search'
const filters = new FilterBuilder()
.term('quarterly report')
.thisMonth()
.user('admin')
.build()
// Serialize for API requests
const params = filters.toQueryParams()
// { term: 'quarterly report', since: '2025-01-01T...', until: '2025-01-31T...', person: 'user:admin' }
```
### Date Range Helpers
```typescript
const filters = new FilterBuilder()
.term('meeting notes')
.today() // From start of today
// .thisWeek() // From start of current week (Monday)
// .thisMonth() // From start of current month
// .thisYear() // From start of current year
// .lastDays(7) // Last 7 days
// .dateRange({ since: new Date('2025-01-01'), until: new Date('2025-06-30') })
.build()
```
### FilterCollection
Work with immutable filter collections:
```typescript
import { FilterCollection } from '@nextcloud/search'
// Parse from URL query parameters
const definitions = new Map([
['term', { type: 'string' }],
['since', { type: 'datetime' }],
['person', { type: 'person' }],
])
const collection = FilterCollection.fromQueryParams(
{ term: 'report', since: '2025-01-01T00:00:00.000Z' },
definitions
)
// Access typed values
const term = collection.getTerm() // 'report'
const dateRange = collection.getDateRange() // { since: Date, until?: Date }
const person = collection.getPerson() // { type: 'user', id: 'admin' } | null
// Immutable updates
const updated = collection
.with('person', { name: 'person', type: 'person', value: { type: 'user', id: 'alice' } })
.without('since')
```
### Types
```typescript
import type {
Filter,
FilterDefinition,
DateRange,
PersonValue,
SearchQuery,
SearchResultEntry,
ProviderInfo,
} from '@nextcloud/search'
```
## Development
```bash
npm install
npm test
npm run build
```
## License
AGPL-3.0-or-later