File

src/lib/service/stored-queries/stored-query.model.ts

Description

Stored query is an extension of a SearchQuery. It adds properties like name and a list of dynamic filter properties and the ability to generate an object from its properties that could be pwersisted on the backend side.

Extends

SearchQuery

Index

Properties
Methods

Constructor

constructor(item?: IStoredQuery)
Parameters :
Name Type Optional
item IStoredQuery yes

Properties

favorite
favorite: boolean
Type : boolean
id
id: string
Type : string
Static ID_NEW
ID_NEW: string
Type : string
Default value : 'new'

temporary id for new stored queries

name
name: string
Type : string
parameter
parameter: IStoredQueryParam[]
Type : IStoredQueryParam[]
roles
roles: string[]
Type : string[]
shared
shared: boolean
Type : boolean
user
user: string
Type : string

the username of the user that created this query

version
version: number
Type : number
__updateCause
__updateCause: string
Type : string
Inherited from SearchQuery
Defined in SearchQuery:174
Static BASE_PARAMS
BASE_PARAMS: object
Type : object
Default value : { TYPE: 'type', CREATOR: 'creator', CREATED: 'created', MODIFIER: 'modifier', MODIFIED: 'modified', FILESIZE: 'filesize', FILENAME: 'filename', MIMETYPEGROUP: 'mimetypegroup', FOLDER: 'folder' }
Inherited from SearchQuery
Defined in SearchQuery:21

Base Parameters for a Search Query

Public contextFolderTypes
contextFolderTypes: ObjectType[]
Type : ObjectType[]
Default value : []
Inherited from SearchQuery
Defined in SearchQuery:132

List of context folder types

Static DEFAULT_SEARCH_MODE
DEFAULT_SEARCH_MODE: string
Type : string
Default value : 'idxs'
Inherited from SearchQuery
Defined in SearchQuery:112

Detault Search mode Index

Public expertMode
expertMode:
Default value : false
Inherited from SearchQuery
Defined in SearchQuery:144

Whether or not the term is an expert mode query

Public fields
fields: string[]
Type : string[]
Inherited from SearchQuery
Defined in SearchQuery:124

Array of fields to request from the search service, leaving this blank will return the fields specified in the result field configuration

Static FILE_SIZE_BUCKETS
FILE_SIZE_BUCKETS: object
Type : object
Default value : { NONE: 'none', LT1MB: 'lt1MB', LT10MB: 'lt10MB', LT100MB: 'lt100MB', GT100MB: 'gt100MB' }
Inherited from SearchQuery
Defined in SearchQuery:90

filesize buckets property names

Public filters
filters: SearchFilter[]
Type : SearchFilter[]
Default value : []
Inherited from SearchQuery
Defined in SearchQuery:136

List of filters to define the query

Static FULLTEXT_SEARCH_MODE
FULLTEXT_SEARCH_MODE: string
Type : string
Default value : 'fts'
Inherited from SearchQuery
Defined in SearchQuery:116

Search mode for Full test Search

Public highlighting
highlighting: boolean
Type : boolean
Default value : false
Inherited from SearchQuery
Defined in SearchQuery:166
Static MIMETYPEGROUP_BUCKETS
MIMETYPEGROUP_BUCKETS: object
Type : object
Default value : { PDF: 'pdf', MAIL: 'mail', WORD: 'word', IMAGE: 'image', OCTET_STREAM: 'octet-stream', TXT: 'txt', EXCEL: 'excel', POWERPOINT: 'powerpoint', VIDEO: 'video', HTML: 'html', AUDIO: 'audio', ZIP: 'zip' }
Inherited from SearchQuery
Defined in SearchQuery:72

mimetype buckets property names

Public Optional name
name: string
Type : string
Inherited from SearchQuery
Defined in SearchQuery:169
Static RELATIVE_DATE_BUCKETS
RELATIVE_DATE_BUCKETS: object
Type : object
Default value : { TODAY: 'today', YESTERDAY: 'yesterday', TOMORROW: 'tomorrow', THIS_WEEK: 'thisweek', LAST_WEEK: 'lastweek', NEXT_WEEK: 'nextweek', THIS_MONTH: 'thismonth', LAST_MONTH: 'lastmonth', NEXT_MONTH: 'nextmonth', THIS_QUARTER: 'thisquarter', LAST_QUARTER: 'lastquarter', NEXT_QUARTER: 'nextquarter', THIS_YEAR: 'thisyear', LAST_YEAR: 'lastyear', NEXT_YEAR: 'nextyear' }
Inherited from SearchQuery
Defined in SearchQuery:50

Relative date buckets property names

Public resolveReference
resolveReference:
Default value : true
Inherited from SearchQuery
Defined in SearchQuery:160

Resolve references with their title instead of their actual value

Public scope
scope: QueryScope
Type : QueryScope
Inherited from SearchQuery
Defined in SearchQuery:148

The scope of the query

