add an exact match index to schema
| 15 | |
| 16 | // add an exact match index to schema |
| 17 | static 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 |
| 68 | static int Schema_AddFullTextIndex |
no test coverage detected