| 139 | } |
| 140 | |
| 141 | RSDoc *Index_IndexGraphEntity |
| 142 | ( |
| 143 | Index idx, |
| 144 | const GraphEntity *e, |
| 145 | const void *key, |
| 146 | size_t key_len, |
| 147 | uint *doc_field_count |
| 148 | ) { |
| 149 | ASSERT(idx != NULL); |
| 150 | ASSERT(e != NULL); |
| 151 | ASSERT(key != NULL); |
| 152 | ASSERT(doc_field_count != NULL); |
| 153 | ASSERT(key_len > 0); |
| 154 | |
| 155 | double score = 1; // default score |
| 156 | IndexField *field = NULL; // current indexed field |
| 157 | SIValue *v = NULL; // current indexed value |
| 158 | EntityID id = ENTITY_GET_ID(e); |
| 159 | uint field_count = array_len(idx->fields); |
| 160 | |
| 161 | *doc_field_count = 0; |
| 162 | |
| 163 | // list of none indexable fields |
| 164 | uint none_indexable_fields_count = 0; // number of none indexed fields |
| 165 | const char *none_indexable_fields[field_count]; // none indexed fields |
| 166 | |
| 167 | // create an empty document |
| 168 | RSDoc *doc = RediSearch_CreateDocument2(key, key_len, NULL, score, |
| 169 | idx->language); |
| 170 | |
| 171 | // add document field for each indexed property |
| 172 | if(idx->type == IDX_FULLTEXT) { |
| 173 | for(uint i = 0; i < field_count; i++) { |
| 174 | field = idx->fields + i; |
| 175 | const char *field_name = field->name; |
| 176 | v = GraphEntity_GetProperty(e, field->id); |
| 177 | if(v == ATTRIBUTE_NOTFOUND) continue; |
| 178 | |
| 179 | SIType t = SI_TYPE(*v); |
| 180 | |
| 181 | // value must be of type string |
| 182 | if(t == T_STRING) { |
| 183 | *doc_field_count += 1; |
| 184 | RediSearch_DocumentAddFieldString(doc, field_name, v->stringval, |
| 185 | strlen(v->stringval), RSFLDTYPE_FULLTEXT); |
| 186 | } |
| 187 | } |
| 188 | } else { |
| 189 | for(uint i = 0; i < field_count; i++) { |
| 190 | field = idx->fields + i; |
| 191 | const char *field_name = field->name; |
| 192 | v = GraphEntity_GetProperty(e, field->id); |
| 193 | if(v == ATTRIBUTE_NOTFOUND) continue; |
| 194 | |
| 195 | SIType t = SI_TYPE(*v); |
| 196 | |
| 197 | *doc_field_count += 1; |
| 198 | if(t == T_STRING) { |