KristerV

KristerV

Hexdocs search engine for devs

How I currently use Hexdocs

I use hexdocs all day every day, but finding the right module and function takes too long even with my bookmark system.

Too much scrolling, reading, clicking around for the right function. I already know what function I need!

Solution

So I’m making a tool that lets you search many Elixir packages from a single website. Yeah, it’s a website and not a package (couldn’t find a better section).

I’ll show you what I mean. This is very much a WIP, but i have the data in and search does function.

Here’s a few implementation details.

Data source

There are many ways to get data, but I wanted this to work with any package (not that all are supported) and without much going on on disk (don’t want to generate docs myself).

I have a spider that

  1. Gets the sidebar-items.json file from hexdocs.pm/{package}
  2. Parses JSON, convert it into rows
  3. Inserts into DB

Crawly was way too much overhead, would use HTTPoison and Floki next time. May refactor at one point.

Fuzzy search

I’m just using ILIKE in Postgres for now.

def list_fuzzy(str) do
    search_str =
      str
      |> String.split(" ")
      |> Enum.intersperse("%")
      |> Enum.join()
      |> then(&"%#{&1}%")

    from(p in Page,
      where: fragment("? ilike ?", p.search_body, ^search_str)
    )
    |> Repo.all()
  end

Ideally the index would be client-side for instant results, but I’m not sure how to do fuzzy search in JS yet and I probably wont think about it unless the service gets slow.

Version 1.0 plans

The end result would ideally have

  • iframe with hexdocs straight in it for instant results (not sure how possible)
  • auto-bookmark popular pages
  • keyboard navigation

But we’ll see. It’s just a fun side-project.

Feedback welcome

I am building it for myself, but obviously would love more users and ideas on what would be awesome.
Also looking for cool domain names. otherwise it’s going to be hexdocs-search.krister.ee - not so pretty. I’d go with hexdocs.search, but that’s not easy to aquire. TLD is supposed to exist, but not on my provider, Namecheap.

Most Liked

gregvaughn

gregvaughn

I don’t want to take away your fun on a side project, but if it were me, I’d use mix hex.docs fetch to cache all docs for my project’s deps locally, then run rg (ripgrep) in that directory for function names.

17
Post #2
stefanchrobot

stefanchrobot

TIL mix hex.docs fetch! It’s exactly what I was looking for!

But… it would be great to have something like mix hex.docs offline (without more args) that would open up aggregated docs for the dependencies of the current project. I was actually thinking about opening an issue on ExDoc to suggest something like that. Thoughts?

11
Post #6
dimitarvp

dimitarvp

Yeah, that’s exactly what I do. I crafted a few very simple ripgrep regex-ish expressions and alias-ed them in my ~/.zshrc and then just do e.g. exdoc Enum.group_by in the terminal.

…Actually it might be time to extend that script to use open (Mac) / xdg-open (Linux) so as to just open the docs in a browser. :thinking:

KristerV

KristerV

The service is now live. Lots of work to be done still, but basically usable already now.

Website: https://hexdocs.krister.ee/
GitLab: Krister Viirsaar / hexdocs-search · GitLab

Notes:

  • the search results dropdown is meant to stay open. sometimes you want to compare different functions.
  • The packages included for now are (open for suggestions)
[
    "elixir",
    "plug",
    "ecto",
    "ecto_sql",
    "phoenix",
    "phoenix_html",
    "phoenix_live_view",
    "phoenix_pubsub",
    "ex_unit",
    "timex",
    "quantum"
  ]

oh, that didn’t even occur to me. good idea! please keep us updated.

edit: oh… i had falsely assumed if it works for /elixir it’ll work for others and in prod it’s clear it doesn’t.
edit2: assumption was correct. code wasn’t. fixed.

dimitarvp

dimitarvp

Yeah, probably before hitting 50 years old would be nice :003: (currently 42).

Where Next?

Popular in RFCs Top

bennydreamtech23
So recently I have been looking for ways to improve my workflow in elixir and I saw all the commands I need to run to setup a project and...
New
senconscious
EctoJuno is a package that provides parsing, validation and applying sorting parameters for your ecto queries on models. Currently sortin...
New
UlrikHD
I’ve been wanting to write a library for the lemmy API so that I can port some of my scripts over to elixir. For those unfamiliar with le...
New
sodapopcan
EDIT: I forgot to link the repo, ha: GitHub - sodapopcan/vials: Tweak your mix generators This project is not quite ready for prime-time...
New
pepicrft
Hey folks :wave: I implemented a library that uses macros extensively, and I’d appreciate feedback from people that are more versed at w...
New
wingyplus
Hi, I start working on the fork version of Elixir GRPC. What I’ve done is the past few days: Support Elixir 1.11+ Support OTP 23+ OTP...
New
KristerV
I got fed up with removing unused aliases manually so made a package for it: GitHub - KristerV/remove_unused_ex: Remove unused aliases an...
New
felix-starman
I’ve noticed that often when I find myself needing to manually set content-disposition - [MDN] the advice is usually to use URI.encode_ww...
New
KristerV
How I currently use Hexdocs I use hexdocs all day every day, but finding the right module and function takes too long even with my bookma...
New
benlime
In the last couple of days I was playing around with LiveView, function components and animations. I ended up with a little prototype whi...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement