Options
All
  • Public
  • Public/Protected
  • All
Menu

This is the "main class" of this package. Please read the getting-started section" for a proper introduction.

The SearchClient manages a range of other services:

  • Authentication,
  • Autocomplete,
  • Categorize
  • Find

Each of the above services can be used independently, but it is highly recommended to use the SearchClient instead.

The SearchClient allows you to have an advanced search with minimal effort in regards to setup and logics. instead of having to write all the logics yourself the SearchClient exposes the following methods for managing your search:

  1. Configure callbacks in your settings-object that you pass to the SearchClient.
  2. Configure triggers to define when to do server-lookups and not (if you need to deviate from the defaults)
  3. Set query-values real-time (queryText, filters, date-ranges, etc.)
  4. Receive autocomplete-suggestions, matches and categories in your callback handlers when the data is available.

What happens is that any query-changes that arrive are checked in regards to trigger-settings. If they are to trigger and a callback has been set up then the server is requested and when the data is received it is sent to the callback registered in the settings-object.

Hierarchy

  • SearchClient

Implements

Index

Constructors

constructor

  • new SearchClient(settings: string | ISettings, fetchMethod?: (input: RequestInfo, init?: RequestInit) => Promise<Response>): SearchClient
  • Creates a SearchClient instance using the supplied settings object. Please see getting-started section for an introduction on how to set up the instance.

    Parameters

    • settings: string | ISettings

      A settings object that indicates how the search-client instance is to behave.

    • Optional fetchMethod: (input: RequestInfo, init?: RequestInit) => Promise<Response>
        • (input: RequestInfo, init?: RequestInit): Promise<Response>
        • Parameters

          • input: RequestInfo
          • Optional init: RequestInit

          Returns Promise<Response>

    Returns SearchClient

Properties

authentication

authentication: IAuthentication = ...

Holds a reference to the setup Authentication service.

autocomplete

autocomplete: Autocomplete = ...

Holds a reference to the setup Autocomplete service.

categorize

categorize: Categorize = ...

Holds a reference to the setup Categorize service.

find

find: Find = ...

Holds a reference to the setup Find service.

tokenResolver

tokenResolver: () => string

Holds a reference to method resolving jwt access token.

Type declaration

    • (): string
    • Returns string

Accessors

authenticationToken

  • get authenticationToken(): string
  • Holds a reference to the currently set authentication token.

    Returns string

categorizationType

  • Gets the currently active categorizationType value.

    Returns CategorizationType

  • Sets the currently active categorizationType.

    Will run trigger-checks and potentially update services.

    Parameters

    Returns void

clientId

  • get clientId(): string
  • set clientId(clientId: string): void
  • Gets the currently active client-id value.

    Returns string

  • Sets the currently active client-id.

    Will run trigger-checks and potentially update services.

    Parameters

    • clientId: string

    Returns void

dateFrom

  • Gets the currently active date-from value.

    Returns DateSpecification

  • Sets the from-date for matches to be used.

    Will run trigger-checks and potentially update services.

    Parameters

    Returns void

dateTo

  • Gets the currently active date-to value.

    Returns DateSpecification

  • Sets the to-date for matches to be used.

    Will run trigger-checks and potentially update services.

    Parameters

    Returns void

filters

  • get filters(): Filter[]
  • set filters(filters: Filter[]): void
  • Gets the currently active filters.

    Returns Filter[]

  • Sets the filters to be used.

    Will run trigger-checks and potentially update services.

    Parameters

    Returns void

matchGenerateContent

  • get matchGenerateContent(): boolean
  • set matchGenerateContent(generateContent: boolean): void
  • Gets the currently active match generateContent setting.

    Returns boolean

  • Sets whether the results should generate the content or not.

    Note: Requires the backend IndexManager to have the option enabled in its configuration too.

    Will run trigger-checks and potentially update services.

    Parameters

    • generateContent: boolean

    Returns void

matchGenerateContentHighlights

  • get matchGenerateContentHighlights(): boolean
  • set matchGenerateContentHighlights(generateContentHighlights: boolean): void
  • Gets the currently active match generateContentHighlights setting.

    Returns boolean

  • Sets whether the results should generate the content-highlight tags or not.

    Note: See the matchGenerateContent property in regards to IndexManager requirements.

    Will run trigger-checks and potentially update services.

    Parameters

    • generateContentHighlights: boolean

    Returns void

