* Serializes the IndexKey to a GetIndexes friendly manner. * Returns any additional Text indexes that were captured from processing * the index keys. */
| 2443 | * the index keys. |
| 2444 | */ |
| 2445 | static List * |
| 2446 | WriteIndexKeyForGetIndexes(pgbson_writer *writer, pgbson *keyDocument) |
| 2447 | { |
| 2448 | bson_iter_t iter; |
| 2449 | PgbsonInitIterator(keyDocument, &iter); |
| 2450 | |
| 2451 | bool writtenTextColumn = false; |
| 2452 | pgbson_writer nestedWriter; |
| 2453 | PgbsonWriterStartDocument(writer, "key", 3, &nestedWriter); |
| 2454 | |
| 2455 | List *fullTextColumns = NIL; |
| 2456 | |
| 2457 | while (bson_iter_next(&iter)) |
| 2458 | { |
| 2459 | StringView keyView = bson_iter_key_string_view(&iter); |
| 2460 | const bson_value_t *value = bson_iter_value(&iter); |
| 2461 | |
| 2462 | /* We only care about text indexes here.*/ |
| 2463 | if (IsTextIndex(value)) |
| 2464 | { |
| 2465 | /* |
| 2466 | * For text, we insert a well-known metadata here |
| 2467 | * key: { _fts: 'text', _ftsx: 1 } |
| 2468 | * The actual keys go in "weights as an option" |
| 2469 | */ |
| 2470 | if (!writtenTextColumn) |
| 2471 | { |
| 2472 | PgbsonWriterAppendUtf8(&nestedWriter, "_fts", 4, "text"); |
| 2473 | PgbsonWriterAppendInt32(&nestedWriter, "_ftsx", 5, 1); |
| 2474 | writtenTextColumn = true; |
| 2475 | } |
| 2476 | |
| 2477 | if (strcmp(keyView.string, "_fts") != 0) |
| 2478 | { |
| 2479 | /* Store the columns for later (weights) */ |
| 2480 | TextIndexWeights *weights = palloc0(sizeof(TextIndexWeights)); |
| 2481 | weights->path = keyView.string; |
| 2482 | weights->weight = 1.0; |
| 2483 | fullTextColumns = lappend(fullTextColumns, (void *) weights); |
| 2484 | } |
| 2485 | } |
| 2486 | else |
| 2487 | { |
| 2488 | if (strcmp(keyView.string, "_ftsx") != 0) |
| 2489 | { |
| 2490 | PgbsonWriterAppendValue(&nestedWriter, keyView.string, keyView.length, |
| 2491 | value); |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | PgbsonWriterEndDocument(writer, &nestedWriter); |
| 2497 | return fullTextColumns; |
| 2498 | } |
| 2499 | |
| 2500 | |
| 2501 | /* |
no test coverage detected