create a full text index for the given label and attribute
| 677 | |
| 678 | // create a full text index for the given label and attribute |
| 679 | bool GraphContext_AddFullTextIndex |
| 680 | ( |
| 681 | Index *idx, // [input/output] index created |
| 682 | GraphContext *gc, // graph context |
| 683 | const char *label, // label of indexed entities |
| 684 | const char **fields, // fields to index |
| 685 | uint fields_count, // number of fields to index |
| 686 | double *weights, // fields weights |
| 687 | bool *nostems, // |
| 688 | const char **phonetics, // |
| 689 | char **stopwords, |
| 690 | const char *language |
| 691 | ) { |
| 692 | ASSERT(idx != NULL); |
| 693 | ASSERT(gc != NULL); |
| 694 | ASSERT(label != NULL); |
| 695 | ASSERT(fields != NULL); |
| 696 | ASSERT(fields_count > 0); |
| 697 | |
| 698 | // retrieve the schema for this label |
| 699 | ResultSet *result_set = QueryCtx_GetResultSet(); |
| 700 | bool index_changed = false; |
| 701 | Schema *s = GraphContext_GetSchema(gc, label, SCHEMA_NODE); |
| 702 | |
| 703 | if(s == NULL) { |
| 704 | s = GraphContext_AddSchema(gc, label, SCHEMA_NODE); |
| 705 | } |
| 706 | |
| 707 | for(uint i = 0; i < fields_count; i++) { |
| 708 | const char* field = fields[i]; |
| 709 | double weight = weights[i]; |
| 710 | bool nostem = nostems[i]; |
| 711 | const char *phonetic = phonetics[i]; |
| 712 | |
| 713 | IndexField index_field; |
| 714 | Attribute_ID f_id = GraphContext_FindOrAddAttribute(gc, field, NULL); |
| 715 | IndexField_New(&index_field, f_id, field, weight, nostem, phonetic); |
| 716 | if(Schema_AddIndex(idx, s, &index_field, IDX_FULLTEXT) == INDEX_OK) { |
| 717 | index_changed = true; |
| 718 | // update result-set |
| 719 | ResultSet_IndexCreated(result_set, INDEX_OK); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | if(stopwords != NULL) { |
| 724 | Index_SetStopwords(*idx, stopwords); |
| 725 | } |
| 726 | |
| 727 | if(language != NULL) { |
| 728 | Index_SetLanguage(*idx, language); |
| 729 | } |
| 730 | |
| 731 | // diable index if it was created |
| 732 | if(index_changed) { |
| 733 | Index_Disable(*idx); |
| 734 | } |
| 735 | |
| 736 | return index_changed; |
no test coverage detected