Template talk:Search link

Latest comment: 1 year ago by Jonesey95 in topic Option to add quote marks?
edit
This section was copied here from Wikipedia talk:Searching. --David Göthberg (talk) 09:55, 22 April 2009 (UTC)Reply

I'm sure this has come up before, but is there a clean way to create a generic search link for a particular search term? For example: [{{SERVER}}{{ScriptPath}}iki/Special:Search?ns0=1&ns14=1&ns100=1&search=%22a%20bacteria%22&fulltext=Search a bacteria] does appear to work (a bacteria) on both the secure and unsecure interfaces, but looks very hacked. I tried using [{{SERVER}}{{Script}}?title=Special:Search&ns0=1&ns14=1&ns100=1&search=%22a%20bacteria%22&fulltext=Search a bacteria] but it appears there is a name collision with a template named "script". I thought there was some sort of "full url" template? Thanks! Plastikspork (talk) 14:38, 20 April 2009 (UTC)Reply

This was a tricky question. It took me some testing to find out the details. I will use "New York" in my examples here.
For most special pages you could just do like this: Special:Search/New York. Unfortunately the Special:Search interprets that as if you filled in the search box and clicked Go. So if there is an exact match it takes you to that page, instead of to the search results. And if there is no exact match it shows an error message "No page with that title exists" and shows the search results below that. But I guess both you and I want to "click" the Search button, right?
Then you need to use an URL that looks like this:
http://en.wiki.x.io/w/index.php?title=Special:Search&search=New+York&fulltext=Search
Note that I had to tag on the "fulltext=Search" part to make it "search" and not "go". And the search term has to be "URL encoded", for instance spaces have to be changed to "+".
As you mentioned there is a shorter way to encode this. You can use the magic word {{fullurl}}. Then you can do like this:
{{fullurl:Special:Search|search=New+York&fulltext=Search}}

//en.wiki.x.io/w/index.php?title=Special:Search&search=New+York&fulltext=Search

If you want to automatically URL encode the search term you can use the magic word {{urlencode}}. That's especially useful when the search data is an incoming parameter to a template. Like this:
{{fullurl:Special:Search|search={{urlencode:New York}}&fulltext=Search}}

//en.wiki.x.io/w/index.php?title=Special:Search&search=New+York&fulltext=Search

And usually you don't want to show the whole URL but just a caption. Then do like this:
[{{fullurl:Special:Search|search={{urlencode:New York}}&fulltext=Search}} Find stuff]

Find stuff

You probably want to get rid of the external link icon. Then surround the search link with this code:
<span class="plainlinks"> ... </span>

Find stuff

We didn't specify what namespaces the searches above should be done in. So they will use whatever the user have set in "My preferences - Search - Namespaces". If you want to make it so your search link only searches for instance articles and article talk pages (namespace 0 and 1), then add the code "&ns0=1&ns1=1".
Here is an example with all the bells and whistles:
<span class="plainlinks">[{{fullurl:Special:Search|search={{urlencode:New York}}&fulltext=Search&ns0=1&ns1=1}} Find stuff]</span>

Find stuff