matchGrouping

  • get matchGrouping(): boolean
  • set matchGrouping(useGrouping: boolean): void
  • Gets the currently active match grouping mode.

    Returns boolean

  • Sets whether the results should be grouped or not.

    Note: Requires the search-service to have the option enabled in it's configuration too.

    Will run trigger-checks and potentially update services.

    Parameters

    • useGrouping: boolean

    Returns void

matchOrderBy

  • get matchOrderBy(): OrderBy
  • set matchOrderBy(orderBy: OrderBy): void
  • Gets the currently active match order.

    Returns OrderBy

  • Sets the match sorting mode to be used. Will run trigger-checks and potentially update services.

    Parameters

    Returns void

matchPage

  • get matchPage(): number
  • set matchPage(page: number): void
  • Gets the currently active match-page.

    Returns number

  • Sets the match-page to get. Will run trigger-checks and potentially update services.

    Parameters

    • page: number

    Returns void

matchPageSize

  • get matchPageSize(): number
  • set matchPageSize(pageSize: number): void
  • Gets the currently active match page-size.

    Returns number

  • Sets the match page-size to be used. Will run trigger-checks and potentially update services.

    Parameters

    • pageSize: number

    Returns void

maxSuggestions

  • get maxSuggestions(): number
  • set maxSuggestions(maxSuggestions: number): void
  • Gets the currently active max number of autocomplete suggestions to get.

    Returns number

  • Sets the max number of autocomplete suggestions to get. Will run trigger-checks and potentially update services.

    Parameters

    • maxSuggestions: number

    Returns void

query

  • Returns the currently active query.

    Returns IQuery

  • Sets the query to use. Consider using the queryText-property for query-text-changes instead.

    Note: Changing the query property will likely lead to multiple trigger-checks and potential updates. This is because changing the whole value will lead to each of the query-objects' properties to trigger individual events.

    To avoid multiple updates, call deferUpdates(true) before and deferUpdates(false) afterwards. Then at max only one update will be generated.

    Parameters

    Returns void

queryText

  • get queryText(): string
  • set queryText(queryText: string): void
  • Gets the currently active query-object.

    Returns string

  • Sets the query-text to be used. Will run trigger-checks and potentially update services.

    Parameters

    • queryText: string

    Returns void

searchType

  • Gets the currently active search-type value.

    Returns SearchType

  • Sets the search-type to be used. Will run trigger-checks and potentially update services.

    Parameters

    Returns void

uiLanguageCode

  • get uiLanguageCode(): string
  • set uiLanguageCode(uiLanguageCode: string): void
  • Gets the currently active match generateContent setting.

    Returns string

  • Sets the language that the client uses. Affects category-names (and in the future maybe metadata too). The expected values should be according to the https://www.wikiwand.com/en/IETF_language_tag standard.

    Changes will run trigger-checks and potentially update services.

    Parameters

    • uiLanguageCode: string

    Returns void

Methods

deferUpdates

  • deferUpdates(state: boolean, skipPending?: boolean): void
  • Decides whether an update should be executed or not. Typically used to temporarily turn off update-execution. When turned back on the second param can be used to indicate whether pending updates should be executed or not.

    Note: Changes deferring of updates for all components (Autocomplete, Categorize and Find). Use the service properties of the SearchClient instance to control deferring for each service.

    example

    Some examples:

    // Example 1: Defer updates to avoid multiple updates:
    searchClient.deferUpdates(true);
    
    // Example 2: Change some props that triggers may be listening for
    searchClient.dateFrom = { M: -1};
    searchClient.dateTo = { M: 0};
    // When calling deferUpdates with (false) the above two update-events are now executed as one instead (both value-changes are accounted for though)
    searchClient.deferUpdates(false);
    
    // Example 3: Suppress updates (via deferUpdates):
    searchClient.deferUpdates(true);
    // Change a prop that should trigger updates
    searchClient.queryText = "some text";
    // Call deferUpdates with (false, true), to skip the pending update.
    searchClient.deferUpdates(false, true);
    
    // Example 4: Defer update only for one service (Categorize in this sample):
    searchClient.categorize.deferUpdates(true);
    

    Parameters

    • state: boolean

      Turns on or off deferring of updates.

    • skipPending: boolean = false

      Used to indicate if a pending update is to be executed or skipped when deferring is turned off. The param is ignored for state=true. Default is false.

    Returns void

