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

Function Schema_AddExactMatchIndex

src/schema/schema.c:17–65  ·  view source on GitHub ↗

add an exact match index to schema

Source from the content-addressed store, hash-verified

15
16// add an exact match index to schema
17static int Schema_AddExactMatchIndex
18(
19 Index *idx, // [input/output] index to create
20 Schema *s, // schema holding the index
21 IndexField *field // field to index
22) {
23 ASSERT(s != NULL);
24 ASSERT(idx != NULL);
25 ASSERT(field != NULL);
26
27 // see if index already exists
28 Index _idx = NULL;
29 GraphEntityType et = (s->type == SCHEMA_NODE) ? GETYPE_NODE : GETYPE_EDGE;
30
31 //--------------------------------------------------------------------------
32 // determine which index to populate
33 //--------------------------------------------------------------------------
34
35 // if pending-index exists, reuse it
36 // if active-index exists, clone it and use clone
37 // otherwise (first index) create a new index
38 Index active = ACTIVE_EXACTMATCH_IDX(s);
39 Index pending = PENDING_EXACTMATCH_IDX(s);
40 Index altered = (pending != NULL) ? pending : active;
41
42 if(altered != NULL) {
43 // make sure attribute isn't already indexed
44 if(Index_ContainsAttribute(altered, field->id)) {
45 // field already indexed, quick return
46 IndexField_Free(field);
47 return INDEX_FAIL;
48 }
49 }
50
51 _idx = pending;
52 if(pending == NULL) {
53 if(active != NULL) {
54 _idx = Index_Clone(active);
55 } else {
56 _idx = Index_New(s->name, s->id, IDX_EXACT_MATCH, et);
57 }
58 }
59 PENDING_EXACTMATCH_IDX(s) = _idx; // set pending exact-match index
60
61 Index_AddField(_idx, field);
62
63 *idx = _idx;
64 return INDEX_OK;
65}
66
67// add a full-text index to schema
68static int Schema_AddFullTextIndex

Callers 1

Schema_AddIndexFunction · 0.85

Calls 5

Index_ContainsAttributeFunction · 0.85
IndexField_FreeFunction · 0.85
Index_CloneFunction · 0.85
Index_NewFunction · 0.85
Index_AddFieldFunction · 0.85

Tested by

no test coverage detected