Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.80 KB | None | 0 0
  1. <?php
  2.  
  3. namespace wpsolr\core\classes\models\post;
  4.  
  5.  
  6. use wpsolr\core\classes\engines\WPSOLR_AbstractIndexClient;
  7. use wpsolr\core\classes\models\WPSOLR_Model_Abstract;
  8. use wpsolr\core\classes\services\WPSOLR_Service_Container;
  9. use wpsolr\core\classes\WPSOLR_Events;
  10. use wpsolr\core\classes\WpSolrSchema;
  11.  
  12. /**
  13. * Class WPSOLR_Model_Post
  14. * @package wpsolr\core\classes\models
  15. */
  16. class WPSOLR_Model_Post extends WPSOLR_Model_Abstract {
  17.  
  18. /** @var \WP_Post */
  19. protected $data;
  20.  
  21. /**
  22. * @inheritdoc
  23. */
  24. public function get_id() {
  25. return $this->data->ID;
  26. }
  27.  
  28. /**
  29. * @inheritdoc
  30. */
  31. function get_type() {
  32. return $this->data->post_type;
  33. }
  34.  
  35. /**
  36. * @inheritdoc
  37. */
  38. public function get_date_modified() {
  39. return $this->data->post_modified;
  40. }
  41.  
  42. /**
  43. * @inheritdoc
  44. * @throws \Exception
  45. */
  46. public function create_document_from_model_or_attachment_inner( WPSOLR_AbstractIndexClient $search_engine_client, $attachment_body ) {
  47.  
  48. $post_to_index = $this->data;
  49.  
  50. $pauthor_id = $post_to_index->post_author;
  51. $ptitle = $post_to_index->post_title;
  52. // Post is NOT an attachment: we get the document body from the post object
  53. $pcontent = $post_to_index->post_content . ( empty( $attachment_body ) ? '' : ( '. ' . $attachment_body ) );
  54. $post_parent = isset( $post_to_index->post_parent ) ? $post_to_index->post_parent : 0;
  55.  
  56. $pexcerpt = $post_to_index->post_excerpt;
  57. $pauth_info = get_userdata( $pauthor_id );
  58. $pauthor = isset( $pauth_info ) && isset( $pauth_info->display_name ) ? $pauth_info->display_name : '';
  59. $pauthor_s = isset( $pauth_info ) && isset( $pauth_info->user_nicename ) ? get_author_posts_url( $pauth_info->ID, $pauth_info->user_nicename ) : '';
  60.  
  61. // Get the current post language
  62. $post_language = apply_filters( WPSOLR_Events::WPSOLR_FILTER_POST_LANGUAGE, null, $post_to_index );
  63.  
  64. $post_date = $search_engine_client->search_engine_client_format_date( $post_to_index->post_date );
  65. $post_date_gmt = solr_format_date( $post_to_index->post_date_gmt );
  66. $post_modified = $search_engine_client->search_engine_client_format_date( $post_to_index->post_modified );
  67. $post_modified_gmt = solr_format_date( $post_to_index->post_modified_gmt );
  68.  
  69. $purl = get_permalink( $this->data );
  70.  
  71. $comments_con = [];
  72.  
  73. $indexing_options = $search_engine_client->get_search_engine_indexing_options();
  74. $comm = isset( $indexing_options[ WpSolrSchema::_FIELD_NAME_COMMENTS ] ) ? $indexing_options[ WpSolrSchema::_FIELD_NAME_COMMENTS ] : '';
  75.  
  76. $numcomments = 0;
  77. if ( $comm ) {
  78. $comments_con = [];
  79.  
  80. $comments = get_comments( "status=approve&post_id={$post_to_index->ID}" );
  81. foreach ( $comments as $comment ) {
  82. array_push( $comments_con, $comment->comment_content );
  83. $numcomments += 1;
  84. }
  85.  
  86. }
  87. $pcomments = $comments_con;
  88. $pnumcomments = $numcomments;
  89.  
  90.  
  91. /*
  92. Get all custom categories selected for indexing, including 'category'
  93. */
  94. $cats = [];
  95. $categories_flat_hierarchies = [];
  96. $categories_non_flat_hierarchies = [];
  97. $aTaxo = WPSOLR_Service_Container::getOption()->get_option_index_taxonomies();
  98. $newTax = []; // Add categories by default
  99. if ( is_array( $aTaxo ) && count( $aTaxo ) ) {
  100. }
  101. foreach ( $aTaxo as $a ) {
  102.  
  103. if ( WpSolrSchema::_SOLR_DYNAMIC_TYPE_STRING === substr( $a, ( strlen( $a ) - 4 ), strlen( $a ) ) ) {
  104. $a = substr( $a, 0, ( strlen( $a ) - 4 ) );
  105. }
  106.  
  107. // Add only non empty categories
  108. if ( strlen( trim( $a ) ) > 0 ) {
  109. array_push( $newTax, $a );
  110. }
  111. }
  112.  
  113.  
  114. // Get all categories ot this post
  115. $terms = wp_get_post_terms( $post_to_index->ID, [ 'category' ], [ 'fields' => 'all_with_object_id' ] );
  116. if ( $terms && ! is_wp_error( $terms ) ) {
  117. foreach ( $terms as $term ) {
  118.  
  119. // Add category and it's parents
  120. $term_parents_names = [];
  121. // Add parents in reverse order ( top-bottom)
  122. $term_parents_ids = array_reverse( get_ancestors( $term->term_id, 'category' ) );
  123. array_push( $term_parents_ids, $term->term_id );
  124.  
  125. foreach ( $term_parents_ids as $term_parent_id ) {
  126. $term_parent = get_term( $term_parent_id, 'category' );
  127.  
  128. array_push( $term_parents_names, $term_parent->name );
  129.  
  130. // Add the term to the non-flat hierarchy (for filter queries on all the hierarchy levels)
  131. array_push( $categories_non_flat_hierarchies, $term_parent->name );
  132. }
  133.  
  134. // Add the term to the flat hierarchy
  135. array_push( $categories_flat_hierarchies, implode( WpSolrSchema::FACET_HIERARCHY_SEPARATOR, $term_parents_names ) );
  136.  
  137. // Add the term to the categories
  138. array_push( $cats, $term->name );
  139. }
  140. }
  141.  
  142. // Get all tags of this port
  143. $tag_array = [];
  144. $tags = get_the_tags( $post_to_index->ID );
  145. if ( ! $tags == null ) {
  146. foreach ( $tags as $tag ) {
  147. array_push( $tag_array, $tag->name );
  148.  
  149. }
  150. }
  151.  
  152. if ( $search_engine_client->get_is_in_galaxy() ) {
  153. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_BLOG_NAME_STR ] = $search_engine_client->get_galaxy_slave_filter_value();
  154. }
  155.  
  156. if ( ! empty( $post_parent ) ) {
  157. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_POST_PARENT_I ] = $post_parent;
  158. }
  159. if ( ! empty( $ptitle ) ) {
  160. // bbPress by default does not have reply titles and if no titles then no indexing with ES, topic indexing works nicely thought.
  161. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_TITLE ] = $ptitle;
  162. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_TITLE_S ] = $ptitle; // For sorting titles
  163. }
  164. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_STATUS_S ] = $post_to_index->post_status;
  165.  
  166. if ( isset( $indexing_options['p_excerpt'] ) && ( ! empty( $pexcerpt ) ) ) {
  167.  
  168. // Index post excerpt, by adding it to the post content.
  169. // Excerpt can therefore be: searched, autocompleted, highlighted.
  170. $pcontent .= WPSOLR_AbstractIndexClient::CONTENT_SEPARATOR . $pexcerpt;
  171. }
  172.  
  173. if ( ! empty( $pcomments ) ) {
  174.  
  175. // Index post comments, by adding it to the post content.
  176. // Excerpt can therefore be: searched, autocompleted, highlighted.
  177. //$pcontent .= self::CONTENT_SEPARATOR . implode( self::CONTENT_SEPARATOR, $pcomments );
  178. }
  179.  
  180.  
  181. $content_with_shortcodes_expanded_or_stripped = $pcontent;
  182. if ( isset( $indexing_options['is_shortcode_expanded'] ) && ( strpos( $pcontent, '[solr_search_shortcode]' ) === false ) ) {
  183.  
  184. // Expand shortcodes which have a plugin active, and are not the search form shortcode (else pb).
  185. global $post;
  186. $post = $post_to_index;
  187. $content_with_shortcodes_expanded_or_stripped = do_shortcode( $pcontent );
  188. }
  189.  
  190. // Remove shortcodes tags remaining, but not their content.
  191. // strip_shortcodes() does nothing, probably because shortcodes from themes are not loaded in admin.
  192. // Credit: https://wordpress.org/support/topic/stripping-shortcodes-keeping-the-content.
  193. // Modified to enable "/" in attributes
  194. $content_with_shortcodes_expanded_or_stripped = preg_replace( "~(?:\[/?)[^\]]+/?\]~s", '', $content_with_shortcodes_expanded_or_stripped ); # strip shortcodes, keep shortcode content;
  195.  
  196. // Remove HTML tags
  197. $stripped_content = strip_tags( $content_with_shortcodes_expanded_or_stripped );
  198. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CONTENT ] = ! empty( $stripped_content ) ? $stripped_content : ' '; // Prevent empty content error with ES
  199.  
  200. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_AUTHOR_ID_S ] = $pauthor_id;
  201. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_AUTHOR ] = $pauthor;
  202. $author_copy_to = $search_engine_client->copy_field_name( WpSolrSchema::_FIELD_NAME_AUTHOR );
  203. if ( WpSolrSchema::_FIELD_NAME_AUTHOR !== $author_copy_to ) {
  204. $this->solarium_document_for_update[ $author_copy_to ] = $pauthor;
  205. }
  206.  
  207.  
  208. if ( isset( $post_to_index->menu_order ) ) {
  209. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_MENU_ORDER_I ] = $post_to_index->menu_order;
  210. }
  211.  
  212. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_PID_I ] = $post_to_index->ID;
  213. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_AUTHOR_S ] = $pauthor_s;
  214.  
  215. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_POST_DATE ] = $post_date;
  216. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_DISPLAY_DATE_DT ] = $post_date;
  217. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_POST_DATE_GMT ] = $post_date_gmt;
  218. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_POST_MODIFIED ] = $post_modified;
  219. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_POST_MODIFIED_GMT ] = $post_modified_gmt;
  220.  
  221.  
  222. foreach (
  223. [
  224. WpSolrSchema::_FIELD_NAME_POST_MODIFIED_GMT,
  225. WpSolrSchema::_FIELD_NAME_POST_DATE,
  226. WpSolrSchema::_FIELD_NAME_DISPLAY_DATE_DT,
  227. WpSolrSchema::_FIELD_NAME_POST_MODIFIED,
  228. ] as $date_field
  229. ) {
  230.  
  231. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_YEAR_I ] =
  232. (int) date_i18n( 'Y', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  233.  
  234. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_YEAR_MONTH_I ] =
  235. (int) date_i18n( 'n', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  236.  
  237. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_YEAR_WEEK_I ] =
  238. (int) date_i18n( 'W', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  239.  
  240. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_YEAR_DAY_I ] =
  241. 1 + (int) date_i18n( 'z', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  242.  
  243. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_MONTH_DAY_I ] =
  244. (int) date_i18n( 'j', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  245.  
  246. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_WEEK_DAY_I ] =
  247. 1 + (int) date_i18n( 'N', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  248.  
  249.  
  250. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_DAY_HOUR_I ] =
  251. (int) date_i18n( 'G', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  252.  
  253. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_DAY_MINUTE_I ] =
  254. (int) date_i18n( 'i', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  255.  
  256. $this->solarium_document_for_update[ $date_field . WpSolrSchema::_FIELD_NAME_DAY_SECOND_I ] =
  257. (int) date_i18n( 's', strtotime( $this->solarium_document_for_update[ $date_field ] ) );
  258. }
  259.  
  260.  
  261. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_PERMALINK ] = $purl;
  262. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_COMMENTS ] = $pcomments;
  263. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_NUMBER_OF_COMMENTS ] = $pnumcomments;
  264.  
  265. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CATEGORIES_STR ] = $cats;
  266. $categories_copy_to = $search_engine_client->copy_field_name( WpSolrSchema::_FIELD_NAME_CATEGORIES );
  267. if ( WpSolrSchema::_FIELD_NAME_CATEGORIES_STR !== $categories_copy_to ) {
  268. $this->solarium_document_for_update[ $categories_copy_to ] = $cats;
  269. }
  270.  
  271. // Hierarchy of categories
  272. $this->solarium_document_for_update[ sprintf( WpSolrSchema::_FIELD_NAME_FLAT_HIERARCHY, WpSolrSchema::_FIELD_NAME_CATEGORIES_STR ) ] = $categories_flat_hierarchies;
  273. $this->solarium_document_for_update[ sprintf( WpSolrSchema::_FIELD_NAME_NON_FLAT_HIERARCHY, WpSolrSchema::_FIELD_NAME_CATEGORIES_STR ) ] = $categories_non_flat_hierarchies;
  274. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_TAGS ] = $tag_array;
  275. $tags_copy_to = $search_engine_client->copy_field_name( WpSolrSchema::_FIELD_NAME_TAGS );
  276. if ( WpSolrSchema::_FIELD_NAME_TAGS !== $tags_copy_to ) {
  277. $this->solarium_document_for_update[ $tags_copy_to ] = $tag_array;
  278. }
  279.  
  280. // Index post thumbnail
  281. $this->index_post_thumbnails( $solarium_document_for_update, $post_to_index->ID, $search_engine_client->get_is_in_galaxy() );
  282.  
  283. // Index post url
  284. $this->index_post_url( $solarium_document_for_update, $post_to_index->ID, $search_engine_client->get_is_in_galaxy() );
  285.  
  286. $taxonomies = (array) get_taxonomies( [ '_builtin' => false ], 'names' );
  287. foreach ( $taxonomies as $parent ) {
  288. if ( in_array( $parent, $newTax, true ) ) {
  289. $terms = get_the_terms( $post_to_index->ID, $parent );
  290. if ( (array) $terms === $terms ) {
  291. $parent = strtolower( str_replace( ' ', '_', $parent ) );
  292. $nm1 = $parent . WpSolrSchema::_SOLR_DYNAMIC_TYPE_STRING;
  293. $nm1_array = [];
  294.  
  295. $taxonomy_non_flat_hierarchies = [];
  296. $taxonomy_flat_hierarchies = [];
  297.  
  298. foreach ( $terms as $term ) {
  299.  
  300. // Add taxonomy and it's parents
  301. $term_parents_names = [];
  302. // Add parents in reverse order ( top-bottom)
  303. $term_parents_ids = array_reverse( get_ancestors( $term->term_id, $parent ) );
  304. array_push( $term_parents_ids, $term->term_id );
  305.  
  306. foreach ( $term_parents_ids as $term_parent_id ) {
  307. $term_parent = get_term( $term_parent_id, $parent );
  308.  
  309. if ( $term_parent instanceof \WP_Error ) {
  310. throw new \Exception( sprintf( 'WPSOLR: error on term %s for taxonomy \'%s\': %s', $term_parent_id, $parent, $term_parent->get_error_message() ) );
  311. }
  312.  
  313. if ( property_exists( $term_parent, 'name' ) ) {
  314.  
  315. array_push( $term_parents_names, $term_parent->name );
  316.  
  317. // Add the term to the non-flat hierarchy (for filter queries on all the hierarchy levels)
  318. array_push( $taxonomy_non_flat_hierarchies, $term_parent->name );
  319.  
  320. } else {
  321. // Some taxonomies do not have the property name. Probably due to bad imports.
  322.  
  323. throw new \Exception( sprintf( "WPSOLR: term %s for taxonomy %s has no name: %s", $term_parent_id, $parent, print_r( $term_parent, true ) ) );
  324. }
  325. }
  326.  
  327. // Add the term to the flat hierarchy
  328. array_push( $taxonomy_flat_hierarchies, implode( WpSolrSchema::FACET_HIERARCHY_SEPARATOR, $term_parents_names ) );
  329.  
  330. // Add the term to the taxonomy
  331. array_push( $nm1_array, $term->name );
  332.  
  333. // Add the term to the categories searchable
  334. array_push( $cats, $term->name );
  335.  
  336. }
  337.  
  338. if ( count( $nm1_array ) > 0 ) {
  339. $this->solarium_document_for_update[ $nm1 ] = $nm1_array;
  340. $nm1_copy_to = $search_engine_client->copy_field_name( $nm1 );
  341. if ( $nm1 !== $nm1_copy_to ) {
  342. $this->solarium_document_for_update[ $nm1_copy_to ] = $nm1_array;
  343. }
  344.  
  345.  
  346. $this->solarium_document_for_update[ sprintf( WpSolrSchema::_FIELD_NAME_FLAT_HIERARCHY, $nm1 ) ] = $taxonomy_flat_hierarchies;
  347. $this->solarium_document_for_update[ sprintf( WpSolrSchema::_FIELD_NAME_NON_FLAT_HIERARCHY, $nm1 ) ] = $taxonomy_non_flat_hierarchies;
  348.  
  349. }
  350. }
  351. }
  352. }
  353.  
  354. // Set categories and custom taxonomies as searchable
  355. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CATEGORIES ] = $cats;
  356.  
  357. // Add custom fields to the document
  358. $this->set_custom_fields( $search_engine_client, $solarium_document_for_update, $post_to_index );
  359.  
  360. if ( isset( $indexing_options['p_custom_fields'] ) && isset( $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CUSTOM_FIELDS ] ) ) {
  361.  
  362. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CONTENT ] .= WPSOLR_AbstractIndexClient::CONTENT_SEPARATOR . implode( ". ", $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CUSTOM_FIELDS ] );
  363. }
  364.  
  365.  
  366. return $solarium_document_for_update;
  367. }
  368.  
  369. /**
  370. * Set custom fields to the update document.
  371. * HTML and php tags are removed.
  372. *
  373. * @param WPSOLR_AbstractIndexClient $search_engine_client
  374. * @param $solarium_document_for_update
  375. * @param \WP_Post $post
  376. *
  377. * @throws \Exception
  378. */
  379. function set_custom_fields( WPSOLR_AbstractIndexClient $search_engine_client, &$solarium_document_for_update, $post ) {
  380.  
  381. $custom_fields = WPSOLR_Service_Container::getOption()->get_option_index_custom_fields();
  382.  
  383. if ( count( $custom_fields ) > 0 ) {
  384. if ( count( $post_custom_fields = get_post_custom( $post->ID ) ) ) {
  385.  
  386. // Apply filters on custom fields
  387. $post_custom_fields = apply_filters( WPSOLR_Events::WPSOLR_FILTER_POST_CUSTOM_FIELDS, $post_custom_fields, $post->ID );
  388.  
  389. $existing_custom_fields = isset( $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CUSTOM_FIELDS ] )
  390. ? $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CUSTOM_FIELDS ]
  391. : [];
  392.  
  393. foreach ( ! empty( $custom_fields[ $post->post_type ] ) ? $custom_fields[ $post->post_type ] : [] as $field_name_with_str_ending ) {
  394.  
  395. $field_name = WpSolrSchema::get_field_without_str_ending( $field_name_with_str_ending );
  396.  
  397. if ( isset( $post_custom_fields[ $field_name ] ) ) {
  398. $field = (array) $post_custom_fields[ $field_name ];
  399. $is_date_type = WpSolrSchema::get_custom_field_is_date_type( $field_name_with_str_ending );
  400.  
  401. $nm1 = WpSolrSchema::replace_field_name_extension( $field_name_with_str_ending );
  402. $array_nm1 = [];
  403. $array_unformatted_values = [];
  404. foreach ( $field as $field_value ) {
  405.  
  406. $field_value_sanitized = WpSolrSchema::get_sanitized_value( $search_engine_client, $field_name_with_str_ending, $field_value, $post );
  407.  
  408. // Only index the field if it has a value.
  409. if ( ( '0' === $field_value_sanitized ) || ! empty( $field_value_sanitized ) ) {
  410.  
  411. array_push( $array_nm1, $field_value_sanitized );
  412.  
  413. /**
  414. * Add un-formatted dates to the index (epoch formats can be used raw, as in Toolset Views custom field date filters)
  415. */
  416. if ( $is_date_type && WpSolrSchema::is_string_an_integer( $field_value ) ) {
  417. array_push( $array_unformatted_values, $field_value );
  418. }
  419.  
  420. // Add current custom field values to custom fields search field
  421. // $field being an array, we add each of it's element
  422. // Convert values to string, else error in the search engine if number, as a string is expected.
  423. array_push( $existing_custom_fields, is_array( $field_value_sanitized ) ? $field_value_sanitized : strval( $field_value_sanitized ) );
  424. }
  425. }
  426.  
  427. $this->solarium_document_for_update[ $nm1 ] = $array_nm1;
  428.  
  429. if ( ( WpSolrSchema::_SOLR_DYNAMIC_TYPE_TEXT !== WpSolrSchema::get_custom_field_dynamic_type( $field_name_with_str_ending ) ) ) {
  430. // Copy fields to _str, but _t fields (else immense field error)
  431. $nm1_copy = $search_engine_client->copy_field_name( $field_name_with_str_ending );
  432. if ( $nm1 !== $nm1_copy ) {
  433. $this->solarium_document_for_update[ $nm1_copy ] = $array_nm1;
  434. }
  435. }
  436.  
  437. if ( ! empty( $array_unformatted_values ) ) {
  438. // Add the epoch field content to a new integer field
  439. $this->solarium_document_for_update[ $field_name . WpSolrSchema::_SOLR_DYNAMIC_TYPE_INTEGER ] = $array_unformatted_values;
  440. }
  441. }
  442. }
  443.  
  444. if ( count( $existing_custom_fields ) > 0 ) {
  445. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_CUSTOM_FIELDS ] = $existing_custom_fields;
  446. }
  447.  
  448. }
  449.  
  450. }
  451.  
  452. }
  453.  
  454. /**
  455. * Index a post thumbnail
  456. *
  457. * @param $solarium_document_for_update
  458. * @param $post_id
  459. * @param bool $is_in_galaxy
  460. *
  461. * @return void
  462. */
  463. private
  464. function index_post_thumbnails(
  465. &$solarium_document_for_update, $post_id, $is_in_galaxy
  466. ) {
  467.  
  468. if ( $is_in_galaxy ) {
  469.  
  470. // Master must get thumbnails from the index, as the $post_id is not in local database
  471. $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ) );
  472. if ( false !== $thumbnail ) {
  473.  
  474. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_POST_THUMBNAIL_HREF_STR ] = $thumbnail[0];
  475. }
  476. }
  477.  
  478. }
  479.  
  480. /**
  481. * Index a post url
  482. *
  483. * @param $solarium_document_for_update
  484. * @param $post_id
  485. * @param bool $is_in_galaxy
  486. *
  487. * @return void
  488. */
  489. private
  490. function index_post_url(
  491. &$solarium_document_for_update, $post_id, $is_in_galaxy
  492. ) {
  493.  
  494. if ( $is_in_galaxy ) {
  495.  
  496. // Master must get urls from the index, as the $post_id is not in local database
  497. $url = get_permalink( $post_id );
  498. if ( false !== $url ) {
  499.  
  500. $this->solarium_document_for_update[ WpSolrSchema::_FIELD_NAME_POST_HREF_STR ] = $url;
  501. }
  502. }
  503. }
  504.  
  505. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement