magento2 – Override vendor/magento/module-catalog-search for Magento 2

Basically you do not copy the core module to app/code. You create a new module inside app/code directory and use common extending technics to change core functionality. Inside your new module define sequence to the core module you extending, so it will load after the core module and won’t work if the core module is disabled.

If you need to change PHP class:

  1. Rewrite – point your new class to the core class and implement changes in it.
  2. Plugin – use before, around, after plugins for some functions and implement changes in those plugins.
  3. Observers – observe specific event and do some actions when those are fired (should not manipulate event data though).

If you need to change layout:

  1. Create new layout file with the same name as core layout – add your changes into it.

If you need to change template file:

  1. Create your new template file and use layout to point it to existing block.

If you need to change di.xml or other xml files:

  1. Add same xml’s into your module and use extending methods that’s specific to xml file.

Please, read more about extending Magento here:https://devdocs.magento.com/guides/v2.4/extension-dev-guide/bk-extension-dev-guide.html