From e8eec0863699195fe6336d66428055a39bac0c10 Mon Sep 17 00:00:00 2001 From: axelcl Date: Fri, 2 Sep 2005 19:31:03 +0000 Subject: [PATCH] Tests for indexing a PHP AST with Lucene search engine; Needs more ideas how to store the meta-information :-) --- .../phpdt/core/tests/lucene/LuceneTest.java | 16 ++-------------- .../phpdt/core/tests/lucene/PHPSearcher.java | 20 ++++++++++++++++++++ .../phpdt/core/tests/lucene/PHPWriter.java | 13 ++++++++++++- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/LuceneTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/LuceneTest.java index 2e8e653..fd388d3 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/LuceneTest.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/LuceneTest.java @@ -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"); + } /** diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPSearcher.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPSearcher.java index 035c752..05ce6bb 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPSearcher.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPSearcher.java @@ -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 { diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPWriter.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPWriter.java index bdd54d9..d370d3b 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPWriter.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/lucene/PHPWriter.java @@ -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= 0;) { + for (int i=0; i