Elixir library and Mix task. Give it a CSV of search queries and the result URLs each one returned. It normalises every URL, then shows how many rows were duplicates, which URLs were returned by more than one query, which hosts supply the most unique URLs and how many unique URLs each query brought. It reads the file you give it, fetches nothing and has no network access.
URL normalisation, in this order: the URL is trimmed; the scheme and host are lowercased; http is treated as https; a leading www. is removed from the host; the fragment (everything from #) is removed; query parameters whose name starts with utm_ (any letter case) are removed and all other parameters are kept in their original order; trailing slashes are removed from the path unless the path is just /. Path and parameter values keep their letter case. Two URLs that differ only in those ways count as one. The query column is trimmed and compared exactly, so letter case counts.
Duplicates removed is the number of rows minus the number of unique URLs. A URL returned by more than one query means the same normalised URL appeared under at least two different queries; the first 10 are listed, most queries first and then by URL, with the queries. Hosts are listed by unique URLs, first 10, with the share of all unique URLs as a percentage with 1 decimal. Queries are listed by unique URLs, most first, then by query.
Exit code 0 means the report was printed, 2 means the input could not be read: a missing file, a missing column, no rows, an empty query, or a URL without :// or without a host (the error names the line).
Part of the OneGTMLab free GTM tools. Background on the idea: Exa vs Parallel AI.
Install
{:search_result_dedupe, "~> 1.0"} # in mix.exs depsUse
CSV columns: query, url. The sample has 9 rows under 3 queries, with a trailing slash, a utm_ parameter, a fragment and a different letter case used on purpose.
$ mix search_result_dedupe sample.csv
rows: 9
unique URLs after normalisation: 6
duplicates removed: 3
URLs returned by more than one query: 2
https://example.com/page-one (2 queries: Query A; Query B)
https://example.org/guide (2 queries: Query A; Query C)
hosts by unique URLs (first 10):
example.com: 3 URLs (50.0%)
example.org: 2 URLs (33.3%)
docs.example.net: 1 URLs (16.7%)
per query (most unique URLs first):
Query B: 3 rows, 3 unique URLs
Query C: 3 rows, 3 unique URLs
Query A: 3 rows, 2 unique URLs
Test
mix testOffline, no network calls, no dependencies beyond the language runtime. MIT licensed.