知识图谱服务上 executeSearchStreaming() 或 executeQueryStreaming() 的结果。包含匹配搜索或查询条件的可读对象流。要访问返回的图谱数据,必须使用 getReader() 函数对可读流进行解码。
示例
// sample executeSearchStreaming that would return a GraphQueryStreamingResult
KnowledgeGraphModule.executeSearchStreaming(
knowledgeGraph,
{
searchQuery: "solar",
typeCategoryFilter: "entity",
returnSearchContext: false,
start: 1, // index of the first record to return
num: 200, // return 200 records.
namedTypesFilter: ["Company", "Supplier", "Part"],
globalIdsFilter: ["{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}",
"{25WNN24S-41F1-49A4-8412-ANIWN9906E88}",
"{NS51HE8D-41F1-49A4-8412-5HNIRH9906E8}"]
}
).then((streamingSearchResult)=>{
// the result of a streaming search is a readableStream which requires decoding.
readStream(streamingSearchResult)
})
// the returned readable stream before decoding
{
resultsRowsStream: {
locked: true
}
}
// sample streaming query using bind parameters
// to search for entities with a the `name` property that matches a specific string
// or have their geometry within a bounding box.
// get all parts bought by each supplier.
// query returns both the supplier and the part it buys.
const query = `MATCH (s:Supplier)-[:buys_part]-(p:Part) RETURN s,p`;
KnowledgeGraphModule.executeQueryStreaming(knowledgeGraph, query})
.then((streamingQueryResult)=>{
// streaming query returns a readableStream which must be read to access the returned graph data
readStream(streamingQueryResult);
})
// a function to read the readable stream returned from the above query
const readStream = async (streamingQueryResult) => {
let time = Date.now();
let reader = streamingQueryResult.resultRowsStream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
console.log(`Completed database requests: ${(Date.now() - time) / 1000} seconds`, value);
break;
}
console.log(`Chunk returned in: ${(Date.now() - time) / 1000} seconds`, value);
// use the results
// list the parts bought by each supplier
let supplierParts = {};
// each element of the result array will contain one supplier and one part it buys
for (var v in value){
let supplier = value[v][0].properties.Name
let part = value [v][1].properties.Name
if(!(supplier in supplierParts)){
supplierParts[supplier] = [];
}
// collect parts by supplier that buys them
supplierParts[supplier].push(part);
console.log(supplierParts);
// result printed to the console: {Supplier 1:[Part1], Supplier 3:[Part2, Part3]}
}
} catch (err) {
if (err.name === "AbortError") {
console.log("Request aborted as expected");
} else {
throw err;
}
}
};
// sample result of streaming search result chunk read and printed to the console.
// the reader will continue to return chunks until the stream is complete
// and all matching results are returned
"Streaming chunk returned in: 0.082 seconds"
[
[{
"declaredClass": "geoscene.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Suncommon",
"Employee_Count": 400,
"energyType": "solar"
},
"typeName": "Company",
"id": "{25WNN24S-41F1-49A4-8412-ANIWN9906E88}"
}],
[{
"declaredClass": "geoscene.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Quality Solar Supply",
"Supplier_code": "158B",
"City": "New Orleans",
},
"typeName": "Supplier",
"id": "{GE5G1E8D-41F1-49A4-8412-QNG5EG48SG8S}"
}],
[{
"declaredClass": "geoscene.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Solar panel",
"panel_type": "Polycrystalline",
"price_per_unit": 400
},
"typeName": "Part",
"id": "{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}",
}]
]
构造函数
属性概述
可以设置、检索或侦听任何属性。请参阅使用属性主题。
名称 | 类型 | 描述 | 类 |
---|---|---|---|
String | 类的名称。 更多详情 | Accessor | |
ReadableStream | 匹配 executeSearchStreaming() 或 executeQueryStreaming() 条件的可读对象流。 更多详情 | GraphQueryStreamingResult |
属性详细信息
-
类的名称。声明的类名称格式化为
geoscene.folder.className
。
-
resultRowsStream ReadableStream
-
匹配 executeSearchStreaming() 或 executeQueryStreaming() 条件的可读对象流。需要使用 getReader() 方法进行解码。
示例// example of result decoding. // execute streaming query on a knowledge graph kgModule.executeQueryStreaming( kg, { openCypherQuery: "MATCH (n) RETURN n LIMIT 500", } ).then((streamingQueryResult) => { readStream(streamingQueryResult); }) //read the ReadableStream result const readStream = async (streamingQueryResult) => { let time = Date.now(); // create new stream reader let reader = streamingQueryResult.resultRowsStream.getReader(); try { // while the stream is returning data while (true) { const { done, value } = await reader.read(); // the stream has finished retrieving all matching records from the database if (done) { console.log("Client Query stream completed"); break; } // do something with the result records returned in each chunk console.log( `Client Query Result at Time ${Date.now() - time}:`, value ); } // if stream is aborted by user return message, otherwise throw error } catch (err) { if (err.name === "AbortError") { console.log("Request aborted as expected"); } else { throw err; } } };
方法概述
名称 | 返回值类值 | 描述 | 类 |
---|---|---|---|
添加一个或多个与对象的生命周期相关联的句柄。 更多详情 | Accessor | ||
Boolean | 如果存在指定的句柄组,则返回 true。 更多详情 | Accessor | |
移除对象拥有的句柄组。 更多详情 | Accessor |
方法详细说明
-
addHandles(handleOrHandles, groupKey)inherited
-
添加一个或多个与对象的生命周期相关联的句柄。当对象被销毁时,将移除句柄。
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); // Handle gets removed when the object is destroyed. this.addHandles(handle);
参数handleOrHandles WatchHandle|WatchHandle[]对象销毁后,标记为要移除的句柄。
groupKey *optional标识句柄应添加到的组的键。组中的所有句柄稍后都可使用 Accessor.removeHandles() 进行删除。如果未提供键,则句柄将被添加到默认组。
-
如果存在指定的句柄组,则返回 true。
参数groupKey *optional组键。
返回类型 描述 Boolean 如果存在指定的句柄组,则返回 true
。示例// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
removeHandles(groupKey)inherited
-
移除对象拥有的句柄组。
参数groupKey *optional要移除的组键或组键的数组或集合。
示例obj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");