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

Small enhancements to the DefaultRecord class #3279

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

dmj
Copy link
Contributor

@dmj dmj commented Jan 2, 2024

These are two small enhancements to the DefaultRecord class that we would like to see in VuFind mainline. They make it easier for us to work the K10Plus Zentral search index.

David Maus added 3 commits January 2, 2024 10:43
The german search index K10Plus Zentral stores title, title_sub, and
title_short as multi-valued. This change to RecordDriver/DefaultRecord
modifies the respective getters accordingly.
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @dmj, this makes sense to me, but I have some suggested improvements to the approach.

@@ -1210,7 +1210,14 @@ public function getSeries()
*/
public function getShortTitle()
{
return $this->fields['title_short'] ?? '';
if (array_key_exists('title_short', $this->fields)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider simplifying this method (and the equivalent below) to something like:

$titles = (array)($this->fields['title_short'] ?? []);
return $titles[0] ?? '';

Pretty sure this has the same outcome in less code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It certainly is shorter but could be harder to understand. I can certainly live with both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think it's too hard to understand, we could introduce a support method like protected getFirstValueFromField($fieldName) and put the logic in there... and then the other methods could call it. That would make the individual methods even shorter, and the behavior of the two-line logic would be self-documenting based on the method name.

@@ -734,9 +734,9 @@ protected function getOpenUrlFormat()
$formats = $this->getFormats();
if (in_array('Book', $formats) || in_array('eBook', $formats)) {
return 'Book';
} elseif (in_array('Article', $formats)) {
} elseif (in_array('Article', $formats) || in_array('electronic Article', $formats)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding more hard-coded values here, what if you add new class properties for $journalFormats and $articleFormats and then do an array_intersect to see if they are present? This way, we can leave the default values at the current ['Journal'] and ['Article'], but it's very easy to adjust in a local subclass for other situations (or we might even be able to make it configurable somewhere).

I would prefer not to add new format strings here that are not found in the language files or anywhere else, as I think that could lead to confusion... though if you think that's the only way forward, I'm certainly willing to discuss further!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Hardcoded values are a quick'n'dirty solution.

It'll think about it, there might be a longer development arc: It should be possible to separate the serialization of a record (OpenURL, Schema.org, XML, Citations) from the RecordDriver.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this open until we can find a generic solution -- though if defining properties to hold the lists is a workable short-term solution for you, we could do that now and still work toward a more robust longer-term solution.

While I support separation of concerns where practical, I think the main challenge to figure out is how to deal with the various format-specific special cases and limitations if we have an external serializer. I'd rather have that logic in the record drivers than have a single monolithic class riddled with special cases, as I think that's much less extensible and flexible. But maybe there's a middle ground where we build a serialization mechanism that can have driver-specific plugins, so we retain the current degree of flexibility but also reduce the size of individual classes. Or maybe you have something entirely different in mind! But, just as one very specific example, I think the current system where each record driver knows which formats of XML it can return through getXML is better than a system where we have a single XmlGenerator class that needs to somehow figure out when it can do Dublin Core and when it can do MARC-XML, etc., etc.

@demiankatz demiankatz added improvement small Minor changes to relatively few files labels Jan 2, 2024
@demiankatz demiankatz added this to the 10.0 milestone Jan 2, 2024
@demiankatz
Copy link
Member

@dmj, it also looks like a vendor/bin/phing php-cs-fixer run is in order to add a missing use statement (though of course I'd hold off on that until making any other changes first).

@demiankatz
Copy link
Member

@dmj, since there has been no activity here for a few months, I wanted to check with you on the status of this PR. I originally scheduled this for release 10.0, which should be completed in the next couple of months. Do you think we can finish this work in time for the release, or should we reschedule it for 10.1 or 11.0?

@demiankatz
Copy link
Member

I've merged the latest dev branch into the PR to get things up to date again. (There were no conflicts).

@demiankatz demiankatz modified the milestones: 10.0, 10.1 Jun 14, 2024
@demiankatz demiankatz modified the milestones: 10.1, 11.0 Oct 28, 2024
@demiankatz
Copy link
Member

Since this has not gotten completed in time, I am pushing it forward to the 11.0 milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement small Minor changes to relatively few files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants