-
Notifications
You must be signed in to change notification settings - Fork 114
Indexing ACF Fields #680
Comments
I was that I can adjust the indexing settings and Any ideas on how to optimize the data? I'm adding the custom fields data in a separate attribute through Here's the function that I have: <?php
public function algolia__addACFFields( $attributes, $post ) {
$postID = $post->ID;
$template = get_page_template_slug( $postID );
$template = str_replace( 'templates/', '', $template );
$template = str_replace( '.php', '', $template );
$content = '';
switch ( $template )
{
case 'take-action':
$fields = array( 'feature_action', 'act_online', 'act_locally', 'clean_living_tips', 'volunteer' );
foreach ( $fields as $key => $value )
{
$group = get_field( $value, $postID );
if ( isset( $group[ 'headline' ] ) && !empty( $group[ 'headline' ] ) )
{
$content .= $group[ 'headline' ] . ' ';
}
if ( isset( $group[ 'title' ] ) && !empty( $group[ 'title' ] ) )
{
$content .= $group[ 'title' ] . ' ';
}
$content .= strip_tags( $group[ 'content' ] ) . ' ';
}
break;
case 'experts':
$experts = get_field( 'experts_listing', $postID );
if ( empty( $experts ) )
{
continue;
}
$experts = $experts[0][ 'experts' ];
foreach ( $experts as $key => $expert )
{
$args[ 'term_taxonomy_id' ] = $expert;
$term = get_term( $expert, 'expert' );
$content .= $term->name . ' ' . $term->description . ' ';
}
break;
default:
// code...
break;
}
if ( !empty( $content ) )
{
$attributes[ 'extra_content' ] = $content;
}
if ( get_post_type( $postID ) != 'page' )
{
return $attributes;
}
$blocks = get_field( 'blocks', $postID );
if ( !empty( $blocks ) )
{
$blockContent = '';
foreach ( $blocks as $key => $block )
{
$layout = $block[ 'acf_fc_layout' ];
if ( isset( $block[ 'title' ] ) && !empty( $block[ 'title' ] ) )
{
$blockContent .= $block[ 'title' ] . ' ';
}
if ( isset( $block[ 'content' ] ) && !empty( $block[ 'content' ] ) )
{
$blockContent .= strip_tags( $block[ 'content' ] ) . ' ';
}
if ( isset( $block[ 'posts' ] ) && !empty( $block[ 'posts' ] ) )
{
foreach ( $block[ 'posts' ] as $key => $value )
{
$blockContent .= get_the_title( $value->ID ) . ' ';
$blockContent .= get_the_excerpt( $value->ID );
}
}
switch ( $layout ) {
case 'card_columns':
if ( isset( $block[ 'cards' ] ) && !empty( $block[ 'cards' ] ) )
{
foreach ( $block[ 'cards' ] as $key => $value )
{
$blockContent .= $value[ 'title' ];
$blockContent .= strip_tags( $value[ 'content' ] );
}
}
break;
case 'by_the_numbers':
case 'content_image':
if ( isset( $block[ 'numbers' ] ) && !empty( $block[ 'numbers' ] ) )
{
foreach ( $block[ 'numbers' ] as $key => $value )
{
$blockContent .= $value[ 'title' ];
$blockContent .= strip_tags( $value[ 'content' ] );
}
}
break;
case 'accordion':
if ( isset( $block[ 'accordions' ] ) && !empty( $block[ 'accordions' ] ) )
{
foreach ( $block[ 'accordions' ] as $key => $value )
{
$blockContent .= $value[ 'title' ];
$blockContent .= strip_tags( $value[ 'content' ] );
}
}
break;
default:
// default
break;
}
}
if ( !empty( $blockContent ) )
{
$attributes[ 'extra_content' ] .= $blockContent;
}
}
return $attributes;
} |
Hi @ypantig , The plugin uses the distinct feature by default: https://community.algolia.com/wordpress/index-schema.html However it uses distinct on the In your case you might want to truncate the content of your attribute. Can you tell me more about the attribute causing issues, what it contains? |
Hi @rayrutjes, Thanks for getting back to me. I've added more info above. As well, I tried appending the custom field content to |
Even if I try to do |
What is the hook you are using? Maybe you could try to append the given content to the native Right after that line, content gets exploded accross multiple records so if you want to change the content, it needs to happen before. Feel free to submit a PR here. |
I may have found the issue. I think I'm missing some fields in the function, which for some reason I wasn't when I was using the |
Quick question, so I'm using the So before, with the |
I did some error logging and it looks like the content is being added to the attributes for the templates, but not getting to Algolia.. Here's a screenshot: Any thoughts? It looks like this is just for fields from custom templates where I'm doing a check for the template. For a more general custom field, the content gets appended. Here's a sample screenshot of a page entry in Algolia with content coming from that general custom field I was talking about earlier. |
Hi @rayrutjes any thoughts on the above? |
Hi @rayrutjes, I was able to fix it by adding 3 lines of code in the plugin. I'll submit a PR as you suggested. Here's the lines of code that I added in:
|
Thanks @ypantig ! I made a comment on the PR. |
Hi there,
I added custom field data into the record to be indexed and now the record size is bigger than the quota that was set. Is there anyway to go about this? I've reached out to Algolia and they suggested using distinct but since it doesn't look like there's a hook to do it (and it works via JS rather than PHP), not sure how I can go about doing so?
The record sizes I have vary, there are some that go below 10KB, but most of them go over. I have removed some data from the index, but it would be great of all the fields can be indexed (we're using a lot of flexible fields throughout the site and each page has a lot of layouts set).
Algolia couldn't increase the size and suggested reaching out to you guys.
Thanks.
The text was updated successfully, but these errors were encountered: