What's SearchProcessor

SearchProcessor uses ProgressParser to parse source files and create an index with all the statements found. Then, you can search files using Google-like queries.

Sample Code


The box below shows the Java code used to create an index and search statements:

SearchProcessor sample code
import net.cordova.justus.smartgrep.*;
import java.io.*;

public class MyTest {
    public static void main(String args[]) {
        File indexDir  = new File(args[0]); // Path to where the index will be created 
        File sourceDir = new File(args[1]); // Path to a folder with source files

        // Path to source files
        SearchPathInfo info = new SearchPathInfo();
        info.setPath(sourceDir);
        info.setExtensions(new String[] {"p", "w", "i", "cls"});
        info.setRecursive(true);
       
        // Creates database and add source codes
        SearchProcessor p = new SearchProcessor(sourceDir);
        p.prepareProcessing();
        p.addPath(info);
        p.finishProcessing();
    
        // Search FOR and FIND statements without NO-LOCK or EXCLUSIVE-LOCK
        String queryString = "+(FOR OR FIND) NOT \"NO-LOCK\" NOT \"EXCLUSIVE-LOCK\"";
        
        HashMap<File, Collection<GenericProgressStatement>> result = p.search(queryString, new String[] {"Find", "For"});
        for(File f : result.keySet()) {
            System.out.println(f.getAbsolutePath());
            System.out.println("==================================");
            for(GenericProgressStatement stmt : result.get(f)) {
                System.out.println(stmt);
            }
            System.out.println("");
        }
    }
}