How to make partial pattern matches in keyword queries?

Maxim8
Giga Contributor

Hello all,

As the question states, I was wondering if there is a way to make partial pattern matches for keyword queries using GlideRecord?

Let's say I have records/text like:

Apple

Orange

Apple and Orange

I know that if I do something like

gr.addQuery("123TEXTQUERY321", keyword);

I have to match the entire word for a result for a result to show up, and if I make keyword something that is a partial match, like

gr.addQuery("123TEXTQUERY321", "Appl");

no results will show. Is there a way to get results back using partial matches and if so, what is the best way?

I've tried using wildcards like *keyword and keyword* but that doesn't really solve my issue because there are cases like searching the last X digits of a record's number field where the result won't show up. Individually, these also don't help the partial matching issue either. Querying Appl* helps with the partial matching issue but it doesn't help if the query is for the last X digits of a record's number field (000001* isn't going to return results for RITM0000001). And switching from keyword* to *keyword just switches the type of queries that won't show up.

/*
Example records
RITM0000001 - Oranges
TASK0000001 - Apples
*/

// keyword*
gr.addQuery("123TEXT321", "Appl*")
// TASK0000001 - Apples appears
// RITM0000001 - Oranges doesn't appear

gr.addQuery("123TEXTQUERY321", "0000001*")
// Nothings appears


// *keyword
gr.addQuery("123TEXTQUERY321", "*Appl");
// Nothing appears

gr.addQuery("123TEXTQUERY321", "*0000001");
// TASK0000001 appears
// RITM0000001 appears

I've also tried doing things like *keyword* but I get an error message saying how the wildcards are too ambiguous/too many results (or something like that).

 

Is there any way to achieve partial pattern matching when querying keywords? Or do I have to resort to some type of workaround?

10 REPLIES 10

Hitoshi Ozawa
Giga Sage
Giga Sage

Instead of using .addQuery(), there is .addEncodedQuery() that is more useful in partial matching.

For example, .addEncodedQuery('numberENDSWITH12') will match text ending with "12" on a number field.

.addEncodedQuery('numberLIKEC001') will match text containing "C001" in a number field.

 

https://developer.servicenow.com/blog.do?p=/post/training-encoded-query/

To get the query to use in addEncodedQuery(), display the list to query and use the funnel at the top left corner to create a query. Then, right click on the breadcrumb and select "Copy query".

find_real_file.png

Hmmm... I was looking more for a full text search option. Maybe querying multiple fields using the 'LIKE' operator could work?

addEncodedQuery() also is faster than having complex queries with addQuery().