Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fulltext search ignoring comments

I want fulltext search for my JavaScript code, but I'm usually not interested in matches from the comments.

How can I have fulltext search ignoring any commented match? Such a feature would increase my productivity as a programmer.

Also, how can I do the opposite: search within the comments only?

(I'm currently using Text Mate, but happy to change.)

like image 217
Randomblue Avatar asked Sep 05 '11 19:09

Randomblue


1 Answers

See our Source Code Search Engine (SCSE). This tool indexes your code base using the langauge structure to guide the indexing; it can do so for many languages including JavaScript. Search queries are then stated in terms of abstract language tokens, e.g., to find identifiers involving the string "tax" multiplied by some constant, you'd write:

  I=*tax* '*' N

This will search all indexed languages only for identifiers (in each language) following by a '*' token, followed by some kind of number. Because the tool understands language structure, it isn't confused by whitespace, formatting or interverning comments. Because it understands comments, you can search inside just comments (say, for authors):

   C=*Author* 

Given a query, the SCSE finds all the hits across the code base (possibly millions of lines), and offers these as set of choices; clicking on choice pulls up the file with the hit in the middle outlined where the match occurs.

If you insist on searching just raw text, the SCSE provides grep-style searches. If you have only a small set of files, this is still pretty fast. If you have a big set of files, this is a lot slower than language-structure based searches. In both cases, grep like searches get you more hits, usually at the cost of false positives (e.g., finding "tax" in a comment, or finding a variable named "Authorization_code"). But at least you have the choice.

While this doesn't operate from inside an editor, you can launch your editor (for most editors) on a file once you've found the hit you want.

like image 66
Ira Baxter Avatar answered Sep 18 '22 23:09

Ira Baxter