<p>Thanks Brad but it seems to me 'EVENT_AFTER_SEARCH' is not really suitable for this. 
I've found a better way on the frontend though in case you or somebody else gonna be interested: </p>

<p>I did some investigation how search and element sorting works and surprisingly the sorting by 'score' attribute is coming from the frontend.</p>

<p>The only thing I had to do is to overwrite the original EntryIndex js class which controls the behaviour of the entry index page. This is definitely possible the following non-hacky way: </p>

<pre><code>Craft.OriginalEntryIndex = Craft.EntryIndex;
Craft.EntryIndex = Craft.BaseElementIndex.extend(
    {
        startSearching: function () {
            this.base();
            this.setSortAttribute('postDate'); // overwrite attr.
            this.setSortDirection('desc'); // overwrite direction
        },
    });

delete (Craft._elementIndexClasses["craft\\\elements\\\Entry"]);
Craft.registerElementIndexClass("craft\\\elements\\\Entry", Craft.EntryIndex);
</code></pre>

CC BY-SA 4.0
2020-01-16T22:31:37.617Z
2020-01-16T22:31:37.617Z
peet86
<p>Maybe?  Pretty hacky I think, but there is an <a href="https://github.com/craftcms/cms/blob/develop/src/services/Search.php#L306-L313" rel="nofollow noreferrer">EVENT_AFTER_SEARCH</a> you can listen to that has the results already scored.</p>

<p>You could probably take those results, then resort by whatever other attributes you want and pass them along back to the CP.</p>

CC BY-SA 4.0
2020-01-02T20:04:13.103Z
2020-01-02T20:04:13.103Z
Brad Bell
<p>Craft version: 3.3.19</p>

<p>Is it possible to set default order for CP entry search results? The default is search score but for instance for blog entries, news, etc. the date of the entry is usually more important than the relevance. I need to overwrite the default behaviour somehow. </p>

<p>Thx</p>

<control-panel><search>
Is it possible to change the default search result order (CP)?
# Is it possible to change the default search result order (CP)?

(Asked by: username_0 on 2019-12-31)

Craft version: 3.3.19

Is it possible to set default order for CP entry search results? The default is search score but for instance for blog entries, news, etc. the date of the entry is usually more important than the relevance. I need to overwrite the default behaviour somehow.

Thx

**Tags:** control-panel, search

---

## 2 answers

### Answer by username_0 on 2020-01-16. Score: 0 | Accepted answer

Thanks Brad but it seems to me 'EVENT_AFTER_SEARCH' is not really suitable for this. 
I've found a better way on the frontend though in case you or somebody else gonna be interested: 
I did some investigation how search and element sorting works and surprisingly the sorting by 'score' attribute is coming from the frontend.
The only thing I had to do is to overwrite the original EntryIndex js class which controls the behaviour of the entry index page. This is definitely possible the following non-hacky way: 
Craft.OriginalEntryIndex = Craft.EntryIndex;
Craft.EntryIndex = Craft.BaseElementIndex.extend(
    {
        startSearching: function () {
            this.base();
            this.setSortAttribute('postDate'); // overwrite attr.
            this.setSortDirection('desc'); // overwrite direction
        },
    });

delete (Craft._elementIndexClasses["craft\\\elements\\\Entry"]);
Craft.registerElementIndexClass("craft\\\elements\\\Entry", Craft.EntryIndex);


---

### Answer by username_1 on 2020-01-02. Score: 1

Maybe? Pretty hacky I think, but there is an [EVENT\_AFTER\_SEARCH](https://github.com/craftcms/cms/blob/develop/src/services/Search.php#L306-L313) you can listen to that has the results already scored.

You could probably take those results, then resort by whatever other attributes you want and pass them along back to the CP.


---

