1.0.2 • Published 2 years ago

@noowah/ch-search-service v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

ch-search-service SDK

Getting started

❗️User must have access to ch-search-sevice to work with this SDK flexibly due to following reasons

  • ✅ check index fiends
  • ✅ CORS information
  • ✅ private service values such as key and endpoint

Installation

npm install @noowah/ch-search-service
yarn add @noowah/ch-search-service

User guide

azsearch(SearchServiceConfig)

const azsearch: Promise<{ results: SearchResults; totalCount: number }>;

returned value:

  • results : SearchReuslts
type SearchResults = (
  | HospitalDocument
  | DoctorDocument
  | DealDocument
  | SpecialtyDocument
  | DepartmentDocument
  | HospitalSpecialtyDocument
  | ArticleDocument
  | ServiceDocument
  | ContributorDocument
  | CountryDocument
  | FaqDocument
  | FaqCategoryDocument
)[];
  • totalCount : number

SearchServiceConfig

ParamTypeDesctiption
idxstring (required)use enum Idx ( "hospitals" | "doctors" | "deals")
stagestring (required)"dev" | "int" | "prd"
az_search_keystring (required)Azure search service key (contact CH team)
az_search_endpointstring (optional)Azure search service endpoint
optionsObject(required)use interface SearchOption

SearchOption

ParamTypeDesctiption
searchTermstring (required)search keyword
filtersSearchFilterOption (optional){[propertyName: string]: string[]}
pagenumber (optional)default :1
limitnumber (optional)default :null
selectArray<string> (optional)select specific retrievable fields
queryTypeQueryType (optional)"simple" (default) | "full"
searchFieldsArray<string>(optional)selecct specificsearchable fields
searchModestring (optional)"any"(default) | "all"

example:

const searchOption: SearchOption = {
  searchTerm: `${searchTerm}~`,
  limit: 20,
};

const fetchData = async () => {
  const config: SearchServiceConfig = {
    idx: Idx.hospitals,
    stage: "int",
    az_search_endpoint: NEXT_PUBLIC_AZ_SEARCH_ENDPOINT,
    az_search_key: NEXT_PUBLIC_AZ_SEARCH_KEY,
    options: searchOption,
  };
  const { results, totalCount } = await azsearch(config);

  const castedResult = results as HospitalDocument;
};

SearchFilterOption

interface SearchFilterOption {
  [propertyName: string]: string[];
}
  • Set filterable fields as keys

    ❗️ Refer to the indexes on ch-search-service (only accessible by CH dev team)

example:

   'Translations/IsConfirmed': ['true']