private query()

in src/api/catalog-search/catalog-search.ts [200:230]


  private query(query: string): CatalogSearchResults {
    let refs: lunr.Index.Result[] = [];

    try {
      let tokenizedQuery = lunr.tokenizer(query);

      if (tokenizedQuery.length > 1) {
        // A large number of libraries include the term cdk within the title - which will lead to an
        // inflated result count. TODO: determine if there are other terms to filter out
        tokenizedQuery = tokenizedQuery.filter(
          (token) => token.toString() !== "cdk"
        );
      }

      refs = this.index.query((q) => {
        q.term(tokenizedQuery, {});
      });
    } catch (e) {
      console.error(e);
    }

    return refs.reduce((packages, { ref }) => {
      const pkg = this.map.get(ref);

      if (pkg) {
        packages.set(ref, pkg);
      }

      return packages;
    }, new Map() as CatalogSearchResults);
  }