Skip to main content

Getting Started with Optic

To Include an Operator in the Search String

We could have found our active, full-time employees with a different CTS Function: cts.parse(). The following query is similar to the previous query except that it uses cts.parse() with a single parameter consisting of both phrases separated by an operator instead of cts.nearQuery() with a parameter for each phrase:

op.fromSearchDocs(
   cts.andQuery([
      cts.collectionQuery('https://example.com/content/employee'),
      cts.parse('active NEAR full time')
   ]))
   .offsetLimit(0, 100)
   .result();
  • The CTS Function cts.parse() allows you to quickly write complex search queries using a grammar that will be automatically translated into whatever cts.query-type function will do the job.

  • Creating a search box field in your user-facing application is a common way to enable your users to leverage this grammar.

  • cts.parse(‘active NEAR full time’) is translated into cts.nearQuery([‘active’, ‘full time’]).

  • The full grammar for this function is explained in Creating a Query from Search Text with cts:parse in the Search Developer's Guide.

Here is row 1 of the 100-row x 3-column result:

{
 "uri": "/data/employees/b0d5a15e-b5ce-4138-9a59-f46e08119bc4.json", 
 "doc": {
  "GUID": "b0d5a15e-b5ce-4138-9a59-f46e08119bc4", 
  "Gender": "male", 
  "Title": "Mr.", 
  "GivenName": "Ralph", 
  "MiddleInitial": "M", 
  "Surname": "Deweese", 
  "StreetAddress": "2031 O Conner Street", 
  "City": "Gulfport", 
  "State": "MS", 
  "ZipCode": "39507", 
  "Country": "US", 
  "EmailAddress": "RalphMDeweese@rhyta.com", 
  "TelephoneNumber": "228-850-3365", 
  "TelephoneCountryCode": "1", 
  "Birthday": "11/25/62", 
  "NationalID": "428-08-3456", 
  "BaseSalary": "75054", 
  "Bonus": "7505", 
  "Department": "Marketing", 
  "Status": "Active - Regular Exempt (Full-time)",              // Found! 
  "ManagerGUID": "d0862e5d-5be6-473b-a500-3e3a852b2bb8", 
  "point": {
   "lat": 30.372732, 
   "long": -88.999739
  }, 
  "HiredDate": "2020-03-18"
 }, 
 "score": 4096
}
  • Only one result will be returned per document no matter how many times the phrase occurs within a particular document.