1.0.9 • Published 6 years ago

@dgmip/firestore-searchable-index v1.0.9

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
6 years ago

Firestore Searchable Indexc

Create searchable indices in firestore from a string or string[]

Installation

npm i --save @dgmip/firestore-searchable-index

Use

import * as searchableIndex from "@dgmip/firestore-searchable-index";

mySearchableIndex = searchableIndex.firestoreSearchableIndex;

// create and index on a string
const index = searchableIndex.create("Ben Wall");
// create and index on an array
const index = searchableIndex.create(["Ben Wall", "Peter Williams"]);

Example search using @angular/fire

offset = new Subject<string>() // your search term subject
results$: Observable<any[]>

contructor() {
  this.results$ = this.search()
}

search() {
  return this.offset.pipe(
    filter(val => !!val), // filter empty strings
    switchMap(offset => {
      return this.afs.collection('names', ref =>
        ref.orderBy(`searchableIndex.${ offset }`)
      )
        .snapshotChanges().pipe(
          map(actions => {
            const results = []
            actions.forEach(action => {
              const id = action.payload.doc.id
              const data = action.payload.doc.data()
              results.push({ id, data })
            })
            return results
          })
        )
    })
  )
}

// fire off a search for 'ben'
fireSearch() {
  this.offset.next('ben')
}
1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago