1. 12
  1.  

  2. 3

    A couple of related code search tools include https://github.com/ggreer/the_silver_searcher and https://code.google.com/p/codesearch/.

    Last time I looked, ag didn’t have proper support for gitignores (except on my fork, which is a bit slower and now out-of-date). But it’s does have a lot of other neat features, and it is fast. On reflection, I have no idea why ag’s strstr would be faster than the one in the C standard library, which at least on glibc uses SSE instructions. So that strikes me as weird.

    Codesearch is almost always fastest, because it preindexes your source code. But I’m a bit wary of using it, because I worry that I’ll miss some code that I added since the last indexing. It doesn’t support backreferences, although I only use those once in a blue moon. Also, it’s a bit stupid – searching for “memory link” in the Linux kernel takes almost a second even though the phrase only appears once; that’s because both words are very common and it uses a trigram index instead of a FREE index.

    What I really want is the best of all worlds: codesearch-style preindexing, with the varied options that ag and ack have (particularly search-by-language), and automatic reindexing on code changes.

    One day, I’ll probably write it.

    1. 2

      I don’t know if you’d checked out the search engine I’m wroting for 500lines but it is meant to support that kind of use case — eventually. I don’t know what FREE indexes are, though! Maybe I should learn about them.

      1. 1

        One of the things I toyed with a few months ago in ack was the idea of having an index of digraphs for each directory that would get rebuilt on the fly. Premise is that 99% of the time when you’re acking you’re acking unchanged files in a code base. If I ack the word “sales” and I know that only two files in the directory contain “sa” anywhere in them, then I only need to search those two files. Also, it would index first and last line number in the file, so that if you know that the last place digraph “sa” shows up is on line 7 of foo.c, then ack can stop searching at line 7.

        But then other side projects that pay money took priority. :-/

      2. 3

        I’ve been using ack for at least 3 years now and it is now one of the group of tools I install on new machines I’ll be doing any development on. When it is not present I notice it’s absence.

        1. 2

          Looks like a handy tool. I’ll probably give it a try and report back. :)