npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teclead/search-module

v1.0.24

Published

An NPM module for the Teclead Search Service which can be used for Adobe AEM or other Content Management Systems.

Downloads

3

Readme

Adobe AEM Search as a MicroService

This Typescript module can be used to implement a very fast light weight search for Adobe AEM or ther Content Management Systems like First Spirit, Sitecore or LifeRay.

Example Implementation for a simple Adobe AEM search

The Abstract Search needs to be implemented by a custom class. This is an example for a simple AEM page search.

import { AbstractSearchService } from "@teclead/search-module/AbstractSearch.service";
import {
  AEMTypes,
  CommonSearchModel,
  SearchRankModel,
} from "@teclead/search-module/models";

interface PageSearchModel extends CommonSearchModel {
  path: string;
  name: string;
  content: ContentModel;
}
interface ContentModel {
  productName: string;
  description: string;
}
const pageContentKeys: PageContentKeys[] = [
  { key: "productName" },
  { key: "description", manipulation: cleanUp },
];
// to clean up unwanted data, method will be executed if injected
const cleanUp = (value: string): string => {
  return value.replace("I dont want this", "I love it");
};

export class CustomSearchService extends AbstractSearchService {
  // for multiple instances a delay can be created if instanceNumber > 0 => instanceNumber * instanceDelay = delayTime
  instanceNumber = 0;
  //delay time in minutes
  instanceDelay = 1;
  //enableCacheTrigger allows you to manually trigger cache if set to true under ${apiPath}/updateCache
  enableCacheTrigger = false;

  async setUpCallbacksBefore() {
    await this.getServerData();
  }

  async setUpCallbacksAfter() {}

  public getRawDataElement(child: any): PageSearchModel {
    const content: ContentModel = this.getFilteredContent(
      child,
      pageContentKeys
    );
    const transformed = { ...child };
    return { path: transformed.path, name: transformed.name, content };
  }

  public getSearchCriteria(searchModel: PageSearchModel): SearchRankModel[] {
    return [
      {
        searchElement: searchModel.name,
        rank: 3,
      },
      {
        searchElement: searchModel.content.productName,
        rank: 2,
      },
      {
        searchElement: searchModel.content.description,
        rank: 1,
      },
    ];
  }

  // multiple servers can be configured here in order to have loadbalancing in place
  public getSearchUrl(): string[] | string {
    let aemServerUrls: string[] = [
      "http://localhost:4502",
      "http://localhost:4502",
    ];
    const path = "/content/brand/sub-brand/my-aem-brand-page";
    aemServerUrls = aemServerUrls.map(
      (url: string) =>
        `${url}/bin/company/asset-service.json?path=${path}&type=${AEMTypes.Page}`
    );
    return aemServerUrls;
  }

  // for security purposes headers can be injected into the fetch request
  public getSearchUrlRequestInits(): RequestInit {
    const headers = new Headers();
    headers.append("Authkey", `${btoa(envVar.authKey)}`);
    return {
      method: "GET",
      headers: headers,
    };
  }
}

Using the CustomSearch

The constructor takes multiple arguments:

  • name of the service for logging
  • an optional default API path
  • an optional express object
  • a number in minutes to update the cache

API's

- ${apiPath}?search=**searchWord** => returns search results
- ${apiPath}/updateCache => trigger cache manually if enableCacheTrigger is true
- ${apiPath}/synonyms?word=**searchSynonym** => get an array of arrays of synonyms for the word you are looking for
new CustomSearchService({
  serviceName: "Custom Search Service",
  express: { apiPath: "/api/v1/search", app },
  cacheTime: 5,
});

Response

An example response from the implemented custom Search with Adobe AEM Pages for the term auto.

// 20200103180457
// http://localhost:8082/api/v1/brandname-pages?search=auto
{
    "search": "auto,automobil,fahrbarer untersatz,pkw,personenwagen,personenkraftwagen,motorwagen,blechbüchse,wagen",
    "foundItems": 21,
    "results": [
        {
            "path": "/content/brandname/de/Produkte/KFZ-Versicherung/Autoversicherung",
            "name": "Autoversicherung from Brandname",
            "content": {
               "productName": "Autoversicherung",
               "description": "This is the page description."
            },
            "searchRank": 3
        },
        {...}
    ]
}