Documentation for this module may be created at Module:NeoWikiQueries/doc
local p = {}
function p.propertiesOfPage( frame )
local pageName = frame.args[1] or ''
if pageName == '' then return '' end
local rows = mw.neowiki.query([[
MATCH (page:Page {wiki_id: $wikiId})
WHERE page.name = $pageName
MATCH (page)-[:HasSubject]->(s:Subject)
UNWIND keys(s) AS prop
WITH DISTINCT prop
WHERE NOT prop IN ['id', 'wiki_id', 'name']
RETURN prop ORDER BY prop
]], { pageName = pageName, wikiId = mw.site.server })
-- Fallback: use the wiki's DB name as wikiId if mw.site.server doesn't match
if rows == nil or #rows == 0 then return 'No properties found.' end
local result = {}
for _, row in ipairs( rows ) do
table.insert( result, '* ' .. row.prop )
end
return table.concat( result, '\n' )
end
function p.pagesWithProperty( frame )
local propertyName = frame.args[1] or ''
if propertyName == '' then return '' end
local rows = mw.neowiki.query([[
MATCH (page:Page)-[:HasSubject]->(s:Subject)
WHERE s[$propertyName] IS NOT NULL
RETURN DISTINCT page.name AS pageName
ORDER BY pageName
]], { propertyName = propertyName })
if rows == nil or #rows == 0 then return 'No pages found.' end
local result = {}
for _, row in ipairs( rows ) do
table.insert( result, '* [[' .. row.pageName .. ']]' )
end
return table.concat( result, '\n' )
end
function p.pagesWithPropertyValue( frame )
local propertyName = frame.args[1] or ''
local propertyValue = frame.args[2] or ''
if propertyName == '' or propertyValue == '' then return '' end
local rows = mw.neowiki.query([[
MATCH (page:Page)-[:HasSubject]->(s:Subject)
WHERE s[$propertyName] = $propertyValue
OR $propertyValue IN s[$propertyName]
RETURN DISTINCT page.name AS pageName
ORDER BY pageName
]], { propertyName = propertyName, propertyValue = propertyValue })
if rows == nil or #rows == 0 then return 'No pages found.' end
local result = {}
for _, row in ipairs( rows ) do
table.insert( result, '* [[' .. row.pageName .. ']]' )
end
return table.concat( result, '\n' )
end
return p