Spectrum Search Optimizations with "does not contain" string
search cancel

Spectrum Search Optimizations with "does not contain" string

book

Article ID: 387285

calendar_today

Updated On:

Products

Network Observability

Issue/Introduction

We have implemented several searches for Global Collections in OneClick, but we have noticed that if we add a "does not contain" string at the end of our search, the search goes from 3 seconds to 60 seconds.  A 20x increase seems excessive and causes the 0x10f21 alarm "A possible SpectroSERVER performance problem has been detected" with our search.

Environment

Spectrum  Any

Component Global Collection Searches

Cause

By adding the search as does not have substring, we are searching each letter one at a time for the attribute location (0x23000d).

 

<does-not-have-substring>

<attribute id=""0x23000d"">

<value>123</value>

</attribute>

</does-not-have-substring>

 

If we change this to "does not equal" then we can search all of the string at the same time.

Resolution

If it is necessary to search as "Does Not Have" substring and its taking a long time, you may try to use Regex Matches Pattern using Negative Lookaheads.

 

For example if we add matches pattern for the location attribute (0x23000d)

 ^(?!.*123).*$

 

Our search goes down to a very reasonable 5 seconds.

 

 

Additional Information

Breakdown of this RegEx Pattern

 

^: This matches the start of the string. It ensures that the pattern checks from the very beginning of the string.

(?!.*123): This is a negative lookahead that ensures the string does not contain the substring 123 anywhere after the start of the string. Here's how it works:

.* matches any sequence of characters (except newlines).
123 is the literal string you're trying to avoid.
The ?! part makes this a negative lookahead. This means that if the pattern .*123 is found (i.e., if 123 appears anywhere in the string), the match will fail. In other words, this part ensures that 123 is not present anywhere in the string.
.*: This matches any character (except line breaks) zero or more times. This part of the pattern matches the rest of the string, after the negative lookahead has successfully ensured that 123 is not present.

$: This matches the end of the string, ensuring that the entire string is checked.