filterAdd

  • Add the given filter, if it isn't already there.

    Will run trigger-checks and potentially update services.

    Parameters

    Returns boolean

filterRemove

  • Remove the given filter, if it is already set.

    Will run trigger-checks and potentially update services.

    Parameters

    Returns boolean

filterToggle

  • Toggle the given filter.

    Will run trigger-checks and potentially update services.

    Parameters

    • filter: string[] | Filter | ICategory

      Is either string[], Filter or Category. When string array it expects the equivalent of the Category.categoryName property, which is like this: ["Author", "Normann"].

    Returns boolean

    true if the filter was added, false if it was removed.

findCategory

  • Find the category based on the category-name array.

    Parameters

    • categoryName: string[]

      The category array that identifies the category.

    Returns ICategory | IGroup

    The Category object if found or null.

forceUpdate

  • forceUpdate(query?: IQuery, autocomplete?: boolean, categorize?: boolean, find?: boolean): void
  • This method is called when you want to force an update call to be made for the services.

    It may force an update based on the existing this.query value or you can provide a new query object to be used. After having set the value the services will be called, unless they are disabled in their respective configs or turned off in the params to this method.

    Parameters

    • Optional query: IQuery

      If passed in then the query object will update the internal query-object without triggering any updates, but will just after this force an update on all enabled services, that are not turned off by the consecutive params.

    • autocomplete: boolean = true

      Allows turning off updates for the Autocomplete service (if the service is enabled in the settings).

    • categorize: boolean = true

      Allows turning off updates for the Categorize service (if the service is enabled in the settings).

    • find: boolean = true

      Allows turning off updates for the Find service (if the service is enabled in the settings).

    Returns void

hasChildFilter

  • hasChildFilter(category: string[] | ICategory): boolean
  • Checks whether any child-node of the given category has a filter defined for it. Typically used to visually show in the tree that a child-node has an active filter.

    Parameters

    Returns boolean

isFilter

  • Returns true if the passed argument is a filter. Typically used to visually indicate that a category is also a filter.

    Parameters

    Returns boolean

matchPageNext

  • matchPageNext(): boolean
  • Gets the next page of match-results (if any). Will run trigger-checks and potentially update services.

    Returns boolean

matchPagePrev

  • matchPagePrev(): boolean
  • Gets the previous page of match-results. Will run trigger-checks and potentially update services.

    Returns boolean

reset

  • reset(): void
  • Resets the SearchClient instance (filters, queryText, categoryPresentations++) to initial values.

    Returns void

toggleCategoryExpansion

  • toggleCategoryExpansion(node: string[] | ICategory | IGroup, state?: boolean): boolean
  • Toggles the expansion/collapsed state for the given group/category

    Parameters

    • node: string[] | ICategory | IGroup

      The node that is to be expanded.

    • Optional state: boolean

    Returns boolean

    The new state of the node.

update

  • update(query?: IQuery, autocomplete?: boolean, categorize?: boolean, find?: boolean): void
  • This method is typically called when the user clicks the search-button in the UI.

    For query-fields that accepts enter the default queryChangeInstantRegex catches enter. When they don't take enter you will have to set up something that either catches the default enter or a user clicks on a "Search"-button or similar. You can choose to use the already current query, or you can pass it in. If you include the query then the internal updates are suppressed while changing the query-properties, to make sure that only one update per service is made (if any of their trigger-checks returned true).

    Parameters

    • Optional query: IQuery

      If passed in then the query object will update the internal query-object and any updates will trigger (but only once). The consecutive overriding service params are ignored when this parameter has a value. If the query is empty/null/undefined then the services will force an update, but allows the bool params to override this.

    • autocomplete: boolean = true

      Allows turning off updates for the Autocomplete service (if the service is enabled in the settings). Only effective when query is not set.

    • categorize: boolean = true

      Allows turning off updates for the Categorize service (if the service is enabled in the settings). Only effective when query is not set.

    • find: boolean = true

      Allows turning off updates for the Find service (if the service is enabled in the settings). Only effective when query is not set.

    Returns void

Generated using TypeDoc