See %Regex.Matcher

Example:

text "This is a sample blob of text",
  keywords="This,blob,text"

matcher=##class(%Regex.Matcher).%New($tr(keywords,",","|")),
  matcher.Text=text
w:matcher.Locate() "hit",!

matcher.ResetPosition()

while matcher.Locate() {write "Found ",matcher.Group," at position ",matcher.Start,!}

USER>^test
hit
Found This at position 1
Found blob at position 18
Found text at position 26

Or see $locate: Using Regular Expressions in Caché

Example:

USER>w $locate(text,$tr(keywords,",","|"),1,e,x)
1

I keep my promise (yes, it wasn't an April Fool's joke ;)

  • The first way is associated with a dummy field for the sake of being able to override the final BuildValueArray method and avoid the following error
    ERROR #5272: Can't change final 'Method' : 'BuildValueArray')
    Class rcc.IC.ItemList Extends (%Persistent%Populate) [ Final ]
    {
    
    Index xitmp On (ItemsP(KEYS), ItemsP(ELEMENTS));
    
    Property Company As %String Required ];
    
    Property Region As list Of %String(COLLATION "EXACT"POPSPEC ":4"VALUELIST ",US,CD,MX,EU,JP,AU,ZA") [ Required ];
    
    Property Items As list Of rcc.IC.serItem(POPSPEC ":4") [ Required ];
    
    Property ItemsP As %String(COLLATION "EXACT") [ CalculatedPrivateReadOnlyRequiredSqlComputeCode = {{*} {Items}}, SqlComputed ];
    
    ClassMethod ItemsPBuildValueArray(
      value,
      ByRef arrayAs %Status
    {
      ptr=0
      while $listnext(value,ptr,val){
        v=$li(val,1),
          array($li(v,1))="Subject",
          array($li(v,2))="Change",
          array($li(v,3))="Color"
      }
      q $$$OK
    }
    
    }
    select count(IDfrom rcc_IC.ItemList where FOR SOME %ELEMENT(ItemsP) (%key in ('blue','yellow') and %value='Color')

    or if need to find values in any fields

    select count(IDfrom rcc_IC.ItemList where FOR SOME %ELEMENT(ItemsP) (%key in ('blue','yellow'))

    For the sake of speed, you can store in the index not all the fields of the serial class, i.e.:

    Index xitmp On ItemsP(KEYS);
    
    ClassMethod ItemsPBuildValueArray(
      value,
      ByRef arrayAs %Status
    {
      ptr=0
      while $listnext(value,ptr,val){
        v=$li(val,1),
          array($li(v,3))="" ; only Color
      }
      q $$$OK
    }
    select count(IDfrom rcc_IC.ItemList where FOR SOME %ELEMENT(ItemsP) (%key in ('blue','yellow'))

    You can also add more dummy fields and accordingly indexes to cover all possible queries.


  • The second way involves changing the storage and creating a virtual table
    Class rcc.IC.ItemList Extends (%Persistent%Populate) [ Final ]
    {
    
    Index xitm On Items(ELEMENTS).Color;
    
    Index xitm1 On (Items(ELEMENTS).Color, Items(KEYS));
    
    Property Company As %String Required ];
    
    Property Region As list Of %String(COLLATION "EXACT"POPSPEC ":4"VALUELIST ",US,CD,MX,EU,JP,AU,ZA") [ Required ];
    
    Property Items As list Of rcc.IC.serItem(POPSPEC ":4"STORAGEDEFAULT "array") [ Required ];
    
    }
    select count(distinct IDfrom rcc_IC.ItemList where ItemList_Items->Items_Color in ('blue','yellow') -- index "xitm1" is used

    or even faster

    select count(IDfrom rcc_IC.ItemList where FOR SOME %ELEMENT(Items) (%Value in ('blue','yellow')) -- index "xitm" is used

    Of course, the data can be accessed from both tables, just do not forget about SetCollectionProjection GetCollectionProjection (for more information, see my article SQL index for array property elements)

The %SYS namespace sources are open to study and often (but not always) serve as a coding etalon reference for application developers. This is a whole storehouse of knowledge for those who want to better understand certain mechanisms work of system classes.
If some of the commands found there are not documented, but effectively do useful work, then why can't they be used by application developers?
In addition, I do not rule out the fact that some of them are simply forgot to document.

What really needs to be hidden or potentially dangerous is already hidden in the deployed classes.

Hi Robert.

I also got carried away with this question and found two more ways to use indexes for a list of serial objects, and you can explicitly specify specific fields in the query, rather than $list (%Value,3).

The speed may be not always the best, but I did the best I could. I tested on Caché (perhaps something has been improved in IRIS in this regard?)

If you're interested, I can share it.

$LISTFIND certainly does its job well, but there is a better solution.

As the data grows, the search speed will drop, since this solution does not use indexes in any way.
Therefore, the best solution is to use the predicate FOR SOME %ELEMENT.

For more details with examples, see one of my articles: SQL Performance Resources (item k. Indexing of non-atomic attributes)

Only customers with the corresponding paid valid service have access to the download from WRC (see in the price list the section Services Fees: Software Updates, Technical Assistance).
Those who use the Community Edition or who have expired, can not download anything from there.

Therefore, in this case, open resources, such as Github or FTP, are more preferable.

The interactive tutorials with exercises built into the documentation helped me a lot in my time:

Also included was a database "SAMPLES" (code and data) with examples for every taste. I often used it for performance testing.

Note: I give a link to version 2016.2, because since version 2017.1, for some reason, the developers have changed the display styles in the online documentation and removed some information. Local documentation does not have these disadvantages.

In addition, in the <cachesys>\dev\ folder there were numerous demos with source code for various programming languages and connection technologies (С++, C#, Java, PHP, Python, ODBC, JDBC, ADO.NET, ActiveX, XEP, etc.):

 
Incomplete content

Examining an XML Subtree

  try{

    $$$ThrowOnError(##class(%XML.XPATH.Document).CreateFromString("<a><b><c>some content</c></b></a>", .doc))
    
$$$ThrowOnError(doc.EvaluateExpression("/a""b", .field))
    
#dim obj As %XML.XPATH.DOMResult field.GetAt(1)
    
    
while obj.Read() {
      
if obj.HasValue {
        
write obj.Path,": ",obj.Value,!
      
}
    }
    
  }
catch(ex){
    
write "Error "ex.DisplayString(),!
  
}

Result:
b\c: some content