查詢服務的查詢參數
多個 ThingWorx 服務接受選用查詢參數。查詢參數是配置方式不同 (取決於所要求的查詢類型) 的值物件。
可能的類型有:
Matches, NotMatches TaggedWith,
NotTaggedWith
GT, LT, GE, LE, NE, EQ, LIKE, NOTLIKE, IN, NOTIN
Between, NotBetween MissingValue,
NotMissingValue Near, NotNear
查詢可以是 AND/OR,且可包括「排序」。
查詢參數可用於以 query 開始的所有服務,其中包括:
全部物件
QueryThingStreamEntries
全部串流
QueryStreamData
QueryStreamEntries
QueryStreamEntriesWithData
全部資料表
QueryDataTableEntries
InfoTableFunctions 資源
Query
全部物範本
QueryImplementingThings
QueryImplementingThingsWithData
全部物形式
QueryImplementingThings
QueryImplementingThingsWithData
稽核子系統
組態
查詢參數有兩個可配置選項:篩選器與排序器。查詢參數定義完成後,可以將其傳遞到查詢服務。以下是查詢參數的篩選器與排序選項。建議您在指令集配置器中使用指令編寫工具和程式碼片段開始著手,然後再建立適當的查詢參數物件。
單一篩選器選項
Matches 或 NotMatches 篩選器
var query =
{
"filters": {
"type": "Matches|NotMatches",
"fieldName": "Source",
"expression": "(Kettle)|(Filler)"
}
};
TAGGED 或 NOTTAGGED 篩選器
var query = {
"fieldName": "tags",
"type": "NOTTAGGED",
"tags": [
{
"vocabulary": "Applications",
"vocabularyTerm": "Testing"
},
{
"vocabulary": "Plants",
"vocabularyTerm": "Sedona"
}
]
};
單一比較子
* 
使用 LIKE/NOTLIKE 時,您需新增自己的萬用字元 (% 或 * 或 ? 適用於單一字元的萬用字元)。例如,如欲尋找 ThingWorx,請使用 LIKE Th%
var query = {
"filters":{
"type": "GT, LT, GE, LE, NE, EQ, LIKE, NOTLIKE",
"fieldName": "<field_name>",
"value": "Th\\+*"
}
};
In 或 Not In 篩選器
var jsonArray = [12,14];
var query = {
"filters": {
"type": "IN, NOTIN",
"fieldName": "Duration",
"values": jsonArray
}
};
Between 或 NotBetween 篩選器
var query =
{
"filters": {
"type": "Between, NotBetween",
"fieldName": "Duration",
"from": "2",
"to": "12"
}
};
MissingValue 或 NotMissingValue 篩選器
var query =
{
"filters": {
"type": "MissingValue, NotMissingValue",
"fieldName": "OrderQuantity"
}
};
Near 或 NotNear 篩選器
var query =
{
"filters": {
"type": "Near, NotNear",
"fieldName": "fieldName",
"distance": "50",
"units": "M(iles), K(ilometers), N(autical miles)",
"location": {
"latitude": "40.12",
"longitude": "51.24",
"elevation": "300",
"units": "WGS84"
}
}
};
複合篩選器選項
可使用 AndOr 篩選器類型來結合多個篩選器。以下範例會篩選出持續時間大於 12,而且同時在標籤欄位中標記了停電維護問題的列。
var query =
{
"filters": {
"type": "And",
"filters": [
{
"type": "GT",
"fieldName": "Duration",
"value": "12"
},
{
"type": "TaggedWith",
"fieldName": "tags",
"tags": "MaintenanceIssues:PowerOutage"
}
]
}
};
具有不同 And/Or 類型的嵌套篩選器
欲使用不同的 And/Or 類型嵌套篩選器,每個 JSON 物件層級都必須有一個類型及篩選器關鍵字。下列用於查詢的 JSON 語法會取得所需的結果 (不是空白字串,以下範例中的空白字串已被 empty 取代)。
var query3 = {
"filters": {
"type": "AND",
"filters": [
{
"type": "OR",
"filters": [
{ "fieldName": "Status", "type": "LIKE", "value": "*-none-*" }
,
{ "fieldName": "Status", "type": "LIKE", "value": "empty" }
]
},
{ "fieldName": "IsDeleted", "type": "EQ", "value": false }
]
}
};
排序選項
Sorters 選項是物件陣列。在 Sorters 陣列 fieldName、isAscending 和 isCaseSensitive 中,每個排序物件都有三個可能的參數。僅欄位名稱為必填。isAscending 和 isCaseSensitive 預設為 true。
單一排序選項
var query =
{
"sorts": [
{
"fieldName": "Material"
}
]
}
複雜排序選項
var query =
{
"sorts": [
{
"fieldName": "Material"
},
{
"fieldName": "OrderDate",
"isAscending": false
}
]
}
排序與篩選器
您可以將排序與篩選器套用至相同的查詢服務,如接下來的範例所示:
var query =
{
"sorts": [
{
"fieldName": "LotID",
"isAscending": false,
"isCaseSensitive": false
},
{
"fieldName": "Plant"
}
],
"filters": {
"type": "And",
"filters": [
{
"type": "GT",
"fieldName": "Duration",
"value": "12"
},
{
"type": "TaggedWith",
"fieldName": "tags",
"tags": "MaintenanceIssues:PowerOutage"
}
]
}
};
可能的類型
可能的類型有:
EQ = 等於
NE = 不等於
GT = 大於
GE = 大於或等於
LT = 小於
LE = 小於或等於
LIKE = 類似
BETWEEN
NOTBETWEEN
這是否有幫助?