Public searchMode
searchMode: string
Type : string
Default value : SearchQuery.DEFAULT_SEARCH_MODE
Inherited from SearchQuery
Defined in SearchQuery:152

The search mode to be used (SearchQuery.DEFAULT_SEARCH_MODE or SearchQuery.FULLTEXT_SEARCH_MODE)

Public sortOptions
sortOptions: SortOption[]
Type : SortOption[]
Default value : []
Inherited from SearchQuery
Defined in SearchQuery:156

Additional options to be applied to the query

Public state
state: SearchState
Type : SearchState
Default value : new SearchState()
Inherited from SearchQuery
Defined in SearchQuery:164

The state of the current query

Public suggest
suggest: boolean
Type : boolean
Inherited from SearchQuery
Defined in SearchQuery:140

Whether or not to retrieve suggestions

Public term
term: string
Type : string
Inherited from SearchQuery
Defined in SearchQuery:120

fulltext search term

Static TIME_PERIOD_BUCKETS
TIME_PERIOD_BUCKETS: object
Type : object
Default value : { TODAY: 'today', YESTERDAY: 'yesterday', THIS_WEEK: 'thisweek', LAST_WEEK: 'lastweek', THIS_MONTH: 'thismonth', LAST_MONTH: 'lastmonth', THIS_YEAR: 'thisyear', LAST_YEAR: 'lastyear' }
Inherited from SearchQuery
Defined in SearchQuery:36

Time period buckets property names

Public types
types: ObjectType[]
Type : ObjectType[]
Default value : []
Inherited from SearchQuery
Defined in SearchQuery:128

List of object types to be fetched by the query. Leaving this blank will return results from any type

Static UPDATE_CAUSE
UPDATE_CAUSE: object
Type : object
Default value : { TOGGLED_TYPE: 'cause.type.toggled', TOGGLED_EXPERTMODE: 'cause.expertmode.toggled', TERM_SET: 'cause.term.set', TYPES_SET: 'cause.types.set', CONTEXT_FOLDER_SET: 'cause.contextfolder.set', TOGGLED_FILTER: 'cause.filter.toggled', ADDED_FILTER: 'cause.filter.added', REMOVED_FILTER: 'cause.filter.removed', }
Inherited from SearchQuery
Defined in SearchQuery:99
Public withContext
withContext: boolean
Type : boolean
Default value : false
Inherited from SearchQuery
Defined in SearchQuery:167

Methods

isNew
isNew()

Check if Query is new or allready Stored

Returns : boolean

boolean

Public setQuery
setQuery(searchQuery: SearchQuery)

Adds the properties of a SearchQuery to the current StoredQuery instance. This is used when loading stored queries from the search service and when you want to create a StoredQuery from a SearchQuery. skip fields and sortOptions properties as they make no sense for stored queries

Parameters :
Name Type Optional Description
searchQuery SearchQuery no

The search query to copy properties from

Returns : void
toPersistableStoredQuery
toPersistableStoredQuery()

Convert IStoredQueryParam objects to array of strings

Returns : IStoredQuery

IStoredQuery

Public addFilter
addFilter(filter: SearchFilter)
Inherited from SearchQuery
Defined in SearchQuery:216

Adds a new filter to the query. If there already is a filter set for the given property, it will be overridden.

Parameters :
Name Type Optional Description
filter SearchFilter no

The filter to be added

Returns : void
Public addSortOption
addSortOption(name: string, order: string, missing?: string)
Inherited from SearchQuery
Defined in SearchQuery:277

Adding new Sort Options Sort Options are only added if they are not already present

Parameters :
Name Type Optional
name string no
order string no
missing string yes
Returns : void
Public addType
addType(type: ObjectType)
Inherited from SearchQuery
Defined in SearchQuery:183

Adds a new target type to the query

Parameters :
Name Type Optional Description
type ObjectType no

Object type to be added

Returns : void
Public getFilter
getFilter(propertyName: string)
Inherited from SearchQuery
Defined in SearchQuery:261

Retrieves a filter by its property name.

Parameters :
Name Type Optional Description
propertyName string no

The filters property name (qname of form element)

Returns : SearchFilter

Search Filter Object

Public getQueryJson
getQueryJson(resolveReference?: boolean)
Inherited from SearchQuery
Defined in SearchQuery:296

Generate a query JSON from the current SearchQuery that can be send to the search service.

Parameters :
Name Type Optional Description
resolveReference boolean yes

in case of csv export the resolving of references is set by configuration

Returns : any
Public getTableFilters
getTableFilters(propertyName: string)
Inherited from SearchQuery
Defined in SearchQuery:265
Parameters :
Name Type Optional
propertyName string no
Returns : SearchFilter[]
Public removeFilter
removeFilter(filterPropertyName: string)
Inherited from SearchQuery
Defined in SearchQuery:235

Removes a filter from the query.

Parameters :
Name Type Optional Description
filterPropertyName string no

