bpm's Operations Room

understanding & extending Opera

Perfected search functions now available

,

(open-in-background works again in 10.53... bug back in 10.54... fixed in 10.60)
(2010-3-25: in 10.5, open-in-background not usable due to this bug)
(updated 2010-2-17 to work with Opera 10.5 except for that)
(show-search-results-in-current-tab options added 2010-3-6)
(green links are button-installer tags)

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 - strings of Opera commands)
  • permit one-hand open-in-background (not requiring use of Shift+Control, Opera's keyboard convention)
  • work regardless of system settings (which can disrupt the maneuvers macros use to achieve opening in background).

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 a couple, for now).

1. Perfected selected-text search

issues
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 copy the text, and write a macro using a variable which references the clipboard; but that has the flaw of obliterating anything else that was on the clipboard.

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 a New page and then a backwards step such as Minimize Page - but they are all flawed: Minimize disrupts tiling, and backwards navigation commands have outcomes dependent on settings for things like 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.

solution
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)

To add the functions:
  • as toolbar buttons, drag these links to the toolbar:
    phrase search, new tab
    wordset search, new tab
    phrase search, background
    wordset search, background
  • to keystrokes or mouse gestures: copy the light blue code below for the function you want, open the keyboard or gesture customization dialog (Tools / Preferences / Advanced /Shortcuts / Edit), get the cursor into the action field in the line for the keystroke or gesture you want to use, and paste. Click OK to register the change & OK to close the dialog.
  • to rightclick menus: if you don't have a custom menu.ini, you'll need to start one; see Tamil's intro to editing menus. Copy the entire new menu below (light and dark blue, including heading) into your custom menu.ini, and add this line to both Hotclick Popup Menu and Edit Widget Popup Menu:
    Include, Selection Search Menu

[Selection search menu]
Item, "&Phrase search, new tab" = Go to Page, "javascript: window.open('http://www.google.com/search?q=\x22'+encodeURIComponent(document.getSelection())+'\x22');void(0)",,,"zoom"
Item, "&Wordset search, new tab" =Go to Page, "javascript: window.open('http://www.google.com/search?q=%27+encodeURIComponent(document.getSelection()));void(0)",,,"zoom"
Item, "phrase search, &Background" =Go to Page, "javascript: window.open('http://www.google.com/search?q=\x22'+encodeURIComponent(document.getSelection())+'\x22').blur();",,,"zoom"
Item, "w&Ordset search, background" =Go to Page, "javascript: window.open('http://www.google.com/search?q=%27+encodeURIComponent(document.getSelection())).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.)

