require(["esri/rest/knowledgeGraph/GraphSearchStreaming"], (GraphSearchStreaming) => { /* code goes here */ });
import GraphSearchStreaming from "@arcgis/core/rest/knowledgeGraph/GraphSearchStreaming.js";
esri/rest/knowledgeGraph/GraphSearchStreaming
The search operation is performed on a knowledge graph service's
graph resource.
This operation allows you to search the properties of both entities and
relationships in the graph.
Any field with the text
data type or the Globally Unique Identifier (GUID) data type with the
searchable properties set to true
is included in the search.
A search index is built and maintained automatically on the values for all searchable fields.
Streaming search returns the result faster than search and in small chunks that can be rendered immediately. Streaming search also provides additional parameters to constrain the search.
// example GraphSearchStreaming used in a executeSearchStreaming
KnowledgeGraphModule.executeSearchStreaming(
knowledgeGraph,
{ // autocasts to new GraphSearchStreaming
searchQuery: "solar",
typeCategoryFilter: "both",
returnSearchContext: false,
start: 1, // index of first record to return
num: 200, // return 200 records.
namedTypesFilter: ["Company", "Supplier", "Part"],
idsFilter: ["{G4E8G2S8D-2GS5-98S4-3S5D-S1DE7G45DS48}",
"{FNWI1G5W-1A5W-3A5W-8412-A1W5F4W8F7AS}",
"{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}"]
}
).then((streamingSearchResult)=>{
// the result of a streaming search is a readableStream which requires decoding.
readStream(streamingSearchResult)
})
// 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)
}
} catch (err) {
if (err.name === "AbortError") {
console.log("Request aborted as expected");
} else {
throw err;
}
}
};
// sample result of read streaming search result chunk printed to the console
"Streaming chunk returned in: 0.082 seconds"
[
[{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Suncommon",
"Employee_Count": 400,
"energyType": "solar"
},
"typeName": "Company",
"id": "{G4E8G2S8D-2GS5-98S4-3S5D-S1DE7G45DS48}"
}],
[{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Quality Solar Supply",
"Supplier_code": "158B",
"City": "New Orleans",
},
"typeName": "Supplier",
"id": "{FNWI1G5W-1A5W-3A5W-8412-A1W5F4W8F7AS}"
}],
[{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Solar panel",
"panel_type": "Polycrystalline",
"price_per_unit": 400
},
"typeName": "Part",
"id": "{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}"
}]
]
Constructors
-
Parameterproperties Objectoptional
See the properties for a list of all the properties
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
The name of the class. | Accessor | ||
Specifies list of IDs to search. | GraphSearchStreaming | ||
Specifies list of names of entity types or relationship types to search. | GraphSearchStreaming | ||
The maximum number of results returned from the search. | GraphSearchStreaming | ||
If | GraphSearchStreaming | ||
The text to search for in the knowledge graph. | GraphSearch | ||
The index of the first result to return. | GraphSearchStreaming | ||
Specifies whether to search entities, relationships, or both. | GraphSearch |
Property Details
-
Specifies list of names of entity types or relationship types to search.
-
num
num Number
-
The maximum number of results returned from the search.
-
returnSearchContext
returnSearchContext Boolean
-
If
true
, returns the IDs of objects that match the search, the names of the properties that matched the search term, scores and highlights of the result set.- Default Value:false
-
searchQuery
InheritedPropertysearchQuery String
Inherited from GraphSearch -
The text to search for in the knowledge graph. Accepts Lucene search syntax.
Required
- knowledgeGraphService.executeSearch() will fail if not provided.
-
start
start Number
-
The index of the first result to return.
-
typeCategoryFilter
InheritedPropertytypeCategoryFilter String
Inherited from GraphSearch -
Specifies whether to search entities, relationships, or both. Valid values are
entity
,relationship
, orboth
.Note
- Check the service definition for the knowledgeGraphService (see ArcGIS REST APIs - Hosted Knowledge Graph Service) for valid values of
typeCategoryFilter
. Not all services supportboth
.
Required
- This property is required for the search to execute successfully. If the service does not support
both
one of the other options must be specified.
Possible Values:"entity" |"relationship" |"both"
- Default Value:"both"
- Check the service definition for the knowledgeGraphService (see ArcGIS REST APIs - Hosted Knowledge Graph Service) for valid values of
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
Returns true if a named group of handles exist. | Accessor | ||
Removes a group of handles owned by the object. | Accessor |
Method Details
-
Inherited from Accessor
-
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from Accessor -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
Inherited from Accessor
-
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");