Field-Specific Search - V2

General keyword-based search scans all the fields in Hawksearch marked as query-able. However sometimes in situations where we already know the field to be searched for, or would like to customize the search option to target a specific field alone, we can use the query filtering option to specify the field to be searched against.

Types of Search

There are 4 different types of search that are supported. To apply these different types of the field needs to be suffixed with the type of search

  • keyword - exact match on an entire field value.
  • text - match on a single word within a field value.
  • prefix - match on the first characters of a single word in a field value.
  • wildcard match on a segment of a single word within a field value.

Field Setup for each type of search

To make each type of search available, the field needs to be set up in a specific way within the Hawksearch admin.

  • keyword - exact match on an entire field value.
    • Field Type
      • Field values are NOT stemmed
      • Field values indexed “as is“ AND are stemmed
  • text - match on a single word within a field value.
    • Field Type
      • Field values are ONLY stemmed (search only)
      • Field values indexed “as is“ AND are stemmed
  • prefix - match on the first characters of a single word in a field value.
    • Partial Query Type
      • Prefix
  • wildcard - match on a segment of a single word within a field value.
    • Partial Query Type
      • Wildcard

Notes

  • This can be used for fields which are not marked as query-able also.
  • Errors in this query field value are ignored, please double check your query if the result is not as expected.
  • This is equivalent to the Hawksearchable parameter used in Hawksearch versions 2.0L to 4.0L.
  • The format for fields that are set up as text in the Hawksearch admin is as follows “fieldname.{{typeofsearch}}” : ”value”.
  • The format for fields that are set up as numeric in the Hawksearch admin is as follows “fieldname” : ”value”.
  • Soft Errors will be thrown in the following scenarios and are not supported
    • Wildcard characters within the query value (must use a field specified as wildcard or prefix and not include * in the query value)
    • Phrase queries with proximity
    • Queries on fields that are not set up according to the guidelines above
    • Regular Expression Queries
    • Malformed queries
    • Queries that don’t specify a specific field

Examples

The URL endpoints are available here - Hawksearch v4.0 - Search API

  1. Specifying the field name in the “query” parameter:
POST /api/v2/search  
{  
    "keyword" : "",  
    "query" : "group_id.prefix: 12",  
    "clientguid" : "SPECIFY YOUR CLIENT GUID HERE"  
}
  1. Use query parameter with the normal search:
POST /api/v2/search  
{  
    "keyword" : "perfect",  
    "query" : "group_id.keyword: 123",  
    "clientguid" : "SPECIFY YOUR CLIENT GUID HERE"  
}
  1. Use query parameter with the operators AND, OR, NOT:
POST /api/v2/search  
{  
    "keyword" : "perfect",  
    "query" : "group_id.keyword: 123 OR group_id.keyword: 456",  
    "clientguid" : "SPECIFY YOUR CLIENT GUID HERE"  
}
  1. Complex query parameter with multiple fields and the operators AND, OR, NOT:
POST /api/v2/search  
{  
    "keyword" : "",  
    "query" : "group_id.keyword:123 AND (sku.keyword:ABC OR sku.keyword:DEF)",  
    "clientguid" : "SPECIFY YOUR CLIENT GUID HERE"  
}
  1. Query parameter with TO (range between two values)
POST /api/v2/search  
{  
    "keyword" : "perfect",  
    "query" : "price: [1.00 TO 10.00]",  
    "clientguid" : "SPECIFY YOUR CLIENT GUID HERE"  
}
  1. Query parameter with Math (numeric values)
POST /api/v2/search  
{  
    "keyword": "perfect",  
    "query": "width: >7 AND width: \<=10",  
    "clientguid":"SPECIFY YOUR CLIENT GUID HERE"  
}
  1. This feature is also available on Hawksearch’s Autocomplete API:
    Please note that the keyword is required for autocomplete request.
POST request to /api/v2/autocomplete  
{  
    "keyword" : "perfect",  
    "query" : "group_id.keyword: 123",  
    "clientguid" : "SPECIFY YOUR CLIENT GUID HERE"  
}
  1. Use query parameter with EXISTS operator to check for values:
POST request to /api/v2/search  
{  
    "keyword" : "",  
    "query" : "_exists_: my_field.keyword",  
    "clientguid" : "SPECIFY YOUR CLIENT GUID HERE"  
}
  1. Use double backslashes \ to escape the spaces:
{  
    "ClientGuid": "SPECIFY YOUR CLIENT GUID HERE",  
    "Keyword": "",  
    "query":"first\\ name.keyword: John\\ Doe"  
}
  1. Use the backslashes with hawk_child_attributes and value also:
{  
    "ClientGuid": "SPECIFY YOUR CLIENT GUID HERE",  
    "Keyword": "",  
    "query":"hawk_child_attributes.field\\ with\\ space.keyword: sample\\ value\\ with\\ spaces"  
}