# `SearchResultDedupe`
[🔗](https://github.com/jaizendra-netizen/search_result_dedupe/blob/main/lib/search_result_dedupe.ex#L1)

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.

# `row`

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

# `analyze`

```elixir
@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`

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

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

# `parse`

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

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

# `pct`

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

Format a percentage with one decimal.

# `render`

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

Render the analysis as text.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
