Tests for indexing a PHP AST with Lucene search engine;
authoraxelcl <axelcl>
Fri, 2 Sep 2005 19:31:03 +0000 (19:31 +0000)
committeraxelcl <axelcl>
Fri, 2 Sep 2005 19:31:03 +0000 (19:31 +0000)
Needs more ideas how to store the meta-information :-)

net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/LuceneTest.java
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPSearcher.java
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPWriter.java

index 2e8e653..fd388d3 100644 (file)
@@ -19,20 +19,6 @@ import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem;
 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
-
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
 
 public class LuceneTest extends AbstractCompilerTest {
        public LuceneTest(String name) {
@@ -101,9 +87,11 @@ public class LuceneTest extends AbstractCompilerTest {
 
                PHPSearcher indexSearcher = new PHPSearcher(indexPath);
 
+               indexSearcher.getIncludeInfo("hello_world");
                indexSearcher.getClassInfo("Overlib");
                indexSearcher.getAttributeInfo("$ol_closetext");
                indexSearcher.getMethodInfo("set");
+
        }
 
        /**
index 035c752..05ce6bb 100644 (file)
@@ -44,6 +44,26 @@ public class PHPSearcher {
                return hits;
        }
 
+       public Hits getIncludeInfo(String ident) {
+               Hits hits = null;
+               try {
+//                     Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
+                       Query query = new TermQuery(new Term("i", ident));
+                       hits = fSearcher.search(query);
+                       int hitCount = hits.length();
+                       Document doc;
+                       for (int i = 0; (i < hitCount && i < 10); i++) {
+                               doc = hits.doc(i);
+                               for (int j = 0; j < doc.getValues("i").length; j++) {
+                                       System.out.println(doc.getValues("i")[j]);
+                               }
+                       }
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return hits;
+       }
+
        public Hits getFunctionInfo(String ident) {
                Hits hits = null;
                try {
index bdd54d9..d370d3b 100644 (file)
@@ -4,6 +4,7 @@ import java.io.IOException;
 
 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
+import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
 
@@ -28,11 +29,21 @@ public PHPWriter(String indexPath, boolean create) throws IOException {
                                doc.add(Field.Keyword("filename", file.getName()));
                                doc.add(Field.Keyword("path", file.getProjectRelativePath().toString()));
                        }
+                       if (computedUnit.imports != null) {
+                               ImportReference imp;
+                               for (int i=0; i<computedUnit.imports.length; i++) {
+                                       // add the php include
+                                       imp = computedUnit.imports[i];
+                                       String incl = new String(imp.includeSource);
+                                       doc.add(Field.Keyword("i", incl));
+                                       doc.add(Field.UnIndexed(incl, "include meta-info"));
+                               }
+                       }
                        if (computedUnit.types != null) {
                                Object obj;
                                MethodDeclaration m;
                                TypeDeclaration c;
-                               for (int i = computedUnit.types.size(); --i >= 0;) {
+                               for (int i=0; i<computedUnit.types.size(); i++) {
                                        obj = computedUnit.types.get(i);
                                        if (obj instanceof MethodDeclaration) {
                                                m = (MethodDeclaration) obj;