Class Reference
%iFind.Utils
Server:irisdocs3
Instance:IRISLATEST
User:UnknownUser
 
-
  [%SYS] >  [%iFind] >  [Utils]
Private  Storage

class %iFind.Utils extends %iFind.FindUtils

This class offers a number of utility methods for working with %iFind

Inventory

Parameters Properties Methods Queries Indices ForeignKeys Triggers
23 5


Summary

Methods
Highlight NormalizeSearchString Rank TestSearchString


Methods

• classmethod Highlight(pText As %String, pSearchString As %String, pSearchOption As %String = $$$IFSEARCHNORMAL, pTags As %String = $$$IFDEFAULTHLTAGS, pLimit As %Integer = 0, pLanguage As %String = "en", Output pSC As %Status) as %String [ SQLProc = Highlight ]

This SQL procedure returns a marked-up version of pText, in which all matches of the supplied pSearchString are highlighted using pTags.

SELECT %iFind.Highlight('Great cocktails by the pool, but the bees were a bit of a bummer.', 'cocktail* OR (hammock AND NOT bees)')

pTags is a comma-separated list of tags to use for highlighting. If only a single one is supplied, it will be used to highlight all matches of search terms. If a second one is supplied, it will be used for all terms in a NOT node of the search tree (such as 'bees' in the above example), while the first will be used for all other terms.

pLimit can be used to limit the text to a maximum number of hits rather than returning the entire, highlighted text. pSearchOption can be used as in other iFind search operations, for example to also mark fuzzy matches or stem matches.

• classmethod NormalizeSearchString(pSearchString As %String, Output pSC As %Status) as %String [ SQLProc = NormalizeSearchString ]

Normalizes the supplied pSearchString into an unambiguous combination of atomic search strings, combined with AND, OR and NOT operators and appropriately surrounded by parentheses for clarifying operator precedence.

SELECT %iFind.NormalizeSearchString('abc or (def* and not xyz)')

See also TestSearchString

• classmethod Rank(pRankerClass As %String = $$$IFDEFAULTRANKER, pClassName As %String, pIndexName As %String, pRecordId As %RawString, pSearchString As %String, pSearchOptions As %String = $$$IFSEARCHNORMAL, Output pSC As %Status) as %Float [ SQLProc = Rank ]

This SQL function returns a score for how well record pRecordId matches the supplied search string pSearchString, according to the ranker implementation pRankerClass. This method can be invoked through SQL directly to override the default ranker class used by the Rank procedure that's generated automatically on the iFind-indexed class.

SELECT %ID, 
	Title,
	FullText,
	%iFind.Rank('%iFind.Rank.TFIDF', 'SomePackage.TheTable', 'MyIndex', %ID, 'cocktail* OR (hammock AND NOT bees)') As Rank
FROM SomePackage.TheTable
WHERE %ID %FIND search_index(MyIndex, 'cocktail* OR (hammock AND NOT bees)')
ORDER BY 4 DESC

See also %iFind.Rank.Abstract.

• classmethod TestSearchString(pSearchString As %String, Output pNormalizedString As %String, Output pDidYouMean As %String) as %Status [ SQLProc = TestSearchString ]

Validates whether the supplied pSearchString is correct according to iFind search syntax rules, returning a %Status object capturing the correctness ($$$OK if the supplied string is valid, an error code if it is not).

SELECT %iFind.TestSearchString('abc or (def* and not xyz)')

This method will also return a cleaned and unambiguous version of the search string through the pNormalized output argument. See also NormalizeSearchString.


Queries

• query FindEntities(pSearchValue As %String, pSearchOption As %String = $$$IFSEARCHNORMAL, pStrippedEntitiesOnly As %Boolean = 1, pLanguage As %String = "en")
Selects EntityId As %Integer, Entity As %String

Utility function to retrieve entities "similar" to the supplied search string, that have occurred in indexing results for this namespace. For the pSearchValue argument, the same syntax is available as for regular word search in an iFind search call for each word "position" in the supplied search string. For example, the following request will retrieve entities such as "matched words", "matching word" and "all matching words":

CALL %iFind.FindEntities('match* word*')

Composite search syntax (AND, OR, NOT) is not supported, but you can use a lone asterisk to accept any at a given position.

pSearchOption supports the same values as for a regular iFind search ($$$IFSEARCHNORMAL, $$$IFSEARCHSTEMMED, $$$IFSEARCHDECOMPOUNDED, $$$IFSEARCHPATTERN and $$$IFSEARCHFUZZY), although in the case of stemmed or decompounded search, the results will be limited to those entity forms having been indexed by an iFind index with stemming resp decompounding enabled in this namespace. For these two options, the pLanguage argument is also required (but ignored for other search modes).

The pStrippedEntitiesOnly flag can be used to only retrieve entities that have been stripped of all (per-word) leading and trailing punctuation (default) or include all actual entities as encountered by iFind indices in this namespace given their respective punctuation-stripping settings.

To filter or sort these results according to a particular index, the (Analytic) index will have to have its IFINDADVANCED parameter set to 2, so this procedure's results can be JOINed to the generated "EntSpread" table. For example, with a table Experiment.IFData and iFind index iText:

SELECT
	e.EntityId, e.Entity, s.Spread 
FROM 
	%iFind.FindEntities('a*') e 
	JOIN Experiment_IFData.IFData_iText_EntSpread s 
		ON e.EntityId = s.EntityId
ORDER BY Spread DESC

Note that this method only retrieves entities appearing in indices whose shared data is stored namespace-wide (the default). See also the IFINDSHAREDSTORAGELOCATION parameter in %iFind.Index.Basic.

• query FindWords(pSearchValue As %String, pSearchOption As %String = $$$IFSEARCHNORMAL, pStrippedWordsOnly As %Boolean = 1, pLanguage As %String = "en")
Selects WordId As %Integer, Word As %String

Utility function to retrieve words "similar" to the supplied search string, that have occurred in indexing results for this namespace. For the pSearchValue argument, the same syntax is available as for regular word search in an iFind search call, where now the matching words rather than records containing them will be retrieved. Composite search syntax (AND, OR, NOT) is not supported.

pSearchOption supports the same values as for a regular iFind search ($$$IFSEARCHNORMAL, $$$IFSEARCHSTEMMED, $$$IFSEARCHDECOMPOUNDED, $$$IFSEARCHPATTERN and $$$IFSEARCHFUZZY), although in the case of stemmed or decompounded search, the results will be limited to those word forms having been indexed by an iFind index with stemming resp decompounding enabled in this namespace. For these two options, the pLanguage argument is also required (but ignored for other search modes).

The pStrippedWordsOnly flag can be used to only retrieve words that have been stripped of all leading and trailing punctuation (default) or include all actual forms as encountered by iFind indices in this namespace given their respective punctuation-stripping settings.

Note that this method only retrieves words appearing in indices whose shared data is stored namespace-wide (the default). See also the IFINDSHAREDSTORAGELOCATION parameter in %iFind.Index.Basic.

• query GetIndicesInClass(namespace As %String = $namespace, class As %String)
Selects namespace As %String, schema As %String, class As %String, index As %String, typeClass As %String
Returns all iFind indices in class
deprecatedquery GetIndicesInNamespace(namespace As %String = $namespace, indexType As %String = "")
Selects namespace As %String, schema As %String, class As %String, index As %String, typeClass As %String
returns all iFind indices in the namespace


Copyright (c) 2019 by InterSystems Corporation. Cambridge, Massachusetts, U.S.A. All rights reserved. Confidential property of InterSystems Corporation.