-- Last, First
local C1 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..FIRST
-- First Last
local C2 = "%22%20OR%20creator%3A%22"..FIRST.."%20"..LAST
local CALL = C1..C2
-- First Last
local T1 = "%22%20OR%20title%3A%22"..FIRST.."%20"..LAST
local TALL = T1
-- Last, First
local D1 = "%22%20OR%20description%3A%22"..LAST.."%2C%20"..FIRST
-- First Last
local D2 = "%22%20OR%20description%3A%22"..FIRST.."%20"..LAST
local DALL = D1..D2  
if sopt == "t" or sopt == "tx" then
return SALL .. CALL .. TALL .. DALL .. "%22"
else
-- Last, F.
local C3 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..firstinitial.."%2E"
local CALL = CALL..C3
return SALL .. CALL .. TALL .. DALL .. "%22"
end  
end  
function p.threeWords(N, sopt)
-- CAUTION: The following is near the max 2000 character URL limit for most browsers when using long names
-- such as "René-Nicolas Dufriche Desgenettes".  
local FIRST = p.urlX(N[1])
local MIDDLE = p.urlX(N[2])
local LAST = p.urlX(N[3])
local firstinitial = p.urlX( p.firstLetter(N[1]) )
local middleinitial = p.urlX( p.firstLetter(N[2]) )  
-- Last, First Middle
local S1 = "%28subject%3A%22"..LAST.."%2C%20"..FIRST.."%20"..MIDDLE
-- Last, First M.
local S2 = "%22%20OR%20subject%3A%22"..LAST.."%2C%20"..FIRST.."%20"..middleinitial.."%2E"
-- Last, F. M.
local S3 = "%22%20OR%20subject%3A%22"..LAST.."%2C%20"..firstinitial.."%2E%20"..middleinitial.."%2E"
-- First Middle Last
local S4 = "%22%20OR%20subject%3A%22"..FIRST.."%20"..MIDDLE.."%20"..LAST
-- First M. Last
local S5 = "%22%20OR%20subject%3A%22"..FIRST.."%20"..middleinitial.."%2E%20"..LAST
-- F. M. Last
local S6 = "%22%20OR%20subject%3A%22"..firstinitial.."%2E%20"..middleinitial.."%2E%20"..LAST
local SALL = S1..S2..S3..S4..S5..S6
-- First Middle Last
local C1 = "%22%20OR%20creator%3A%22"..FIRST.."%20"..MIDDLE.."%20"..LAST
-- First M. Last
local C2 = "%22%20OR%20creator%3A%22"..FIRST.."%20"..middleinitial.."%2E%20"..LAST
-- F. M. Last
local C3 = "%22%20OR%20creator%3A%22"..firstinitial.."%2E%20"..middleinitial.."%2E%20"..LAST
-- F. Middle Last
local C4 = "%22%20OR%20creator%3A%22"..firstinitial.."%2E%20"..MIDDLE.."%20"..LAST
-- Last, First Middle
local C5 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..FIRST.."%20"..MIDDLE
-- Last, First M.
local C6 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..FIRST.."%20"..middleinitial.."%2E"
-- Last, F. M.
local C7 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..firstinitial.."%2E%20"..middleinitial.."%2E"
-- Last, F. M.
local C8 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..firstinitial.."%2E%20"..MIDDLE
local CALL = C1..C2..C3..C4..C5..C6..C7..C8
-- First Middle Last
local T1 = "%22%20OR%20title%3A%22"..FIRST.."%20"..MIDDLE.."%20"..LAST
-- First M. Last
local T2 = "%22%20OR%20title%3A%22"..FIRST.."%20"..middleinitial.."%2E%20"..LAST
-- F. M. Last
local T3 = "%22%20OR%20title%3A%22"..firstinitial.."%2E%20"..middleinitial.."%2E%20"..LAST
local TALL = T1..T2..T3
-- First Middle Last
local D1 = "%22%20OR%20description%3A%22"..FIRST.."%20"..MIDDLE.."%20"..LAST
-- First M. Last
local D2 = "%22%20OR%20description%3A%22"..FIRST.."%20"..middleinitial.."%2E%20"..LAST
-- F. M. Last
local D3 = "%22%20OR%20description%3A%22"..firstinitial.."%2E%20"..middleinitial.."%2E%20"..LAST
-- Last, First Middle
local D4 = "%22%20OR%20description%3A%22"..LAST.."%2C%20"..FIRST.."%20"..MIDDLE
-- Last, First M.
local D5 = "%22%20OR%20description%3A%22"..LAST.."%2C%20"..FIRST.."%20"..middleinitial.."%2E"
local DALL = D1..D2..D3..D4..D5  
if sopt == "t" or sopt == "tx" then
return SALL .. CALL .. TALL .. DALL .. "%22"
else
-- Last, First
local S7 = "%22%20OR%20subject%3A%22"..LAST.."%2C%20"..FIRST
-- First Last
local S8 = "%22%20OR%20subject%3A%22"..FIRST.."%20"..LAST
local SALL = SALL..S7..S8
-- First Last
local C9 = "%22%20OR%20creator%3A%22"..FIRST.."%20"..LAST
-- Last, First
local C10 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..FIRST
local CALL = CALL..C9..C10
-- First Last
local T4 = "%22%20OR%20title%3A%22"..FIRST.."%20"..LAST
local TALL = TALL..T4
-- First Last
local D6 = "%22%20OR%20description%3A%22"..FIRST.."%20"..LAST
-- Last, First
local D7 = "%22%20OR%20description%3A%22"..LAST.."%2C%20"..FIRST
local DALL = DALL..D6..D7  
return SALL .. CALL .. TALL .. DALL .. "%22"
end
end  
function p.fourWords(N, sopt)  
local FIRST = p.urlX(N[1])
local SECOND = p.urlX(N[2])
local THIRD = p.urlX(N[3])
local LAST = p.urlX(N[4])  
local firstinitial = p.firstLetter(N[1])
local secondinitial = p.firstLetter(N[2])
local thirdinitial = p.firstLetter(N[3])  
if sopt == "t" or sopt == "tx" then
-- Last, First Second Third
local S1 = "%28subject%3A%22"..LAST.."%2C%20"..FIRST.."%20"..SECOND.."%20"..THIRD
-- First Second Third Last
local S2 = "%22%20OR%20subject%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST
-- Last, First Second Third
local C1 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..FIRST.."%20"..SECOND.."%20"..THIRD
-- First Second Third Last
local C2 = "%22%20OR%20creator%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST
-- First Second Third Last
local T1 = "%22%20OR%20title%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST
-- First Second Third Last
local D1 = "%22%20OR%20description%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST  
return S1..S2..C1..C2..T1..D1.."%22"
end  
-- Last, First Second Third
local S1 = "%28subject%3A%22"..LAST.."%2C%20"..FIRST.."%20"..SECOND.."%20"..THIRD
-- First Second Third Last
local S2 = "%22%20OR%20subject%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST
-- Last, First Second Third
local C1 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..FIRST.."%20"..SECOND.."%20"..THIRD
-- First Second Third Last
local C2 = "%22%20OR%20creator%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST
-- Last, F. S. T.
local C3 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..firstinitial.."%2E%20"..secondinitial.."%2E%20"..thirdinitial.."%2E"
-- First Second Third Last
local T1 = "%22%20OR%20title%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST
-- First Second Third Last
local D1 = "%22%20OR%20description%3A%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST  
return S1..S2..C1..C2..C3..T1..D1.."%22"  
end  
-- ElasticSearch speed/resource problems if first letter of first word is "*" wildcard ie. accented letter
-- Build special search in these cases.
-- https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_wildcards
function p.wildfix(N, count)  
--- Split along "-" and use only first word ie. John-Taylor-Smith becomes John
local NF = mw.text.split(N[1], "-")
local NL = mw.text.split(N[count], "-")  
-- ..but use full name for 1-word names
if count == 1 then
NF[1] = N[1]
NL[1] = N[1]
end  
-- ((Fïrst OR First) AND (Lást OR Last))
return "%28%28%22" .. NF[1] .. "%22%20OR%20" .. p.ia_deaccent(NF[1]) .. "%29%20AND%20%28%22" .. NL[1] .. "%22%20OR%20" .. p.ia_deaccent(NL[1]) .. "%29"  
end  
-- Return 1 if the first letter of first word, or any single-letter word, is extended ascii
function p.wildcheck(N, count)
local i = 0  
-- first letter of first word is extended ascii
if N[1]:byte(1) < 32 or N[1]:byte(1) > 126 then return 1 end  
-- any single-letter word that is composed of only extended ascii
while i < count do
i = i + 1
if N[i]:len == 1 then
if N[i]:byte(1) < 32 or N[i]:byte(1) > 126 then return 1 end
end
end
return 0
end  
function trimArg(arg)
if arg == "" or arg == nil then
return nil
else
return mw.text.trim(arg)
end
end  
function p.mediaTypes(argsmedia)  
-- Added a default mediatype Dec 2015 due to too many false positives in the software mediatype, caused by birth-death dates catching numbers in source codes
local media = "-mediatype:software"  
if argsmedia ~="" and argsmedia ~=nil then
local medialist = mw.text.split(mw.text.trim(argsmedia), " ")
local al, acount = mw.ustring.gsub(mw.text.trim(argsmedia), "%S+", "")
local i = 0
repeat -- the following could be condensed but repetitive for clarity
i = i + 1