Plugin: Search custom field

What I need: To add custom field search functionality to OJS 3.4 without modifying the core code.

Describe the issue or problem: Consider custom fields in submissions, like those described in the tutorial: https://docs.pkp.sfu.ca/dev/plugin-guide/en/examples-custom-field. How can we enable searching for these custom fields within OJS?

I successfully added a new search filter to the UI by utilizing the Templates::Search::SearchResults::AdditionalFilters hook to include the HTML for new fields. Additionally, I overrode the SearchHandler class with a subclass to leverage the _assignSearchFilters function.

However, the backend search functionality relies on specific functions that don’t utilize hooks. Modifying the OJS and PKP-LIB source code would be necessary to achieve this, which would involve changes to:

  • ArticleSearch::getSearchFilters
  • ArticleSearchDAO::getPhraseResults
  • SearchHandler::search

Is my understanding correct so far?

Modifying the core code is undesirable because of the potential for conflicts during future updates. Therefore, I have the following questions:

  • Are there alternative solutions to enable custom field search without core modifications?
  • How can we contribute to making the code for custom field search more modular and beneficial to the community? (I’m open to creating a pull request, but I’m hesitant to invest time if it’s not in line with community needs.)

Finally, why aren’t search filters available for custom fields, similar to how they are for categories, sections, and issues on the submissions page?

What application are you using? OJS 3.4

I discovered a way to do the custom search without core modifications. Thanks to the good design of the software.

Fortunately the deprecated retrieve method from base DAO class dynamically calls a Hook from the name of parent class and method. So, in my case I used the hook name 'app\\search\\articlesearchdao::_getphraseresults'. Then, getting the query string from hook args and user variables from request I managed to search for what I want.

However I had a little unexpected issue, that I will address here for completeness. In my callback function for this hook the $args are passed “unpacked” to the function. So, I expected to have $args with [$hookName, &$sql, &$params, &$value] receiving in a function like function modifyArticleSearch($hookName, $args). However doing that way $args got only the $sql value, without reference. The workaround for it was to declare the function like modifyArticleSearch($hookName, &$sql, &$params, &$value).