Module:SMWUtils: Difference between revisions
Add deduplication by subject column to eliminate duplicate rows from multiple matching subobjects (via update-page on MediaWiki MCP Server) |
Fix deduplication: key on printout columns instead of subject (subobject subjects are unique per-input) (via update-page on MediaWiki MCP Server) |
||
| Line 42: | Line 42: | ||
end | end | ||
-- Deduplicate rows by | -- Deduplicate rows by printout columns, keeping the first occurrence | ||
local function | -- Uses stripped text of printout columns (2..n+1) as the dedup key, | ||
-- since subobject queries produce unique subjects (e.g. Page#sub1, Page#sub2) | |||
-- but identical printout values for the same parent page | |||
local function deduplicateRows(rows, numPrintouts) | |||
local seen = {} | local seen = {} | ||
local deduped = {} | local deduped = {} | ||
for _, row in ipairs(rows) do | for _, row in ipairs(rows) do | ||
local | local keyParts = {} | ||
for j = 2, numPrintouts + 1 do | |||
table.insert(keyParts, stripHtml(row[j]) or '') | |||
end | |||
local key = table.concat(keyParts, '|') | |||
if not seen[key] then | if not seen[key] then | ||
seen[key] = true | seen[key] = true | ||
| Line 191: | Line 198: | ||
end | end | ||
-- Deduplicate | -- Deduplicate (multiple subobjects on same page produce duplicate rows) | ||
filtered = | filtered = deduplicateRows(filtered, #printoutProps) | ||
-- Build headers list | -- Build headers list | ||
| Line 272: | Line 279: | ||
end | end | ||
-- Deduplicate | -- Deduplicate (multiple subobjects on same page produce duplicate rows) | ||
filtered = | filtered = deduplicateRows(filtered, #printoutProps) | ||
-- Build headers list | -- Build headers list | ||