@refs http://drupal.org/node/1441138

The second feature would be the order by statement of the sliced result, it is currently ordered by the element title (e.g. node title). It would be great if this would be configurable to the length of the title. Lets make a simple example, we are looking for the node with the title "foo", and this is our list of all node with '%foo%' in the title:

another foo no. 1
another foo no. 2
another foo no. 3
another foo no. 4
another foo no. 5
another foo no. 6
another foo no. 7
another foo no. 8
another foo no. 9
another foo no. 10
-- cut --
foo
short foo

As we could see, the alphabetical order will place my "foo" node after the irrelevant previous foo's, even if it's a perfect match to my search string. The solution would be to change the orderBy('n.title') statement to orderBy('LENGTH(n.title)') which helped me very well, because the shortest match ("perfect match") will be placed at top. Maybe some people would also like to see the latest matching titles by using orderBy('n.changed','DESC').

The result will look like:

foo
short foo
another foo no. 1
another foo no. 2
another foo no. 3
another foo no. 4
another foo no. 5
another foo no. 6
another foo no. 7
another foo no. 8
-- cut --
another foo no. 9
another foo no. 10

Comments

kpaxman’s picture

Issue summary: View changes

Not sure about sorting by size, but I did want to push exact matches to the top. I filed issue https://www.drupal.org/node/2860959 and submitted a patch which accomplishes this.