Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We have a requirement for allowing Metatag keywords to be searched and considering writing a patch that adds a Metatag submodule adding support for this, such as in https://drupal.stackexchange.com/questions/167438/how-to-add-metatag-mod... & http://agileadam.com/2015/11/adding-metatag-keywords-to-search-api-index/
Is this something you'd consider adding to Metatag?
Comment | File | Size | Author |
---|---|---|---|
#77 | metatag-n2692877-77.interdiff.txt | 646 bytes | DamienMcKenna |
#77 | metatag-n2692877-77.patch | 9.58 KB | DamienMcKenna |
|
Comments
Comment #2
stefan.r CreditAttribution: stefan.r commentedComment #3
DamienMcKennaI would *definitely* be interested in a patch for that!
Comment #4
stefan.r CreditAttribution: stefan.r commentedComment #7
stefan.r CreditAttribution: stefan.r commentedComment #10
stefan.r CreditAttribution: stefan.r commentedComment #13
stefan.r CreditAttribution: stefan.r commentedComment #16
stefan.r CreditAttribution: stefan.r commentedMy tests are green locally, I think there is an issue with the testbot. It is not fetching the dependencies (entity, search_api) as it is reading the dependencies from test_dependencies in the .info file before applying the patch, rather than after:
https://dispatcher.drupalci.org/job/default/106677/console
Comment #17
stefan.r CreditAttribution: stefan.r commentedTestbot issue: #2692407: Test_dependencies are downloaded before applying patches, rather than after
Comment #18
DamienMcKennaYeah, that's the problem, I see it all the time. I'll give it a spin locally. Thanks.
Comment #19
DamienMcKennaWould you mind reworking this so that it applies to the main module? I don't think it needs to be a submodule.
Comment #20
stefan.r CreditAttribution: stefan.r commentedYes, will do.
Comment #21
stefan.r CreditAttribution: stefan.r commentedComment #24
DamienMcKennaThis improves some of the comments.
Comment #25
DamienMcKennaAfter reviewing the functionality, this needs to be extended to use metatag_get_info() to list all meta tags provided by the module, rather than hardcoding it to only work with the useless 'keywords' field.
Comment #26
DamienMcKennaThe last patch missed some files.
Comment #27
DamienMcKennaComment #28
stefan.r CreditAttribution: stefan.r commentedLooking good so far!
I'm willing to look into adding support for other fields (our specific requirement was just the keywords field), but for now should we limit ourselves to adding just Page title, Description, Abstract and Keywords?
Does this look good to you, other than the missing support for other fields?
Comment #33
DamienMcKennaYes, this is definitely going in the right direction, it just needs to dynamically load the meta tags via the APIs rather than hardcoding the definitions for a few tags.
Comment #34
stefan.r CreditAttribution: stefan.r commentedJust to be clear: all of them? i.e. everything under
metatag_get_info()['tags']
?Please can you point me to the right API hooks you'd like me to use.
Comment #35
DamienMcKennaThinking on it further, is the goal to index the strings that are being manually entered, i.e. overridden values that would be found in the {metatag} table, or the final processed meta tags that would appear on the HTML page?
Comment #36
stefan.r CreditAttribution: stefan.r commentedIn our case, the manual metatags... Not sure what the point would be of indexing the
<meta>
tags?Comment #37
DamienMcKennaSorry, I didn't mean the actual HTML tags, but the final values with all tokens processed.
The next question is: should it exclude values that are just tokens?
Comment #38
Dave ReidThis should be able to go into metatag.search_api.inc as well, since search_api implements hook_hook_info().
Comment #39
stefan.r CreditAttribution: stefan.r commentedAh! Definitely the processed values then -- makes much more sense when searching.
Why would we want to ignore token-only values?
Comment #40
DamienMcKennaThe question about tokens was related to the fact that just pulling the $entity->metatags[LANGCODE][METATAG]['value'] variable will give you the meta tag values before they're processed, so there could be raw tokens. To get the final meta tag strings we'd need to take a different approach, and I'm honestly not sure off-hand the best way of doing this.
Comment #41
DamienMcKennaThinking on it further, I think should be handled as a custom data type via hook_search_api_data_type_info rather than a data alternation thing. It might then list all available meta tags individually, or maybe it could work as a "related field" that then makes all of the tags available?
Comment #42
stefan.r CreditAttribution: stefan.r commentedComment #44
stefan.r CreditAttribution: stefan.r commentedComment #48
stefan.r CreditAttribution: stefan.r commentedScreenshots, for illustration:
Data alteration toggle, which will make the Meta tag fields appear:
(from hook_search_api_alter_callback_info() docs: "Registers one or more callbacks that can be called at index time to add additional data to the indexed items (e.g. comments or attachments to nodes), alter the data in other forms or remove items from the array.")
Fields:
Comment #49
stefan.r CreditAttribution: stefan.r commented@DamienMcKenna, is this close to what you are looking for? Or still waiting for @drunken_monkey feedback?
Comment #50
DamienMcKennaYes, this is definitely the kind of improvement I was looking for, thank you.
I'll test it out next week.
Comment #51
drunken monkeyI don't know about the Metatag-specific code, of course, but as far as integration with the Search API is concerned, the latest patch looks quite good. Just a few things I noticed:
You can use
(bool) $index->getEntityType()
instead. That's more portable than checking for a specific class.I could be mistaken, but I don't think that's valid in PHP 5.2.
This will trigger an error if
$item->language
isn't set.Those should all be fixed in the attached patch. Regarding
field_get_items()
, I'm not completely sure – it should do what you want, but I'm not 100% certain. Please try it out.The test looks also sensible, though I wonder why you're using the UI for creating the server and node, but not for the index. Personally, I'd create all three programmatically, but at least it should be consistent – in my opinion. But not a real "error", of course, so that's up to you.
Comment #54
stefan.r CreditAttribution: stefan.r commented@drunken monkey many thanks for the review, changes look great to me!
field_get_items() doesn't seem to work here though (as field_language() === FALSE), so one of the tests failed. Maybe just a check for $item->language being set instead?
Comment #57
stefan.r CreditAttribution: stefan.r commentedRe-roll, tests are still green:
Comment #58
stefan.r CreditAttribution: stefan.r commentedForgot to attach the actual reroll, here it is :)
Comment #59
stefan.r CreditAttribution: stefan.r commentedTriggering a re-test
Comment #60
DamienMcKennaDid you forget to include the metatag.search_api.test file? I don't see it in patch #57.
Comment #61
DamienMcKennaComment #62
stefan.r CreditAttribution: stefan.r commentedComment #65
DamienMcKennaI've re-queued the last patch for review.
Comment #66
DamienMcKennaComment #68
DamienMcKennaThere were unwanted + signs in the info file ;-)
Comment #70
stefan.r CreditAttribution: stefan.r commentedOops! Passes locally though, doesn't it?
Comment #71
DamienMcKennaAh! It's because we're adding new test dependencies, I forgot about this issue.
Comment #72
DamienMcKennaThe patch in #71 will add the test dependencies, we'll commit that and then do a new patch with the rest.
Comment #74
DamienMcKennaAnd the final tests, which should work fine.
Comment #75
DamienMcKennaBTW I updated the test file to match the other "with [modulename]" tests, but otherwise it's 100% yours.
Comment #77
DamienMcKennaForgot to add the metatag.info changes back again.
Comment #79
stefan.r CreditAttribution: stefan.r commentedWoohoo! Thanks :)
Comment #81
DamienMcKennaThe testbot failure are being caused by #2737555: Test failures in contrib modules when other projects include forked versions of said contrib modules, so hopefully that'll be fixed soon.
BTW would you mind adding a section to the README.txt file explaining how to use the new functionality? I think that'd really help people a lot. Thanks.
Comment #82
DamienMcKennaThe tests are passing again (thanks drumm!), so I think a little extra bit to the README.txt file and it'll be good to go.
Comment #83
DamienMcKennaDuh, there's already some instructions in the README.txt file.
Comment #84
DamienMcKennaAnd it's committed! Woohoo! Great work, stefan.r!
Comment #85
DamienMcKenna