Question: When filters + Ancor is enabled for category, **sorting by product name** doesn't work. I know the fix as I tested in `Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection`. So now I'm trying to override it in my module but below does not work. It still reads from core file.

```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection" type="MyVendor\Mymodule\Model\ResourceModel\Fulltext\Collection" />
</config>

```

Below did not work too:

```
 <virtualType name="MyVendor\MyModule\Model\ResourceModel\Fulltext\CollectionFactory" type="Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
            <arguments>
                <argument name="instanceName" xsi:type="string">MyVendor\MyModule\Model\ResourceModel\Fulltext\Collection</argument>
            </arguments>
 </virtualType>

```

Answer: 
Try following way:

```

<virtualType name="VendorName\ModuleName\Model\ResourceModel\Fulltext\CollectionFactory" type="Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
    <arguments>
        <argument name="instanceName" xsi:type="string">VendorName\ModuleName\Model\ResourceModel\Fulltext\Collection</argument>
    </arguments>
</virtualType>
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection" type="VendorName\ModuleName\Model\ResourceModel\Fulltext\Collection">
    <arguments>
        <argument name="searchRequestName" xsi:type="string">quick_search_container</argument>
    </arguments>
</virtualType>

```

VendorName/ModuleName/Model/ResourceModel/Fulltext/Collection.php

```

<?php
namespace VendorName\ModuleName\Model\ResourceModel\Fulltext;

class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
{
}

```
The reason why it doesn’t work is because the class 

```
Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection

```

is used in the CatalogSearch with customization through virtual types and there is no direct usage of this class.
Customization of the source class for a virtual type is not possible because the ObjectManager resolves preference before resolving is a virtual type used and if that, then which class it should instantiate.
However, with the current implementation, you can customize specific virtual types and it should help you.

In Magento latest version I can find only one virtual type for the class

`Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection` :

```
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection" type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection">
    <arguments>
        <argument name="searchRequestName" xsi:type="string">quick_search_container</argument>
    </arguments>
</virtualType>

```

So to resolve your problem need define preference for the virtual type:

```
<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection" type="CompanyName\ModuleName\Model\ResourceModel\Fulltext\Collection" />

```