Module:ZZNL

From Bodhicitta

Documentation for this module may be created at Module:ZZNL/doc

local p={}
function p.probe()
  local id='RKTSK 231'
  local needle='('..id..')'
  local function ask(c)
    return mw.smw.ask{c,'?#-=Page','?QuoteSource#=QuoteSource','?SegmentOrder#=SegmentOrder',limit=5000} or {}
  end
  local rows=ask('[[QuoteSource::~*'..id..'*]]')
  local seen={}
  for _,r in ipairs(rows) do local pg=r.Page; if type(pg)=='table' then pg=pg[1] end
    if pg then seen[pg]=true end end
  local added=0
  for _,r in ipairs(ask('[[QuoteSource::~*\n*]]')) do
    local pg=r.Page; if type(pg)=='table' then pg=pg[1] end
    if not pg or not seen[pg] then rows[#rows+1]=r; added=added+1 end
  end
  local hits=0
  for _,r in ipairs(rows) do
    local src=r.QuoteSource; if type(src)=='table' then src=src[1] end
    if type(src)=='string' and src:find(needle,1,true) then hits=hits+1 end
  end
  return 'rows='..#rows..' added='..added..' exact-hits='..hits
end
return p