SearchResultDedupe (search_result_dedupe v1.0.0)

Copy Markdown View Source

Normalise the URLs in a list of search results and show what is duplicated.

Input is a CSV with the columns query and url. Extra columns are ignored. The query is trimmed and compared exactly (case counts). Every URL is normalised with these rules:

  • trimmed
  • scheme and host lowercased
  • http treated as https
  • a leading www. removed from the host
  • the fragment (everything from #) removed
  • query parameters whose name starts with utm_ (any letter case) removed, all others kept in their order
  • trailing slashes removed from the path unless the path is just /

The tool reads the file you give it. It fetches nothing and has no network access.

Summary

Functions

Analyse parsed rows (URLs already normalised). Returns a map with :rows, :unique, :duplicates, :multi_total, :multi (URLs returned by more than one query, most queries first, each {url, [queries]}), :hosts and :queries.

Normalise one URL. Returns {:ok, url} or {:error, reason}.

Parse CSV text into rows. Returns {:ok, rows} or {:error, message}.

Format a percentage with one decimal.

Render the analysis as text.

Types

row()

@type row() :: %{line: pos_integer(), query: String.t(), url: String.t()}

Functions

analyze(rows)

@spec analyze([row()]) :: map()

Analyse parsed rows (URLs already normalised). Returns a map with :rows, :unique, :duplicates, :multi_total, :multi (URLs returned by more than one query, most queries first, each {url, [queries]}), :hosts and :queries.

normalize(url)

@spec normalize(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Normalise one URL. Returns {:ok, url} or {:error, reason}.

parse(text)

@spec parse(String.t()) :: {:ok, [row()]} | {:error, String.t()}

Parse CSV text into rows. Returns {:ok, rows} or {:error, message}.

pct(part, whole)

@spec pct(number(), number()) :: String.t()

Format a percentage with one decimal.

render(a)

@spec render(map()) :: String.t()

Render the analysis as text.