Upgrading to 2.6.1 broke Search

I recently updated from 2.2 to 2.6.1 because we needed reCAPTCHA v2 support. Since then, Search has been acting weird.

If I’m not logged in, the Search results page will return the error “Invalid record passed to recordMetadata”. If I’m logged in then Search works fine. If I re-index records then Search works for everyone. However, if any data is written to the database that changes a record’s metadata, it breaks Search again.

We regularly read and write record data, so I’m trying to track down what might be going on. Thank you for any pointers you might have!

This sounds like it would be an issue with the “public/private” flagging on the search texts table… you’d get an error like this if for some reason the search texts table says a record is public when it’s really private.

Thanks very much for the pointer. I’ve gone through and checked to make sure there is no privacy mismatches between search texts and items. I don’t think there are. I ran an SQL command to list out each and they match perfectly. If there are any other clues you could think of it would be greatly appreciated. We haven’t seen this issue until the upgrade. Currently, our search needs to be turned off, which is problematic. Thanks!

Even when the error is happening there are no mismatches?

That error you’re seeing occurs when we’re trying to print some data about the returned results. Since you’re saying it happens only when you’re logged out, it pretty much has to be a situation where the search is attempting to return a result for a private item, leading to the error you’re reporting.

Particularly your mention that things are fine if you re-index makes me more convinced the search_texts private flag is the culprit: the reindex process would (should) “fix” any mismatches that were present.

I was able to narrow down what the issue is.

If a search term is found in a public item, but the collection is private (or vice versa), then the error will be thrown. Even though the search_texts and item and collection tables show identical results for the ‘public’ column, there must be some way I’m building the search results in the custom search/index.php file that is problematic.

We haven’t seen this issue before, but it’s very possible something changed between 2.2.2 and 2.6.1. I’ll look more closely at the release notes since 2.2.2 and rewrite our search page as needed.

For now, I’ll just make sure items and collections have the same public settings. Thanks.

Are you including the collection name in the search results? That would have this result potentially…

If you’ve got custom code that’s fetching a Collection from an item result, you just need to add a check for whether it’s null before trying to print it.

Yes, the results have links to the collection, item, and file along with a snippet of the matched text. I’ll dig into the search page and fix how I’m retrieving the results. Thanks very much for your help!