1 package net.sourceforge.phpdt.core.tests.lucene;
3 import java.io.IOException;
5 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
6 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
7 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
8 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
10 import org.apache.lucene.analysis.standard.StandardAnalyzer;
11 import org.apache.lucene.document.Document;
12 import org.apache.lucene.document.Field;
13 import org.apache.lucene.index.IndexWriter;
14 import org.eclipse.core.resources.IFile;
16 public class PHPWriter {
17 private IndexWriter fWriter = null;
19 public PHPWriter(String indexPath, boolean create) throws IOException {
20 // Make a lucene writer and create new Lucene index with arg3 = true
21 fWriter = new IndexWriter(indexPath, new StandardAnalyzer(), create);
24 public boolean addDocument(CompilationUnitDeclaration computedUnit, IFile file) {
25 Document doc = new Document();
28 doc.add(Field.Keyword("filename", file.getName()));
29 doc.add(Field.Keyword("path", file.getProjectRelativePath().toString()));
31 if (computedUnit.types != null) {
35 for (int i = computedUnit.types.size(); --i >= 0;) {
36 obj = computedUnit.types.get(i);
37 if (obj instanceof MethodDeclaration) {
38 m = (MethodDeclaration) obj;
39 // add the php function name
40 String function = new String(m.selector);
41 doc.add(Field.Keyword("f", function));
42 doc.add(Field.UnIndexed(function, "class meta-info"));
43 } else if (obj instanceof TypeDeclaration) {
44 c = (TypeDeclaration) obj;
46 String clazz = new String(c.name);
47 // new Field("c", clazz, true, false, true, false);
48 doc.add(Field.Keyword("c", clazz));
49 doc.add(Field.UnIndexed(clazz, "class meta-info"));
51 for (int j = 0; j < c.fields.length; j++) {
52 String attribute = new String(c.fields[j].name);
53 doc.add(Field.Keyword("a", attribute));
54 doc.add(Field.UnIndexed(attribute, "field meta-data"));
57 if (c.methods!=null) {
58 for (int j = 0; j < c.methods.length; j++) {
59 String function = new String(c.methods[j].selector);
60 doc.add(Field.Keyword("m", function));
61 doc.add(Field.UnIndexed(function, "method meta-data"));
67 fWriter.addDocument(doc);
69 } catch (IOException e) {
80 } catch (IOException e) {