Plugin Directory

Changeset 3259154


Ignore:
Timestamp:
03/20/2025 01:28:34 PM (12 months ago)
Author:
findkit
Message:

Update to version 1.4.0 from GitHub

Location:
findkit
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • findkit/tags/1.4.0/.gitignore

    r3022180 r3259154  
    55build/*.map
    66findkit.zip
     7.idea
  • findkit/tags/1.4.0/CHANGELOG.md

    r3246350 r3259154  
     1## v1.4.0
     2
     32025-03-20
     4
     5This is a breaking change in terms of error handling. Rather than throwing Exceptions, the public api php functions return WP_Error. More detailed errors will be logged if WP_DEBUG is defined.
     6
     7-   Change the way the plugin handles errors. Rather than throwing exceptions, log errors. [f76592f](https://github.com/findkit/wp-findkit/commit/f76592f) - Lauri Saarni
     8
     9
     10All changes https://github.com/findkit/wp-findkit/compare/v1.3.2...v1.4.0
     11
    112## v1.3.2
    213
  • findkit/tags/1.4.0/plugin.php

    r3246350 r3259154  
    1010 * Description: WordPress Plugin for Findkit Site Search. See findkit.com for details
    1111 * Author: Findkit Team <findkit@findkit.com>
    12  * Version: 1.3.2
     12 * Version: 1.4.0
    1313 * License: GPLv2 or later
    1414 */
     
    4242        );
    4343    });
     44
    4445    return;
    4546}
    4647
    4748\Findkit\Loader::instance();
     49
     50/**
     51 * Handle Findkit errors - logs the error if WP_DEBUG is enabled and returns a WP_Error object
     52 *
     53 * @param string $code Error code
     54 * @param string $message Error message
     55 * @param mixed $data Additional data for context
     56 *
     57 * @return WP_Error
     58 */
     59function findkit_handle_error($code, $message, $data = null)
     60{
     61    // Log the error if debugging is enabled
     62    if (defined('WP_DEBUG') && WP_DEBUG) {
     63        $log_message = '[WP Findkit Error] ' . $message;
     64        if ($data !== null) {
     65            $log_message .=
     66                ' | Data: ' .
     67                (is_string($data) ? $data : wp_json_encode($data));
     68        }
     69        error_log($log_message);
     70    }
     71
     72    // Return a WP_Error object
     73    return new WP_Error($code, $message, $data);
     74}
    4875
    4976/////////////////////////
     
    5380function findkit_full_crawl(array $options = [])
    5481{
    55     $loader = \Findkit\Loader::instance();
    56     $loader->api_client->full_crawl($options);
     82    try {
     83        $loader = \Findkit\Loader::instance();
     84
     85        return $loader->api_client->full_crawl($options);
     86    } catch (\Exception $e) {
     87        return findkit_handle_error(
     88            'findkit_full_crawl_failed',
     89            'Full crawl failed',
     90            ['error' => $e->getMessage()]
     91        );
     92    }
    5793}
    5894
    5995function findkit_manual_crawl(array $urls, array $options = [])
    6096{
    61     $loader = \Findkit\Loader::instance();
    62     $loader->api_client->manual_crawl($urls, $options);
     97    try {
     98        $loader = \Findkit\Loader::instance();
     99
     100        return $loader->api_client->manual_crawl($urls, $options);
     101    } catch (\Exception $e) {
     102        return findkit_handle_error(
     103            'findkit_manual_crawl_failed',
     104            'Manual crawl failed',
     105            ['error' => $e->getMessage()]
     106        );
     107    }
    63108}
    64109
    65110function findkit_partial_crawl(array $options = [])
    66111{
    67     $loader = \Findkit\Loader::instance();
    68     $loader->api_client->partial_crawl($options);
     112    try {
     113        $loader = \Findkit\Loader::instance();
     114
     115        return $loader->api_client->partial_crawl($options);
     116    } catch (\Exception $e) {
     117        return findkit_handle_error(
     118            'findkit_partial_crawl_failed',
     119            'Partial crawl failed',
     120            [
     121                'options' => $options,
     122                'error' => $e->getMessage(),
     123            ]
     124        );
     125    }
    69126}
    70127
    71128function findkit_get_page_meta(\WP_Post $post)
    72129{
    73     return Findkit\PageMeta::get($post);
     130    try {
     131        return Findkit\PageMeta::get($post);
     132    } catch (\Exception $e) {
     133        return findkit_handle_error(
     134            'findkit_page_meta_failed',
     135            'Failed to get page meta',
     136            [
     137                'post_id' => $post->ID,
     138                'error' => $e->getMessage(),
     139            ]
     140        );
     141    }
    74142}
    75143
     
    77145 * @param string $terms
    78146 * @param array|null $search_params search params https://docs.findkit.com/ui-api/ui.searchparams/
    79  * @return object
    80  * @throws \Exception
     147 * @param array|null $options
     148 *
     149 * @return array|WP_Error Returns search results or WP_Error on error
    81150 */
    82151function findkit_search(
     
    85154    array $options = null
    86155) {
    87     return findkit_search_groups(
    88         $terms,
    89         [$search_params ?? (object) []],
    90         $options
    91     )['groups'][0];
     156    try {
     157        $result = findkit_search_groups(
     158            $terms,
     159            [$search_params ?? (object) []],
     160            $options
     161        );
     162
     163        if (is_wp_error($result)) {
     164            return findkit_handle_error(
     165                'findkit_search_failed',
     166                'Search failed',
     167                [
     168                    'terms' => $terms,
     169                    'options' => $options,
     170                    'error' => $result->get_error_message(),
     171                ]
     172            );
     173        }
     174
     175        return $result['groups'][0] ?? [];
     176    } catch (\Exception $e) {
     177        return findkit_handle_error('findkit_search_failed', 'Search failed', [
     178            'terms' => $terms,
     179            'options' => $options,
     180            'error' => $e->getMessage(),
     181        ]);
     182    }
    92183}
    93184
    94185/**
    95186 * @param string $terms
    96  * @param array $groups array for findkit search params https://docs.findkit.com/ui-api/ui.searchparams/
    97  * @return array
    98  * @throws \Exception
    99  *
    100  * Example return value:
     187 * @param array|null $groups array for findkit search params https://docs.findkit.com/ui-api/ui.searchparams/
     188 * @param array|null $options
     189 *
     190 * @return array|WP_Error Returns search results or WP_Error on error
     191 *
     192 *  Example return value:
    101193 *  [
    102194 *  'duration' => 32,
    103195 *  'groups' => [
    104  *      [
    105  *          'total' => 1,
    106  *          'duration' => 7,
    107  *          'hits' => [
    108  *              [
    109  *                  'score' => 65.79195,
    110  *                  'superwordsMatch' => false,
    111  *                  'title' => 'How Findkit Scores Search Results?',
    112  *                  'language' => 'en',
    113  *                  'url' =>
    114  *                      'https://www.findkit.com/how-findkit-scores-search-results/',
    115  *                  'highlight' =>
    116  *                      'But what is an index and <em>how</em> the pages are <em>scored</em> when searching?',
    117  *                  'tags' => [
    118  *                      'wordpress',
    119  *                      'domain/www.findkit.com/wordpress',
    120  *                      'wp_blog_name/findkit',
    121  *                      'domain/www.findkit.com/wp_blog_name/findkit',
    122  *                      'public',
    123  *                      'wp_post_type/post',
    124  *                      'domain/www.findkit.com/wp_post_type/post',
    125  *                      'domain/www.findkit.com/wp_taxonomy/category/article',
    126  *                      'wp_taxonomy/category/article',
    127  *                      'domain/www.findkit.com',
    128  *                      'domain/findkit.com',
    129  *                      'language/en',
    130  *                  ],
    131  *                  'created' => '2024-05-20T07:44:47.000Z',
    132  *                  'modified' => '2024-05-20T10:49:11.000Z',
    133  *                  'customFields' => [
    134  *                      'wpPostId' => 34,
    135  *                      'author' => [
    136  *                          'type' => 'keyword',
    137  *                          'value' => 'Esa-Matti Suuronen',
    138  *                      ],
    139  *                      'excerpt' => [
    140  *                          'type' => 'keyword',
    141  *                          'value' =>
    142  *                              'Findkit is crawler based search toolkit which stores web pages to a search index. But what is an index and how the pages are scored when searching?',
    143  *                      ],
    144  *                  ],
    145  *              ],
    146  *          ],
    147  *      ],
    148  *    ],
     196 *      [
     197 *          'total' => 1,
     198 *          'duration' => 7,
     199 *          'hits' => [
     200 *              [
     201 *                  'score' => 65.79195,
     202 *                  'superwordsMatch' => false,
     203 *                  'title' => 'How Findkit Scores Search Results?',
     204 *                  'language' => 'en',
     205 *                  'url' =>
     206 *                      'https://www.findkit.com/how-findkit-scores-search-results/',
     207 *                  'highlight' =>
     208 *                      'But what is an index and <em>how</em> the pages are <em>scored</em> when searching?',
     209 *                  'tags' => [
     210 *                      'wordpress',
     211 *                      'domain/www.findkit.com/wordpress',
     212 *                      'wp_blog_name/findkit',
     213 *                      'domain/www.findkit.com/wp_blog_name/findkit',
     214 *                      'public',
     215 *                      'wp_post_type/post',
     216 *                      'domain/www.findkit.com/wp_post_type/post',
     217 *                      'domain/www.findkit.com/wp_taxonomy/category/article',
     218 *                      'wp_taxonomy/category/article',
     219 *                      'domain/www.findkit.com',
     220 *                      'domain/findkit.com',
     221 *                      'language/en',
     222 *                  ],
     223 *                  'created' => '2024-05-20T07:44:47.000Z',
     224 *                  'modified' => '2024-05-20T10:49:11.000Z',
     225 *                  'customFields' => [
     226 *                      'wpPostId' => 34,
     227 *                      'author' => [
     228 *                          'type' => 'keyword',
     229 *                          'value' => 'Esa-Matti Suuronen',
     230 *                      ],
     231 *                      'excerpt' => [
     232 *                          'type' => 'keyword',
     233 *                          'value' =>
     234 *                              'Findkit is crawler based search toolkit which stores web pages to a search index. But what is an index and how the pages are scored when searching?',
     235 *                      ],
     236 *                  ],
     237 *              ],
     238 *          ],
     239 *      ],
     240 *  ],
    149241 *  ];
     242 * /
    150243 */
    151244function findkit_search_groups(
     
    154247    $options = null
    155248) {
    156     $public_token =
    157         $options['publicToken'] ?? \get_option('findkit_project_id');
    158 
    159     if (!$public_token) {
    160         throw new \Exception('Findkit public token is not set, cannot search');
    161     }
    162 
    163     $subdomain = 'search';
    164     [$project_id, $region] = explode(':', $public_token);
    165 
    166     if ($region && $region !== 'eu-north-1') {
    167         $subdomain = "search-$region";
    168     }
    169 
    170     if (empty($groups)) {
    171         $groups = [(object) []];
    172     }
    173 
    174     $need_jwt = get_option('findkit_enable_jwt');
    175     if ($need_jwt) {
    176         $jwt = \Findkit\KeyPair::request_jwt_token();
    177         $qs = http_build_query(['p' => 'jwt:' . $jwt]);
    178     } else {
    179         $qs = http_build_query(['p' => $project_id]);
    180     }
    181 
    182     $response = wp_remote_post(
    183         "https://$subdomain.findkit.com/c/$project_id/search?" . $qs,
    184         [
    185             'method' => 'POST',
    186             'headers' => [
    187                 'content-type' => 'application/json',
    188             ],
    189             'body' => wp_json_encode([
    190                 'q' => $terms,
    191                 'groups' => $groups,
    192             ]),
    193         ]
    194     );
    195 
    196     if (is_wp_error($response)) {
    197         $error_message = $response->get_error_message();
    198         throw new \Exception(
    199             'Findkit request search failed: ' . $error_message
    200         );
    201     }
    202 
    203     $body = json_decode(wp_remote_retrieve_body($response), true);
    204     $status = wp_remote_retrieve_response_code($response);
    205 
    206     if ($status !== 200) {
    207         throw new \Exception(
    208             "Findkit search failed\nCODE: $status\nRESPONSE:\n" .
    209                 print_r($body, true)
    210         );
    211     }
    212 
    213     return $body;
    214 }
     249    try {
     250        $public_token =
     251            is_array($options) && isset($options['publicToken'])
     252                ? $options['publicToken']
     253                : \get_option('findkit_project_id');
     254
     255        if (!$public_token) {
     256            return findkit_handle_error(
     257                'findkit_public_token_missing',
     258                'Findkit public token is not set, cannot search',
     259                ['options' => $options]
     260            );
     261        }
     262
     263        $subdomain = 'search';
     264        $parts = explode(':', $public_token);
     265        $project_id = $parts[0];
     266        $region = $parts[1] ?? null;
     267
     268        if ($region && $region !== 'eu-north-1') {
     269            $subdomain = "search-$region";
     270        }
     271
     272        if (empty($groups)) {
     273            $groups = [(object) []];
     274        }
     275
     276        $need_jwt = get_option('findkit_enable_jwt');
     277        if ($need_jwt) {
     278            $jwt = \Findkit\KeyPair::request_jwt_token();
     279            $qs = http_build_query(['p' => 'jwt:' . $jwt]);
     280        } else {
     281            $qs = http_build_query(['p' => $project_id]);
     282        }
     283
     284        $response = wp_remote_post(
     285            "https://$subdomain.findkit.com/c/$project_id/search?" . $qs,
     286            [
     287                'method' => 'POST',
     288                'headers' => [
     289                    'content-type' => 'application/json',
     290                ],
     291                'body' => wp_json_encode([
     292                    'q' => $terms,
     293                    'groups' => $groups,
     294                ]),
     295            ]
     296        );
     297
     298        if (is_wp_error($response)) {
     299            $error_message = $response->get_error_message();
     300            return findkit_handle_error(
     301                'Findkit request search failed',
     302                $error_message
     303            );
     304        }
     305
     306        $body = json_decode(wp_remote_retrieve_body($response), true);
     307        $status = wp_remote_retrieve_response_code($response);
     308
     309        if ($status !== 200) {
     310            return findkit_handle_error(
     311                'findkit_search_response_status',
     312                "Findkit search failed with status {$status}",
     313                $body
     314            );
     315        }
     316
     317        return $body;
     318    } catch (\Exception $e) {
     319        return findkit_handle_error(
     320            'findkit_search_groups_failed',
     321            'Search groups failed',
     322            [
     323                'terms' => $terms,
     324                'error' => $e->getMessage(),
     325            ]
     326        );
     327    }
     328}
  • findkit/tags/1.4.0/readme.txt

    r3246350 r3259154  
    44Requires at least: 6.0
    55Tested up to: 6.7.1
    6 Stable tag: 1.3.2
     6Stable tag: 1.4.0
    77Requires PHP: 7.2
    88Donate link: https://www.findkit.com/
  • findkit/tags/1.4.0/src/LiveUpdate.php

    r3008106 r3259154  
    9898        $can_live_update = apply_filters(
    9999            'findkit_can_live_update_post',
    100             // By default do not equeue post in cli because integrations might
     100            // By default, do not equeue post in cli because integrations might
    101101            // cause unwanted live updates
    102102            php_sapi_name() !== 'cli' &&
  • findkit/tags/1.4.0/vendor/composer/installed.php

    r3246350 r3259154  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => 'bb343e6e424e489bbafae5af8cd33b9351d965a8',
     6        'reference' => 'ed4e36a64783c7a3ce7909a3a340de529fb6a766',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => 'bb343e6e424e489bbafae5af8cd33b9351d965a8',
     16            'reference' => 'ed4e36a64783c7a3ce7909a3a340de529fb6a766',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
  • findkit/trunk/.gitignore

    r3022180 r3259154  
    55build/*.map
    66findkit.zip
     7.idea
  • findkit/trunk/CHANGELOG.md

    r3246350 r3259154  
     1## v1.4.0
     2
     32025-03-20
     4
     5This is a breaking change in terms of error handling. Rather than throwing Exceptions, the public api php functions return WP_Error. More detailed errors will be logged if WP_DEBUG is defined.
     6
     7-   Change the way the plugin handles errors. Rather than throwing exceptions, log errors. [f76592f](https://github.com/findkit/wp-findkit/commit/f76592f) - Lauri Saarni
     8
     9
     10All changes https://github.com/findkit/wp-findkit/compare/v1.3.2...v1.4.0
     11
    112## v1.3.2
    213
  • findkit/trunk/plugin.php

    r3246350 r3259154  
    1010 * Description: WordPress Plugin for Findkit Site Search. See findkit.com for details
    1111 * Author: Findkit Team <findkit@findkit.com>
    12  * Version: 1.3.2
     12 * Version: 1.4.0
    1313 * License: GPLv2 or later
    1414 */
     
    4242        );
    4343    });
     44
    4445    return;
    4546}
    4647
    4748\Findkit\Loader::instance();
     49
     50/**
     51 * Handle Findkit errors - logs the error if WP_DEBUG is enabled and returns a WP_Error object
     52 *
     53 * @param string $code Error code
     54 * @param string $message Error message
     55 * @param mixed $data Additional data for context
     56 *
     57 * @return WP_Error
     58 */
     59function findkit_handle_error($code, $message, $data = null)
     60{
     61    // Log the error if debugging is enabled
     62    if (defined('WP_DEBUG') && WP_DEBUG) {
     63        $log_message = '[WP Findkit Error] ' . $message;
     64        if ($data !== null) {
     65            $log_message .=
     66                ' | Data: ' .
     67                (is_string($data) ? $data : wp_json_encode($data));
     68        }
     69        error_log($log_message);
     70    }
     71
     72    // Return a WP_Error object
     73    return new WP_Error($code, $message, $data);
     74}
    4875
    4976/////////////////////////
     
    5380function findkit_full_crawl(array $options = [])
    5481{
    55     $loader = \Findkit\Loader::instance();
    56     $loader->api_client->full_crawl($options);
     82    try {
     83        $loader = \Findkit\Loader::instance();
     84
     85        return $loader->api_client->full_crawl($options);
     86    } catch (\Exception $e) {
     87        return findkit_handle_error(
     88            'findkit_full_crawl_failed',
     89            'Full crawl failed',
     90            ['error' => $e->getMessage()]
     91        );
     92    }
    5793}
    5894
    5995function findkit_manual_crawl(array $urls, array $options = [])
    6096{
    61     $loader = \Findkit\Loader::instance();
    62     $loader->api_client->manual_crawl($urls, $options);
     97    try {
     98        $loader = \Findkit\Loader::instance();
     99
     100        return $loader->api_client->manual_crawl($urls, $options);
     101    } catch (\Exception $e) {
     102        return findkit_handle_error(
     103            'findkit_manual_crawl_failed',
     104            'Manual crawl failed',
     105            ['error' => $e->getMessage()]
     106        );
     107    }
    63108}
    64109
    65110function findkit_partial_crawl(array $options = [])
    66111{
    67     $loader = \Findkit\Loader::instance();
    68     $loader->api_client->partial_crawl($options);
     112    try {
     113        $loader = \Findkit\Loader::instance();
     114
     115        return $loader->api_client->partial_crawl($options);
     116    } catch (\Exception $e) {
     117        return findkit_handle_error(
     118            'findkit_partial_crawl_failed',
     119            'Partial crawl failed',
     120            [
     121                'options' => $options,
     122                'error' => $e->getMessage(),
     123            ]
     124        );
     125    }
    69126}
    70127
    71128function findkit_get_page_meta(\WP_Post $post)
    72129{
    73     return Findkit\PageMeta::get($post);
     130    try {
     131        return Findkit\PageMeta::get($post);
     132    } catch (\Exception $e) {
     133        return findkit_handle_error(
     134            'findkit_page_meta_failed',
     135            'Failed to get page meta',
     136            [
     137                'post_id' => $post->ID,
     138                'error' => $e->getMessage(),
     139            ]
     140        );
     141    }
    74142}
    75143
     
    77145 * @param string $terms
    78146 * @param array|null $search_params search params https://docs.findkit.com/ui-api/ui.searchparams/
    79  * @return object
    80  * @throws \Exception
     147 * @param array|null $options
     148 *
     149 * @return array|WP_Error Returns search results or WP_Error on error
    81150 */
    82151function findkit_search(
     
    85154    array $options = null
    86155) {
    87     return findkit_search_groups(
    88         $terms,
    89         [$search_params ?? (object) []],
    90         $options
    91     )['groups'][0];
     156    try {
     157        $result = findkit_search_groups(
     158            $terms,
     159            [$search_params ?? (object) []],
     160            $options
     161        );
     162
     163        if (is_wp_error($result)) {
     164            return findkit_handle_error(
     165                'findkit_search_failed',
     166                'Search failed',
     167                [
     168                    'terms' => $terms,
     169                    'options' => $options,
     170                    'error' => $result->get_error_message(),
     171                ]
     172            );
     173        }
     174
     175        return $result['groups'][0] ?? [];
     176    } catch (\Exception $e) {
     177        return findkit_handle_error('findkit_search_failed', 'Search failed', [
     178            'terms' => $terms,
     179            'options' => $options,
     180            'error' => $e->getMessage(),
     181        ]);
     182    }
    92183}
    93184
    94185/**
    95186 * @param string $terms
    96  * @param array $groups array for findkit search params https://docs.findkit.com/ui-api/ui.searchparams/
    97  * @return array
    98  * @throws \Exception
    99  *
    100  * Example return value:
     187 * @param array|null $groups array for findkit search params https://docs.findkit.com/ui-api/ui.searchparams/
     188 * @param array|null $options
     189 *
     190 * @return array|WP_Error Returns search results or WP_Error on error
     191 *
     192 *  Example return value:
    101193 *  [
    102194 *  'duration' => 32,
    103195 *  'groups' => [
    104  *      [
    105  *          'total' => 1,
    106  *          'duration' => 7,
    107  *          'hits' => [
    108  *              [
    109  *                  'score' => 65.79195,
    110  *                  'superwordsMatch' => false,
    111  *                  'title' => 'How Findkit Scores Search Results?',
    112  *                  'language' => 'en',
    113  *                  'url' =>
    114  *                      'https://www.findkit.com/how-findkit-scores-search-results/',
    115  *                  'highlight' =>
    116  *                      'But what is an index and <em>how</em> the pages are <em>scored</em> when searching?',
    117  *                  'tags' => [
    118  *                      'wordpress',
    119  *                      'domain/www.findkit.com/wordpress',
    120  *                      'wp_blog_name/findkit',
    121  *                      'domain/www.findkit.com/wp_blog_name/findkit',
    122  *                      'public',
    123  *                      'wp_post_type/post',
    124  *                      'domain/www.findkit.com/wp_post_type/post',
    125  *                      'domain/www.findkit.com/wp_taxonomy/category/article',
    126  *                      'wp_taxonomy/category/article',
    127  *                      'domain/www.findkit.com',
    128  *                      'domain/findkit.com',
    129  *                      'language/en',
    130  *                  ],
    131  *                  'created' => '2024-05-20T07:44:47.000Z',
    132  *                  'modified' => '2024-05-20T10:49:11.000Z',
    133  *                  'customFields' => [
    134  *                      'wpPostId' => 34,
    135  *                      'author' => [
    136  *                          'type' => 'keyword',
    137  *                          'value' => 'Esa-Matti Suuronen',
    138  *                      ],
    139  *                      'excerpt' => [
    140  *                          'type' => 'keyword',
    141  *                          'value' =>
    142  *                              'Findkit is crawler based search toolkit which stores web pages to a search index. But what is an index and how the pages are scored when searching?',
    143  *                      ],
    144  *                  ],
    145  *              ],
    146  *          ],
    147  *      ],
    148  *    ],
     196 *      [
     197 *          'total' => 1,
     198 *          'duration' => 7,
     199 *          'hits' => [
     200 *              [
     201 *                  'score' => 65.79195,
     202 *                  'superwordsMatch' => false,
     203 *                  'title' => 'How Findkit Scores Search Results?',
     204 *                  'language' => 'en',
     205 *                  'url' =>
     206 *                      'https://www.findkit.com/how-findkit-scores-search-results/',
     207 *                  'highlight' =>
     208 *                      'But what is an index and <em>how</em> the pages are <em>scored</em> when searching?',
     209 *                  'tags' => [
     210 *                      'wordpress',
     211 *                      'domain/www.findkit.com/wordpress',
     212 *                      'wp_blog_name/findkit',
     213 *                      'domain/www.findkit.com/wp_blog_name/findkit',
     214 *                      'public',
     215 *                      'wp_post_type/post',
     216 *                      'domain/www.findkit.com/wp_post_type/post',
     217 *                      'domain/www.findkit.com/wp_taxonomy/category/article',
     218 *                      'wp_taxonomy/category/article',
     219 *                      'domain/www.findkit.com',
     220 *                      'domain/findkit.com',
     221 *                      'language/en',
     222 *                  ],
     223 *                  'created' => '2024-05-20T07:44:47.000Z',
     224 *                  'modified' => '2024-05-20T10:49:11.000Z',
     225 *                  'customFields' => [
     226 *                      'wpPostId' => 34,
     227 *                      'author' => [
     228 *                          'type' => 'keyword',
     229 *                          'value' => 'Esa-Matti Suuronen',
     230 *                      ],
     231 *                      'excerpt' => [
     232 *                          'type' => 'keyword',
     233 *                          'value' =>
     234 *                              'Findkit is crawler based search toolkit which stores web pages to a search index. But what is an index and how the pages are scored when searching?',
     235 *                      ],
     236 *                  ],
     237 *              ],
     238 *          ],
     239 *      ],
     240 *  ],
    149241 *  ];
     242 * /
    150243 */
    151244function findkit_search_groups(
     
    154247    $options = null
    155248) {
    156     $public_token =
    157         $options['publicToken'] ?? \get_option('findkit_project_id');
    158 
    159     if (!$public_token) {
    160         throw new \Exception('Findkit public token is not set, cannot search');
    161     }
    162 
    163     $subdomain = 'search';
    164     [$project_id, $region] = explode(':', $public_token);
    165 
    166     if ($region && $region !== 'eu-north-1') {
    167         $subdomain = "search-$region";
    168     }
    169 
    170     if (empty($groups)) {
    171         $groups = [(object) []];
    172     }
    173 
    174     $need_jwt = get_option('findkit_enable_jwt');
    175     if ($need_jwt) {
    176         $jwt = \Findkit\KeyPair::request_jwt_token();
    177         $qs = http_build_query(['p' => 'jwt:' . $jwt]);
    178     } else {
    179         $qs = http_build_query(['p' => $project_id]);
    180     }
    181 
    182     $response = wp_remote_post(
    183         "https://$subdomain.findkit.com/c/$project_id/search?" . $qs,
    184         [
    185             'method' => 'POST',
    186             'headers' => [
    187                 'content-type' => 'application/json',
    188             ],
    189             'body' => wp_json_encode([
    190                 'q' => $terms,
    191                 'groups' => $groups,
    192             ]),
    193         ]
    194     );
    195 
    196     if (is_wp_error($response)) {
    197         $error_message = $response->get_error_message();
    198         throw new \Exception(
    199             'Findkit request search failed: ' . $error_message
    200         );
    201     }
    202 
    203     $body = json_decode(wp_remote_retrieve_body($response), true);
    204     $status = wp_remote_retrieve_response_code($response);
    205 
    206     if ($status !== 200) {
    207         throw new \Exception(
    208             "Findkit search failed\nCODE: $status\nRESPONSE:\n" .
    209                 print_r($body, true)
    210         );
    211     }
    212 
    213     return $body;
    214 }
     249    try {
     250        $public_token =
     251            is_array($options) && isset($options['publicToken'])
     252                ? $options['publicToken']
     253                : \get_option('findkit_project_id');
     254
     255        if (!$public_token) {
     256            return findkit_handle_error(
     257                'findkit_public_token_missing',
     258                'Findkit public token is not set, cannot search',
     259                ['options' => $options]
     260            );
     261        }
     262
     263        $subdomain = 'search';
     264        $parts = explode(':', $public_token);
     265        $project_id = $parts[0];
     266        $region = $parts[1] ?? null;
     267
     268        if ($region && $region !== 'eu-north-1') {
     269            $subdomain = "search-$region";
     270        }
     271
     272        if (empty($groups)) {
     273            $groups = [(object) []];
     274        }
     275
     276        $need_jwt = get_option('findkit_enable_jwt');
     277        if ($need_jwt) {
     278            $jwt = \Findkit\KeyPair::request_jwt_token();
     279            $qs = http_build_query(['p' => 'jwt:' . $jwt]);
     280        } else {
     281            $qs = http_build_query(['p' => $project_id]);
     282        }
     283
     284        $response = wp_remote_post(
     285            "https://$subdomain.findkit.com/c/$project_id/search?" . $qs,
     286            [
     287                'method' => 'POST',
     288                'headers' => [
     289                    'content-type' => 'application/json',
     290                ],
     291                'body' => wp_json_encode([
     292                    'q' => $terms,
     293                    'groups' => $groups,
     294                ]),
     295            ]
     296        );
     297
     298        if (is_wp_error($response)) {
     299            $error_message = $response->get_error_message();
     300            return findkit_handle_error(
     301                'Findkit request search failed',
     302                $error_message
     303            );
     304        }
     305
     306        $body = json_decode(wp_remote_retrieve_body($response), true);
     307        $status = wp_remote_retrieve_response_code($response);
     308
     309        if ($status !== 200) {
     310            return findkit_handle_error(
     311                'findkit_search_response_status',
     312                "Findkit search failed with status {$status}",
     313                $body
     314            );
     315        }
     316
     317        return $body;
     318    } catch (\Exception $e) {
     319        return findkit_handle_error(
     320            'findkit_search_groups_failed',
     321            'Search groups failed',
     322            [
     323                'terms' => $terms,
     324                'error' => $e->getMessage(),
     325            ]
     326        );
     327    }
     328}
  • findkit/trunk/readme.txt

    r3246350 r3259154  
    44Requires at least: 6.0
    55Tested up to: 6.7.1
    6 Stable tag: 1.3.2
     6Stable tag: 1.4.0
    77Requires PHP: 7.2
    88Donate link: https://www.findkit.com/
  • findkit/trunk/src/LiveUpdate.php

    r3008106 r3259154  
    9898        $can_live_update = apply_filters(
    9999            'findkit_can_live_update_post',
    100             // By default do not equeue post in cli because integrations might
     100            // By default, do not equeue post in cli because integrations might
    101101            // cause unwanted live updates
    102102            php_sapi_name() !== 'cli' &&
  • findkit/trunk/vendor/composer/installed.php

    r3246350 r3259154  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => 'bb343e6e424e489bbafae5af8cd33b9351d965a8',
     6        'reference' => 'ed4e36a64783c7a3ce7909a3a340de529fb6a766',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => 'bb343e6e424e489bbafae5af8cd33b9351d965a8',
     16            'reference' => 'ed4e36a64783c7a3ce7909a3a340de529fb6a766',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.