Perfected search functions now available
Sunday, 27. January 2008, 04:26:28
Here are selected-text searches which patch some shortcomings: they
- offer phrase / wordset choice
- are usable on selections in editable text
- don't use and thus erase the clipboard (as one must to capture defined editable text with macros - the strings of Opera commands one can assign to a keystroke, button or menu line)
- permit one-hand open-in-background (not requiring use of Shift+Control, which is Opera's convention) which works regardless of system settings (not achievable with macros).
Also: instructions on preference settings which make Opera treat single words in the address field as search strings, and any other points of search lore I can think of (only one, for now).
1. Perfected selected-text search
If you select some text as a search string in off-the-shelf Opera, you're out of luck if you want a phrase search, instead of a wordset search (which treats the selection as a set of unconnected words). Pretty basic need - but you'll have to go through realizing that the option isn't set up, and then work out what's required. In fact, quotes must be added around the %s variable you will find via Tools / Preferences / Search / (select search provider) / Edit / Details. This makes it a phrase search, available both for typed-in searches (using a prefix) and selected-text searches (via the "internal search with" list on the context menu). (If you want both, you need to add a search: one with quotes, one without.)
You're more deeply out of luck if the selection is in editable text. Opera searches in that case just don't work. The search command isn't on the context menu - and if you invoke it by button or keystroke, it runs with no search string and returns an error. You can write a macro using a variable which references selected text; but it has the flaw of using the clipboard, and thus obliterating anything else that was on it.
Finally, if you'd like the search results to open in the background you will need to remember and execute a modifier gesture with your other hand - adding Shift+Ctrl to the click or Enter which executes the search - so put down your coffee, tip your chair to the fully upright position, get both hands on the keyboard and get serious. Or you can use macros involving things like New page and then a backwards navigation step - but their outcome is dependent on settings for things like whether search results open a new window and tab bar navigation, which makes them brittle and finicky, given that Opera's macro system doesn't support settings queries or branches.
So - the search system is flawed, and the macro system is not capable enough to permit perfect solutions. Enter javascript: which is cryptic and much harder to learn, but powerful. Luckily the community includes a few javascript masters such as Lex1. He (prompted by frustrated macro writers me and Dude09) provided these functions, which work regardless of settings, on all text, and don't touch the clipboard. They are set up to use Google, but you can swap in the name of any provider you prefer.
Note: this setting must be "yes" to permit search results in background: Allow script to lower window (follow the link, make sure checkbox is ticked, click "save" if you had to change it)
as buttons (drag link to toolbar to install):
phrase search, new tab
wordset search, new tab
phrase search, background
wordset search, background
To add the functions:
- to keystrokes or mouse gestures, copy and paste the light blue into the action field in the keyboard or gesture customization dialog (Tools / Preferences / Advanced /Shortcuts / Edit)
- to rightclick menus, copy the entire new menu below (light and dark blue) into your custom menu.ini, and add this line to both Hotclick Popup Menu and Edit Widget Popup Menu:
Include, Selection Search Menu
If you don't have a custom menu.ini, you'll need to start one; see Tamil's intro to editing menus.
[Selection search menu]
Item, "&Phrase search, new tab" = Go to Page, "javascript: window.open('http://www.google.com/search?q=\x22'+encodeURIComponent(document.selection.createRange().text)+'\x22');void(0)",,,"zoom"
Item, "&Wordset search, new tab" =Go to Page, "javascript: window.open('http://www.google.com/search?q='+encodeURIComponent(document.selection.createRange().text));void(0)",,,"zoom"
Item, "phrase search, &Background" =Go to Page, "javascript: window.open('http://www.google.com/search?q=\x22'+encodeURIComponent(document.selection.createRange().text)+'\x22').blur();",,,"zoom"
Item, "w&Ordset search, background" =Go to Page, "javascript: window.open('http://www.google.com/search?q='+encodeURIComponent(document.selection.createRange().text)).blur();",,,"zoom"
("&" in menu labels causes the next letter to serve as the accelerator (selector keystroke). You can adjust these if other items on your menu use the same letter - that situation necessitates an Enter to confirm selection.)
The improvements emerged in this thread: a way to get a hotclick phrase search. (For the prior state of the art, see this discussion from 2006, and this sort of historical essay post I wrote.)
- I pointed out that the use of capital variables (%C and %T, which add quotes around clipboard contents and current text selection respectively) made hotclick phrase search (as opposed to the usual wordset search) possible.
Example: go to page "g %T" & minimize page gives you a phrase search in a background tab. (At least, it does if "reuse current tab" is unchecked - and puts you in the wrong tab otherwise. An example of how outcomes depend on preference settings.)
- Dude09 pointed out that a flaw in the %T variable (it doesn't work with editable text) obliged him to use %C for searching on editable-text selections (with the unwanted effect of obliterating the clipboard).
- Lex1 presented a javascript improvement on Opera's variables: a search that works on both forms of text. For good measure, he threw in a background-tab version that works regardless of preference settings.
- I pointed out that this did not as yet add the quotes a phrase search requires
- and Lex added commands which put them in.
Regarding use with one hand: Opera applies "open in background" in general, automatically, to any keystroke which uses the Shift+Ctrl modifier - which is worth knowing, but as a two-handed gesture not ideal for those who like to slouch, curl up or sip as they work through the morning news or whatever. This wouldn't matter much if the actions tied to those gestures were available to the customizer - but they're not. Shift+Ctrl works better than anything you can set up with macros: it opens in the background, regardless of setting. That requires access to things we just don't have in Opera's macro system: sensing states and branching. So a settings-independent open-search-in-background you can put on a button or menu was not only an unprovided function: it was unconstructible within the macro system.
2. Address-field search (from 2008)
The last of three steps has been taken to make the address field into a seamless search field. First was search, specified by a prefix letter; then came automatic search if what was in the address field was more than one word; and now we have the ability to set up automatic search on single words as well. Described by dev Martintangsl here.
Setup is 3 changes in Preference Editor; follow this link to access all of them: Opera:config#hostname
- uncheck hostname expansion, to switch off automatic URL-ization (that is,addition of www. and .com) of single words (you can still URL-ize when you want to, with Ctrl+Enter).
- check hostname lookup, to enable single-word search.
- insert hostname address - for Google, it's http://www.google.com/search?q=%s. For other providers, copy from Preference dialog following Martinangsl's instructions.
3. other search lore
- capitalized variables are supposed to be equivalent to the uncapitalized ones in quotes: %T = "%t". This works most of the time, but not in searches: putting %S in a search spec wipes the search out. Not serious, since quotes around the variable ("%s") do work - but a flaw / quirk /inconsistency which anyone trying to become fluent is obliged to figure out and remember.








AyushJ # 27. January 2008, 16:34
Actually, this is a old trick - http://my.opera.com/community/forums/topic.dml?id=144907
bpm # 27. January 2008, 21:34
Minor point: Shoust presents procedure as specific to "I'm feeling lucky" - which was his use, but doesn't point out more important possibility of using it for basic search (and most people don't use "I'm feeling lucky" as their normal search).
So: pref-ed settings are not new, but change in context has changed what they do. Easy to get lost among the trees. Main point here: there is unassimilated good news: a better way (in terms of simplicity and space efficiency) to set up search has become possible, is not generally understood or used - and deserves to be made the default.
Ask yourself: why are people still using the "g" prefix? Answer must be that they think it's still necessary. If you think about it, they're hallucinating - governed by false images, living in the past. The Opera user community - in the grip of a hallucination bubble. That's reality; takes a strange person to see it (in this matter, and in graver ones as well).
lem729 # 4. July 2008, 16:44
Now if I want to change search engines for the address bar, that would take more fiddling. That's why I think it's good to keep the small drop-down search bar -- for other search engines. To avoid that fiddling.
Also, interestingly the Supernova skin, http://my.opera.com/community/customize/skins/?search=supernova&x=0&y=0
has an Ask search box built into it (for the background to the Speed Dial), so that's another easy search option (from the Speed dial), as long as one uses that skin.
Lex1 # 5. July 2008, 08:43
annafil # 22. July 2008, 19:34
jabu2oz # 9. August 2008, 15:20