MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / GraphContext_AddExactMatchIndex

Function GraphContext_AddExactMatchIndex

src/graph/graphcontext.c:621–676  ·  view source on GitHub ↗

create an exact match index for the given label and attribute

Source from the content-addressed store, hash-verified

619
620// create an exact match index for the given label and attribute
621bool GraphContext_AddExactMatchIndex
622(
623 Index *idx, // [input/output] index created
624 GraphContext *gc, // graph context
625 SchemaType schema_type, // type of entities to index nodes/edges
626 const char *label, // label of indexed entities
627 const char **fields_str, // fields to index
628 uint fields_count, // number of fields to index
629 bool should_reply // should reply to client
630) {
631 ASSERT(idx != NULL);
632 ASSERT(gc != NULL);
633 ASSERT(label != NULL);
634 ASSERT(fields_str != NULL);
635 ASSERT(fields_count > 0);
636
637 // retrieve the schema for this label
638 bool index_changed = false;
639 Schema *s = GraphContext_GetSchema(gc, label, schema_type);
640 ResultSet *result_set = should_reply ? QueryCtx_GetResultSet() : NULL;
641
642 if(s == NULL) {
643 // schema doesn't exists, create it
644 s = GraphContext_AddSchema(gc, label, schema_type);
645 }
646
647 for(uint i = 0; i < fields_count; i++) {
648 // create index field
649 const char *field = fields_str[i];
650 IndexField idx_field;
651 Attribute_ID f_id = GraphContext_FindOrAddAttribute(gc, field, NULL);
652 IndexField_Default(&idx_field, f_id, field);
653 if(Schema_AddIndex(idx, s, &idx_field, IDX_EXACT_MATCH) == INDEX_OK) {
654 index_changed = true;
655 if(should_reply) {
656 // update result-set
657 ResultSet_IndexCreated(result_set, INDEX_OK);
658 }
659 }
660 }
661
662 // disable index if it was created
663 // we don't call Index_Disable within Schema_AddIndex as multiple
664 // field additions are still considered a "single" modification
665 // of the index
666 if(index_changed) {
667 Index_Disable(*idx);
668 } else {
669 if(should_reply) {
670 // update result-set
671 ResultSet_IndexCreated(result_set, INDEX_FAIL);
672 }
673 }
674
675 return index_changed;
676}
677
678// create a full text index for the given label and attribute

Callers 1

_index_operation_createFunction · 0.85

Calls 7

GraphContext_GetSchemaFunction · 0.85
QueryCtx_GetResultSetFunction · 0.85
GraphContext_AddSchemaFunction · 0.85
Schema_AddIndexFunction · 0.85
ResultSet_IndexCreatedFunction · 0.85
Index_DisableFunction · 0.85

Tested by

no test coverage detected