Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ACF Flexible Content Layout fields to schema #11

Open
joshuaiz opened this issue Jun 28, 2024 · 6 comments
Open

Adding ACF Flexible Content Layout fields to schema #11

joshuaiz opened this issue Jun 28, 2024 · 6 comments

Comments

@joshuaiz
Copy link

Hello,

The bulk of the content on the site I'm working on is in ACF Flexible Content Layout fields on Posts and Pages.

I'm assuming I would have to add the schema for these fields for them to be indexed in search. I have roughly 20 layouts, each with its own subfields. What is the best way to include all of these fields in the schema?

Additionally, what are the options for type in this fields array:

'fields' => [
    [ 'name' => 'post_content', 'type' => 'string' ],
    [ 'name' => 'post_title', 'type' => 'string' ],
    [ 'name' => 'post_type', 'type' => 'string' ],
    [ 'name' => 'post_author', 'type' => 'string' ],
    [ 'name' => 'comment_count', 'type' => 'int64' ],
    [ 'name' => 'is_sticky', 'type' => 'int32' ],
    [ 'name' => 'post_excerpt', 'type' => 'string' ],
    [ 'name' => 'post_date', 'type' => 'string' ],
    [ 'name' => 'post_id', 'type' => 'string' ],
    [ 'name' => 'post_modified', 'type' => 'string' ],
    [ 'name' => 'id', 'type' => 'string' ],
    [ 'name' => 'permalink', 'type' => 'string' ],
    [ 'name' => 'post_thumbnail', 'type' => 'string' ],
    [ 'name' => 'genre', 'type' => 'string[]', 'facet' => true ]
],
// ...

Thanks!

@digamber89
Copy link
Contributor

Hi @joshuaiz

The schema field types are : https://typesense.org/docs/0.24.0/api/collections.html#field-types

As for the indexing - it really depends - is the layout field going to go into a single content.
Would you strip the html tags and put it into the post_content instead ?

If it was me and all the content generated via layout fields need to be searchable I would use the post_content field.
If they are facets I would add a new field.

Hope this helps.

@joshuaiz
Copy link
Author

joshuaiz commented Jul 1, 2024

Hi @digamber89 the ACF Flexible Content fields are all separate. This is a headless site and we are pulling the content from each field in the layouts using WPGraphQL.

As such I'm not quite following what you mean by putting the content into post_content...can you explain?

But assuming I am not doing that and keeping all of the separate fields, would each of those fields need to be added to the schema for indexing? (I'm assuming yes but want to confirm). Thanks!

@digamber89
Copy link
Contributor

Hi @joshuaiz

What i mean is, if the layout fields are used to generate one single content, then it would be better to aggregate the output of all the fields into one single field.

So by post_content i mean the final html output as post_content is usually the output seen on non-headless WP sites. So i think it would make sense that the output of the ACF Layout fields are aggregated into the post_content schema field ( which is already present ) and would integrate into the search results.

Otherwise - if lets say the layout fields denote separate meta details about your content.
Lets say vehicle is post type and each ACF field denotes vehicle info such as VIN, Make, Model etc. - it would make sense to create different schema fields so as to use them as facets for search,.

I hope i was clear.

@joshuaiz
Copy link
Author

joshuaiz commented Jul 2, 2024

Yes thanks for this - makes sense.

As an example let's take the Callout With Image layout (callout_with_image) and the following sub fields:

heading
callout_content

How would I add these to the schema referencing the callout_with_image layout considering that sub field names are not unique? Multiple ACF Flexible Content layouts may have a heading field, etc.

@joshuaiz
Copy link
Author

@digamber89 still struggling a bit with this - not sure how to add an ACF Flexible Content Layout subfield to the schema.

@digamber89
Copy link
Contributor

Hi @joshuaiz

I would encourage you to think of / organize your data first insead of focusing on ACF Layout Fields.
So i would figure out what the schema should be first.
Then figure out how to extract the data via the ACF Fields into the schema instead of the other way around.

Remember the user is search for / viewing the data from Typesense, they won't care that if it's coming from ACF Layouts or not.

For example lets say i have a vehicle ( CPT ) with the following ACF Fields
VIN: X12313
Make: 1231355
Product Description: This is a great used car

All of these fields would be entered into my schema.
But lets say if the product descrpition uses Flexible content with repeaters / image etc.

I would extract the data that should be put into product description.

I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants