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

Allow fieldtypes to manipulate values before inserting to search indexes #321

Open
jackmcdade opened this issue Jul 12, 2019 · 2 comments
Open

Comments

@jackmcdade
Copy link
Member

I wonder if we should augment the data before inserting it into the search index so you can search on what you would expect as output. Thoughts, @jasonvarga?

Originally posted by @jackmcdade in statamic/cms#550 (comment)

@jackmcdade jackmcdade changed the title Augment data before inserting to search index Augment data before inserting to search index? Jul 15, 2019
@jasonvarga
Copy link
Member

I don't necessarily agree that everything should be augmented before putting in the index, but definitely some.

eg. Bard fields store prosemirror structure that looks like this:

[
  0 => array:2 [
    "type" => "paragraph"
      "content" => array:1 [
        0 => array:2 [
          "type" => "text"
            "text" => "Foo bar"
          ]
        ]
      ]
    ]
  ]
]

If you were to search for paragraph or text, this entry would match. So we'd want Bard fields to get augmented, for sure.

But maybe another field converts to html or something. Use that photo gallery fieldtype example.

images:
  - one.jpg
  - two.jpg

if it augmented to <div class="gallery"><img src="one.jpg" /><img src="two.jpg" /></div> then div, src, class, etc would all match. No bueno.

So whatever the solution is, it should be up to the fieldtype to decide.

Probably just duplicate the Augmentable behavior and make an Indexable one.

@jasonvarga jasonvarga changed the title Augment data before inserting to search index? Allow fieldtypes to manipulate values before inserting to search indexes Sep 19, 2019
@HellPat
Copy link

HellPat commented Jan 12, 2020

Mhh, I'd love to have the index configurable and let the user decide.

What about allowing a closure as fields in the index-configuration?

'default' => [
    'driver' => 'algolia',
     'searchables' => 'all',
     'fields' => ['title'],
],

could look like: (pseudo-code)

'default' => [
    'driver' => 'algolia',
     'searchables' => 'all',
     'fields' => function($entry) {
         return [
             'locale' => $entry->locale(),
             'searchable_content' => $entry->values()->get('content')->raw(),
             'content' => $entry->values()->get('content'),
         ];
     },
],

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

3 participants