On input focus, I ask the developer to automatically select any previously entered text. Doing so, it will allows users to enter a new search by typing, or to modify the previous search. Is this usable? Is this a best practice?
There are two possible scenarios here.
We assume that by default the user wants to replace the search term. In this case the selection aids him, and in case he wants to refine rather than replace the term, all he needs to to is hit "end" or "home" or any of the arrow keys, and the selection is canceled.
We assume that by default the user wants to refine the search term. Then it's best not to select the existing term. But if he wants to replace it, then he needs to either hold "delete" or "backspace" (depending on where you place the cursor) or do shift+home/end.
If you have a good idea of who your users are and what they are likely to do, this should help you decide. Also, I'd say that unsophisticated users are less likely to realize what the selection means (i.e. that anything they type will replace the entire text), and they're also less likely to know the shift+home/end combo.
I used to try to achieve the same thing in Java Swing. Just select everything when the textfield receives the focus. However, doing so may actually introduce more issues than leaving the selection away if not carried out properly. If you opt of the selection upon focus gain, at least the following points should be checked:
The focus can enter the searchfield in different ways: TAB, direct click, initial focus in popup dialog, etc. Do you really want to select everything in all cases? Maybe it makes sense only if using the keyboard, depending on your application/users. As an implementation, it may be hard to determine why the searchfield gets the focus. For example in Swing, listening on the focus grab events would make your searchfield select everything if the parent window regains the focus after loosing it. For example, if you click the searchfield, remove the selection, give the focus on another window, then give the focus on the searchfield window, then everything will get selected again. It is maybe a minor issue for a searchfield, but might be more of an issue is some other cases.
Many (I mean MANY) users often try to select the searchfield text (part of it or entirely) using click+drag. I could see so many people using it that way. In this case, you wouldn't want to select everything automatically upon focus gain. Also, if the user does a click+drag, the location of the cursor | should be at the end of the drag manipulation. For example, if the user drags from right to left (most likely if the text is left-aligned), the cursor should remain on the left. But you select the text automatically just upon focus gain, chances are that the cursor will always be on the right.
If the user just clicks in the middle of the text: then you would either put the cursor exactly at the position of the click (thus no selection of text), or select everything.
As a complement to this, if the user just clicks on the empty space after the text (or before the text if right-aligned): then you would either select everything (a bit like if you click on the side of the document in Word: the whole line gets selected) or just put the cursor at the end of the text (respectively at the beginning if right-aligned).
If a first single click results in selecting everything, then another single click would clear the selection and put the cursor | at the exact location of the mouse pointer.
A good working example IMHO is the omnibar in Google Chrome on Windows. Note that the behavior is different on Linux...