2010-3-6 addendum: here are open-search-in-current-tab functions, for which there is some demand because 10.5 has started opening search in new tab no matter what:
Item, "phrase search, current tab"=Go to Page, "javascript: document.location.href=('http://www.google.com/search?q=\x22'+encodeURIComponent(document.getSelection())+'\x22')"
Item, "wordset search, current tab"=Go to Page, "javascript: document.location.href=('http://www.google.com/search?q=%27+encodeURIComponent(document.getSelection()))"


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 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.
Click the Save button (you'll see it, at the bottom of the Network section of Preferences Editor) after those three changes. You'll get a dialog saying it may take an Opera restart to bring the changes into effect, but in fact it doesn't: works right away.

3. search lore
  • the convention that Shift added to a click or Enter causes resulting page to open in new tab, and Shift+Ctrl in background tab, applies not only to context menu searches but also to search-field and address-field searches.
  • 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 master the system is obliged to figure out and remember.

(more than) 15 things I didn't know6 Opera hacker tidbits

Comments

AyushAyushJ Sunday, January 27, 2008 4:34:52 PM

First was search, specified by a prefix letter; then came automatic search for multi-word field content; and now we have the ability to set up automatic search on single words as well


Actually, this is a old trick - http://my.opera.com/community/forums/topic.dml?id=144907

bpm Sunday, January 27, 2008 9:34:38 PM

Ayush - thanks for pointing out thread. I'd read it - didn't take in that it was describing same PrefEd changes as Martinangsl. But I think you are wrong to say it was same idea. Context was different: multi-word search was not set up (which is why Shoust said you needed to use plus signs instead of spaces). When it was added, in March 2007, whole scenario changed. {General search (single- or multi-word) in address field without prefix} went from fringe possibility (Lex's LNG hack) to something anyone could set up in a minute in PrefEd.

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).

Mel B.lem729 Friday, July 4, 2008 4:44:15 PM

Thanks on helping me get a search directly from the address bar.

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.

A.RuzanovLex1 Saturday, July 5, 2008 8:43:36 AM

For search in background in Opera 9.5, you must set Ctrl+F12->Advanced->Content->Javascript options->Allow lowering of windows.

Annaannafil Tuesday, July 22, 2008 7:34:46 PM

Hmm thanks for the tip. I've been using "g" to search. This post made me dig around in my opera:config and i've found a new level of depth in opera search customizeability smile

jabu2oz Saturday, August 9, 2008 3:20:58 PM

This, for some reason, does not work on my Linux machine, yet works fine with exactly the same Opera install on my Windows machine

dapxin Thursday, November 12, 2009 10:11:58 PM

this was a very useful post. tx.

DH Realistdhrealist Thursday, April 29, 2010 10:13:09 AM

Is there any way that would make it possible to search in background tab in 10.5x version? thanks.

bpm Thursday, May 20, 2010 4:44:43 PM

DH - works now (10.53) - the bug got fixed.

DH Realistdhrealist Saturday, June 12, 2010 6:51:17 PM

bpm,

These strings:
"
Item, "phrase search, &Background" =Go to Page, "javascript: window.open('http://www.google.com/search?q=\x22'+encodeURIComponent(document.getSelection())+'\x22').blur();",,,"zoom"
Item, "w&Ordset search, background" =Go to ..."

do not work for me. The search is performed in an active new tab and not a background one. Can you tell why?

bpm Sunday, June 13, 2010 2:19:27 AM

Realist - "blur" specifies background. They work for me, in 10.53 (not earlier 10.5 versions). If you're using 10.53, and have "allow script to lower window" checked, I don't know what the difference could be.

DH Realistdhrealist Wednesday, June 23, 2010 7:06:56 PM

bpm,

After checking the box "allow script to lower window" in preferences, a background search results in exactly the same behaviour as described in the bug for pre-10.53 versions:

"Opera opens a new tab in the background, but somehow locks it, so it can't be accessed. I can only reactivate it by doing

Righ click on locked tab --> Arrange --> Restore.

reducing it to a window and then maximizing that window to a tab again. This also happens when using javascript in the address bar:

javascript:window.open('http://www.opera.com', 'bla').blur(); void(0); "

I am currently using the version 10.54 ... Do you have a faintest idea what it might be? May be it has something to do with Java? Although I am running the latest 6.20 version ..

Any comment would be very very very greatly appreciated.
Thank you.

bpm Thursday, June 24, 2010 9:48:12 PM

Just got auto-updated to 10.54, and the bug is back - which solves that mystery. However, Lex1 says it's fixed again in 10.60:
http://my.opera.com/community/forums/findpost.pl?id=5770532

edit - and indeed, it's fixed in 10.60.

DH Realistdhrealist Friday, May 20, 2011 12:23:45 PM

Hello bpm,

there are two types of commands being dealt with here: one performs a search in a new open tab, the other does the same in a background one. They differ in their code just by ";void(0)" for the first command and ".blur();" for the second respectively.

Now my question is, how should a command look like which would perform a search in a new tab and then "restore" it, i.e. shrink the tab size in relation to the browser window and make it active as in tab menu| Arrange| Restore. So that the search result page appears in a shrinked-size active tab with the tab containing the search term visible in background.

.. sorry if my way to explain it was too complicated ..

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.