The filter (its property name) to be removed

Returns : void
Public removeSortOption
removeSortOption(name: string)
Inherited from SearchQuery
Defined in SearchQuery:287
Parameters :
Name Type Optional
name string no
Returns : void
Public removeType
removeType(type: ObjectType)
Inherited from SearchQuery
Defined in SearchQuery:194

Removes a type from the target types list

Parameters :
Name Type Optional Description
type ObjectType no

The object type to be removed

Returns : void
Public toggleFilter
toggleFilter(filter: SearchFilter, override?: boolean)
Inherited from SearchQuery
Defined in SearchQuery:244

Adds or removes the given filter based on the current settings

Parameters :
Name Type Optional Description
filter SearchFilter no

The filter to be toggled

override boolean yes
Returns : void
Public toggleType
toggleType(type: ObjectType)
Inherited from SearchQuery
Defined in SearchQuery:203

Adds or removes the given type based on the current settings

Parameters :
Name Type Optional Description
type ObjectType no

The object type to be toggled

Returns : void

Accessors

title
gettitle()
import {SearchQuery} from '../search/search-query.model';

/**
 * @ignore
 * Interface for the data used for backend communication.
 * This is the kind of data we'll get from the server and we
 * have to provide when sending stored queries to the server.
 */
export interface IStoredQuery {
  id: string;
  name: string;
  query: string;
  favorite?: boolean;
  shared?: boolean;
  user?: string;
  version?: number;
  roles?: string[];
  parameter?: string[];
}

/**
 * @ignore
 * Interface for dynamic parameter properties.
 * Form elements will be transformed to this format to save only
 * required properties
 */
export interface IStoredQueryParam {
  qname: string;
  type: string;
}

/**
 * Stored query is an extension of a SearchQuery. It adds properties like
 * name and a list of dynamic filter properties and the ability to generate
 * an object from its properties that could be pwersisted on the backend side.
 */
export class StoredQuery extends SearchQuery {

  /**
   * temporary id for new stored queries
   */
  static ID_NEW = 'new';

  id: string;
  name: string;
  favorite: boolean;
  shared: boolean;
  /**
   * the username of the user that created this query
   */
  user: string;
  version: number;
  roles: string[];
  parameter: IStoredQueryParam[];

  get title() {
    return this.name || '';
  }

  constructor(item?: IStoredQuery) {
    super();
    if (!item) {
      this.id = StoredQuery.ID_NEW;
      this.parameter = [];
    } else {
      this.id = item.id;
      this.name = item.name;
      this.favorite = item.favorite;
      this.shared = item.shared;
      this.user = item.user;
      this.version = item.version;
      this.roles = item.roles || [];
      this.parameter = [];
      /**
       * parameters contain meta data for the dynamic fields of the stored query
       * the values of those fields (if set) are part of the queries filters
       */
      if (item.parameter && item.parameter.length > 0) {
        for (let p of item.parameter) {
          try {
            const pObj = JSON.parse(p);
            const param: IStoredQueryParam = {
              qname: pObj.qname,
              type: pObj.type,
            };
            this.parameter.push(param);
          } catch (e) {
            console.error('Failed parsing stored query parameter', e);
          }
        }
      }
    }
  }

  /**
   * Adds the properties of a SearchQuery to the current StoredQuery instance.
   * This is used when loading stored queries from the search service and when you
   * want to create a StoredQuery from a SearchQuery.
   * skip `fields` and `sortOptions` properties as they make no sense for stored queries
   *
   * @param searchQuery The search query to copy properties from
   */
  public setQuery(searchQuery: SearchQuery) {
      this.term = searchQuery ? searchQuery.term : '';
      this.types = searchQuery ? searchQuery.types : [];
      this.contextFolderTypes = searchQuery ? searchQuery.contextFolderTypes : [];
      this.filters = searchQuery ? searchQuery.filters : [];
      this.suggest = searchQuery ? searchQuery.suggest : false;
      this.expertMode = searchQuery ? searchQuery.expertMode : false;
      this.scope = searchQuery ? searchQuery.scope : null;
      this.searchMode = searchQuery ? searchQuery.searchMode : 'idx';
  }

  /**
   * Convert IStoredQueryParam objects to array of strings
   *
   * @returns IStoredQuery
   */
  toPersistableStoredQuery(): IStoredQuery {

    const stringParameter = [];
    this.parameter.forEach(p => stringParameter.push(JSON.stringify(p)));

    return {
      id: this.id,
      name: this.name,
      favorite: this.favorite,
      shared: this.shared,
      user: this.user,
      version: this.version,
      roles: this.roles,
      parameter: stringParameter,
      query: JSON.stringify(this.getQueryJson())
    };
  }

  /**
   * Check if Query is new or allready Stored
   *
   * @returns boolean
   */
  isNew(): boolean {
    return this.id === StoredQuery.ID_NEW;
  }
}

results matching ""

    No results matching ""