Ouch, that wasn't pretty. It seems we could have use of a template that could put that together for us in a more convenient way. I looked around a little, but could only find templates with more complex search functionality. See the ones listed in Category:Search templates.
--David Göthberg (talk) 17:03, 20 April 2009 (UTC)Reply
Excellent. Thank you so much for your thoughtful response. Should we create a template that just does what you have listed above? First entry is the search term, the subsequent ns#=x fields are the namespaces? This would seem very useful. I'm going to go do a big search and replace on Wikipedia:Lists_of_common_misspellings (A, B ...). Thanks again! Plastikspork (talk) 18:58, 20 April 2009 (UTC)Reply
Yes, I was hoping you would like to make such a template. Feel free to poke me on my talk page when you have made it, if you want me to check the code etc. I see several possible ways to feed the namespaces. I think you mean something like this, right?:
{{search link| New York | ns0=1 | ns5=1 }}
But it is also possible to make a template that works like this:
{{search link| New York | ns0 | ns5 }}
I think that would be easier to use. It took me some thinking to figure out how to implement that, but there is an easy solution:
{{#if:{{{2|}}}| &{{{2|}}}=1 }}{{#if:{{{3|}}}| &{{{3|}}}=1 }}
Come to think of it, this might actually be easier to use:
{{search link| New York | ns0=1&ns5=1 }}
Since then people can get the namespaces right by simply first doing an advanced search and click the namespaces they want there, and then copy and paste the namespace list from the URL they get. Of course, we can make the template understand more than one way to feed the parameters. Tell me if you need my help.
--David Göthberg (talk) 02:20, 21 April 2009 (UTC)Reply

Thank you for encouraging me to try creating it myself (Template: search link). It looks like Template: search and Template: wpsearch have similar functions, but not exactly what I was looking for. I do like your idea of just pasting the namespace string, but it appears this would require manually adding curly braces around all the equal signs, unless there is some trick that I am missing. So, I went with the {{search link| New York | Search for New York | ns0 | ns5}} option ( Search for New York). It would be great to eventually make this flexible enough to support multiple methods for feeding the parameters and, at the same time, cover all the possible parameters. Thanks again for being so extremely helpful and feel free to modify what I have started. I was having some problems if the ns tokens were padded with spaces, but I believe I fixed this using the 'lc' parser function which strips the whitespace (and lowercases the tag). Plastikspork (talk) 04:07, 22 April 2009 (UTC)Reply

I just remembered a thing I had forgot: Using the {{fullurl}} magic word is much better than using a hardcoded URL, since {{fullurl}} gives the correct secure URL for users that are logged in through the secure server. (But I guess you already know that.)
And regarding feeding "{{search link| New York | ns0=1&ns5=1 }}": Oops. Right, when feeding content that contains an equal sign the parser thinks you are feeding ns0 = "1&ns5=1". So then you have to feed it like this:
{{search link| New York | 2 = ns0=1&ns5=1 }}
Note that "New York" here is parameter 1, thus the namespaces are parameter 2. But we humans tend to mix the numbers up and feed "1 = ns0=1&ns5=1". So then it is better we make the template use a named parameter, like this:
{{search link| New York | ns = ns0=1&ns5=1 }}
And when you need to strip away whitespace from a parameter but not lower-case it, then you can do like this:
{{#if:x| {{{1|}}} }}
The "x" is always there, so the if-case is always true, thus it returns the parameter. And just like many other parser functions the if-case strips away whitespace around the parameter. (I just learnt that trick myself some week ago.) But yeah, in this case we want to use {{lc:}}.
Since we are now talking template programming details, I will copy this discussion to the talk page of {{search link}} and continue there.
--David Göthberg (talk) 09:50, 22 April 2009 (UTC)Reply

End of part copied here from Wikipedia talk:Searching. --David Göthberg (talk) 09:55, 22 April 2009 (UTC)Reply

I added the "ns = all / ns0=1&ns5=1" functionality to the template, and I documented it. I did some testing, both of the "old" and the new functionality, and all seems to be working fine.
--David Göthberg (talk) 11:57, 22 April 2009 (UTC)Reply

Tharaka University college — Preceding unsigned comment added by KevinAmenya (talkcontribs) 12:20, 29 March 2021 (UTC)Reply

Default output

edit

Plastikspork: I see that you too prefer that a template have some kind of default output, even when it doesn't get the parameters it needs. I am thinking of several different possible default behaviours:

1: Currently this template outputs a search for its own template name, using the caption "search". Like this: search

2: It could return a link to Special:Search, with the caption "search", which would look like this: search

3: Or it could show its own basic syntax, which would look like this: {{search link|search string|link text}}

I think the template should only do this when it doesn't get parameter one. If it doesn't get parameter two then it can simply use the default caption "search" as it does now.

I think I slightly prefer option three. But the other two is okay too.

--David Göthberg (talk) 11:49, 22 April 2009 (UTC)Reply

I was actually planning to go with option three, but I just didn't get around to it. I made a first attempt. Feel free to add indentation/comments/etc, or improve it. Thanks! Plastikspork (talk) 23:19, 22 April 2009 (UTC)Reply
The code looks great, you are a skilled template coder. I can't see anything to improve in the code itself. I just did a little indenting and added some words in two of the comments. And all seems to work fine. I think this template is ready to deploy!
You should proofread the documentation, since I am not a native English speaker so I pretty often make some funny sentences. And besides, a documentation usually is not complete until 3-4 persons have worked it over. And change it to American English if that is your preference, since this is "your" template, you did all the hard work. (I just have my spell checking plug-in set to British English since that means many words are spelled more like in my native tongue Swedish.)
--David Göthberg (talk) 02:14, 23 April 2009 (UTC)Reply
Your command of the English language is exceptional. I have lived on both sides of the Atlantic, so I find myself thinking about the ENGVAR problem. Plastikspork (talk) 23:13, 23 April 2009 (UTC)Reply

I changed the default output for the "link text" to be the "search string". I think this is as logical a choice as "search", but is keeps me from writing the same text twice on the "List of common misspellings" page. Thanks again. Plastikspork (talk) 23:13, 23 April 2009 (UTC)Reply

Haha, thanks. Well, I have a good spell checking plug-in in my browser. And the English and Swedish languages are pretty close, so that makes it easier.
Oh, I like your new default. Yeah, in most cases one probably want to see the search string, not the word "search". So yeah, will save a lot of typing in cases like yours.
And now I am curios: Why did you add whitespace stripping around parameter 1 when it is used as link text? Was it needed?
And I am thinking, we probably want to be able to use the template like this:
{{search link|New York| |ns0}} = New York
That is, when parameter 2 is empty but defined, then we also want the search string to be the caption. Currently when feeding an empty but defined parameter 2 we get no caption, just a numbered link. I can fix it for you if you want it but don't know how to do it, but I think you know.
--David Göthberg (talk) 00:16, 24 April 2009 (UTC)Reply
Good idea. I believe I correctly modified it. You are correct about the added stripping of whitespace around the link text when it's set to parameter 1, it does not appear to be necessary, so I removed it. Thanks again. Plastikspork (talk) 04:34, 24 April 2009 (UTC)Reply
Yes, your modification works fine. I updated the documentation accordingly.
And a side note: Since parameter 1 and 2 now are within an if-case when fed as link text, as a side effect they both get whitespace stripping. Not that we need it in this case, but I just wanted to mention when we get whitespace stripping.
--David Göthberg (talk) 10:44, 24 April 2009 (UTC)Reply
Yes, good point. Thanks! Plastikspork (talk) 14:52, 24 April 2009 (UTC)Reply

Not for use in articles?

edit

Similar search templates such as {{Google custom}} and {{Search subpages link}} contain warnings (both in the templates and their documentation pages) against using search links from articles. Wikipedia editors added these warnings after this discussion:

indicated the need to exclude such links from article space. To avoid a repetitive nomination for deletion, someone may want to add a similar warning to this template and its documentation. I can add the warnings if you like, but since other editors are actively developing this template I hesitate to jump in and possibly break something. --Teratornis (talk) 20:06, 29 April 2009 (UTC)Reply

  Done Thanks for the suggestion. Plastikspork (talk) 21:32, 29 April 2009 (UTC)Reply
edit

I created {{Search subpages link}} to work similarly to {{Search link}} except to use the prefix: search modifier to search subpage trees. Many issues similar to the above discussions apply (the need to urlencode the arguments, etc.). It would be nicer to put the prefix: into the URL as a separate URL parameter rather than as a modifier to the search= parameter, to keep it out of the resulting search box, but I could not find a way to make that work. I don't think it would be practical to try combining {{Search subpages link}} with {{Search link}}, since the latter is all about searching on namespaces, whereas the former searches subpage trees which are always within one namespace. --Teratornis (talk) 20:12, 29 April 2009 (UTC)Reply

I could add a prefix option but perhaps it makes sense, as you say, to just have a separate {{search subpages link}}. I won't add it if it's not being requested. Plastikspork (talk) 21:34, 29 April 2009 (UTC)Reply
Keeping the functions in different templates seems better to me, to keep the template options compact and easy to remember. Not to mention that the namespace feature seems completely disjoint from the prefix feature - having both in the same template might tempt someone to mix them, with unpredictable results. Plus I'm noticing some odd behavior with some searches with {{Search subpages link}} (and a derivative special-case template I'm working on, {{Search help desk}}, which is still in a sandbox as User:Teratornis/Search help desk while I debug it). I haven't determined whether the problems are with the new Wikipedia search features, or how I'm using them. Having separate templates makes experimenting and debugging easier, since I don't have to worry about breaking someone else's features while I'm testing mine. --Teratornis (talk) 03:51, 1 May 2009 (UTC)Reply

wildcard

edit

Is *wild card" broke? OR is it not? — CpiralCpiral 21:49, 23 February 2013 (UTC)Reply

This is a problem with the parserfunction turning the * into a bullet. Unfortunately, I don't see any easy way to fix this at the moment, so try this {{search link|{{asterisk}}wild card"}} for now. Plastikspork ―Œ(talk) 22:46, 23 February 2013 (UTC)Reply
It looks like that doesn't work either. I will work on it ... Thanks! Plastikspork ―Œ(talk) 22:56, 23 February 2013 (UTC)Reply
Okay, I think I fixed it. Thanks! Plastikspork ―Œ(talk) 23:03, 23 February 2013 (UTC)Reply

Who is Slovene?

edit

Why does {{sl|wp:pagename}} return "(Slovene)": wp:pagename? — CpiralCpiral 03:59, 5 March 2013 (UTC)Reply

(in Slovene)? It was a language icon for external links. Now {{sl}} redirects here, per Template talk:sl, because now we have
  • This template, {{sl}} to directly create general search links of any and all kinds
  • {{slre}} to sandbox and develop a general regexp search, then share its search link
  • {{tlre}} to sandbox and develop a template regexp search, then share its search link

For why these sandboxes may be important, see mw:Help:CirrusSearch's insource:/regexp/ searches. To learn more about MediaWiki's Elastica regexp extension, see the documentation for slr and slt.

CpiralCpiral 21:42, 8 July 2015 (UTC)Reply

Insource: doesn't work

edit

The recommended search method, when using insource:/regexp/ (mw:Help:CirrusSearch#insource:) is to layer two or three filters, but it doesn't display:

{{search link|insource:val insource:/\{val/ insource:/u=/}}

CpiralCpiral 19:09, 11 June 2015 (UTC)Reply

Oh, I forgot to use either 1= or {{=}} if I have an "=" in my search link. Thanks. — CpiralCpiral 21:05, 2 July 2015 (UTC)Reply

Insource:/regex/ without a link=label so that the text=query is the label, now works with square brackets. I edited the template after testing in the sandbox. I also edited the Advanced section of the documentation, redirected links, and removed unnecessary material, replacing it with other material. Now its more usable in its important place in the {{sl}}/{{slre}}/{{tlre}} scheme. — CpiralCpiral 10:31, 12 July 2015 (UTC)Reply

Proposed change for blank input

edit

currently, when the input is blank, this template returns "documentation" in the form of the following nowiki string: {{search link|search string|link text}}. I would like change this to return a link to the page [1] which would then allow the user to type in a search, without having it pre-filled. any comments? Frietjes (talk) 17:33, 2 December 2014 (UTC)Reply

I must be missing something. See these tests:

  • {{sl|text=}}
  • {{sl}}
  • {{sl|}}
  • {{sl|text=0}}0

CpiralCpiral 11:53, 12 July 2015 (UTC)Reply

{{search link||search}} still works. Frietjes (talk) 23:00, 21 July 2015 (UTC)Reply

Default search domain

edit

The default search domain is now article space. This change does not effect an IP who clicks on a search link that has no ns specified. But for logged in users who have set there own user preference for there own search domain at Special:Search Advanced, it will have a beneficial effect.

When someone creates a search link without specifying a search domain, limiting a default search domain to article space is beneficial for two scenarios: 1) the creator was unfamiliar with the intricacies of search behaviors, assumed the default search domain was article space, and did not read Help:Searching or this Template:Search link documentation, and the link they created is activated by a user who has set there default search domain to all namespaces or to any other combination of namespaces: the benefit is that it no longer loads the search engine while unnecessarily violating the creators intentions. 2) The advanced user doesn't want to have to specify the namespaces every time, no matter what, because it is a 3rd parameter, and parameter two is often unneeded, so setting the 3rd parameter requires naming it, and that opens up the writing of the search link to easy errors.

When the search link is tested by an advanced creator, they will probably notice the effected search domain, and change it accordingly if needed. — CpiralCpiral 06:43, 8 August 2015 (UTC)Reply

Search within the pages within a WikiProject

edit

Am trying to specifically search for a url within a specific Wikiproject. Any advice on how to do this? Doc James (talk · contribs · email) 18:09, 12 March 2017 (UTC)Reply

@Doc James: I'm no expert, but I think you're looking for the "prefix" parameter. If you were looking for "test" in WikiProject Medicine, for instance, you'd type
Test prefix:Wikipedia:WikiProject Medicine
into the search box. To search the talk pages, it would be a separate search:
Test prefix:Wikipedia talk:WikiProject Medicine
For a URL, you could enclose it in quote marks:
"http://biogeosciences.agu.org" prefix:Wikipedia:WikiProject Medicine
I don't know that the quotation marks are necessary, but they won't hurt.
I hope this helps. — Gorthian (talk) 16:33, 13 March 2017 (UTC)Reply
To clarify I want to search the content pages within a specific Wikiproject not the WP itself. Doc James (talk · contribs · email) 17:25, 13 March 2017 (UTC)Reply
Ah, I think I understand: you want to search articles that are "claimed" by a certain WikiProject. The PetScan tool (manual) is very powerful and configurable, BUT I don't think it searches the text of articles. Or, if it does, I don't know how to do it. — Gorthian (talk) 04:05, 14 March 2017 (UTC)Reply
Okay thanks. I will keep looking. Doc James (talk · contribs · email) 04:19, 15 March 2017 (UTC)Reply

Searching for strings that use specific capitalization

edit

Is it possible to specify capitalization in search strings? Also, is it possible to exclude redirects from search results? (I'm a typo hunter, and have a couple of projects in mind. E.g., fixing instances of "Sig Sauer" (SIG Sauer) and "freemason".) —DocWatson42 (talk) 10:45, 6 May 2017 (UTC)Reply

DocWatson42, I believe "insource" is case sensitive. for example, try this vs this. Frietjes (talk) 14:37, 4 June 2017 (UTC)Reply
@Frietjes: That works—thank you. ^_^ —DocWatson42 (talk) 15:22, 6 June 2017 (UTC)Reply

Option to add quote marks?

edit

Is there an option to add quote marks automatically? This search, for example, results in about twice as many false positives (9,000) as useful search results (3,000) when I am looking for the actual word. Adding quote marks works better, but I would rather have it as an option than have to type the quote marks every time. – Jonesey95 (talk) 13:16, 20 May 2023 (UTC)Reply