Code search in Gforge AS 5.7

One of the new features of Gforge AS 5.7 is the support for source code indexing/search using doxygen and tsearch2 in both Subversion and CVS repositories. In this article, we’ll go trough a complete example to show the highlights of this feature.

Setup

In order to use this feature, you’ll need doxygen. You can get it from your distribution repositories or compile it from source.

After installing doxygen, you may need to edit your /etc/gforge/gforge.conf file. Look for the $config['doxygenPath'] configuration variable, and change it as need.ed Then, recreate the configuration cache.

#cd /opt/gforge5 && php bin/create_config_cache.php

Setting the path for code indexing

If you want to enable the code indexing in a given project, you’ll need to set one or more source code paths. In this example we will use subversion, but you can accomplish the same with CVS.

Navigate to SVN->Admin->Code search paths, you will see a screen like this

Browse search paths

In this example we will use the source code from pgadmin, a graphical client for PostgreSql.
We are interested in the code under /trunk/pgadmin path, so let’s proceed to add the path.

Index path added

In this case we are using C++, but doxygen can handle several  other languages (C, Java, Objective-C, Python,PHP, etc), check the doxygen documentation for a complete list of supported languages.

Now that we have configured the path a cronjob executed on a daily basis will index all the code found under the specified path. However, you can run the indexing script manually:

#cd /opt/gforge5
#php bin/gforge cronjobs scm_index

Some searching examples

Now that we have all the source code indexed, we can search for classes, methods and properties in the last revision.

Let’s search for the class PgsRecord

First search

The search will return a long list of methods and properties for this class and the class itself, this is just a small sample

Search results

The fields returned are self-explanatory. Comments will be shown for a given item if there is any.

You can search for a specific method or property inside a given class by using :: or . operators (ie: PgsRecordset::insert and PgsRecordset.index are equivalents)

Second search example

In our final example, we will use the tsearch2 operators. Suppose you want to look for setters in PgsRecord or PgsParser classes, we can use the tsearch2 OR operator (|)

Third search example

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s