035c752ee03858dabfe390468dfcd74c6711481f
[phpeclipse.git] / net.sourceforge.phpeclipse.tests / src / net / sourceforge / phpdt / core / tests / lucene / PHPSearcher.java
1 package net.sourceforge.phpdt.core.tests.lucene;
2
3 import java.io.IOException;
4
5 import org.apache.lucene.analysis.standard.StandardAnalyzer;
6 import org.apache.lucene.document.Document;
7 import org.apache.lucene.index.Term;
8 import org.apache.lucene.queryParser.ParseException;
9 import org.apache.lucene.queryParser.QueryParser;
10 import org.apache.lucene.search.Hits;
11 import org.apache.lucene.search.IndexSearcher;
12 import org.apache.lucene.search.Query;
13 import org.apache.lucene.search.TermQuery;
14
15 public class PHPSearcher {
16         private IndexSearcher fSearcher;
17         private StandardAnalyzer analyzer;
18
19         public PHPSearcher(String indexPath) {
20                 try {
21                         fSearcher = new IndexSearcher(indexPath);
22                         analyzer = new StandardAnalyzer();
23                 } catch (IOException e) {
24                         e.printStackTrace();
25                 }
26         }
27
28         public Hits getClassInfo(String ident) {
29                 Hits hits = null;
30                 try {
31       Query query = new TermQuery(new Term("c", ident));
32                         hits = fSearcher.search(query);
33                         int hitCount = hits.length();
34                         Document doc;
35                         for (int i = 0; (i < hitCount && i < 10); i++) {
36                                 doc = hits.doc(i);
37                                 for (int j = 0; j < doc.getValues("c").length; j++) {
38                                         System.out.println(doc.getValues("c")[j]);
39                                 }
40                         }
41                 } catch (IOException e) {
42                         e.printStackTrace();
43                 }
44                 return hits;
45         }
46
47         public Hits getFunctionInfo(String ident) {
48                 Hits hits = null;
49                 try {
50 //                      Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
51                         Query query = new TermQuery(new Term("f", ident));
52                         hits = fSearcher.search(query);
53                         int hitCount = hits.length();
54                         Document doc;
55                         for (int i = 0; (i < hitCount && i < 10); i++) {
56                                 doc = hits.doc(i);
57                                 for (int j = 0; j < doc.getValues("f").length; j++) {
58                                         System.out.println(doc.getValues("f")[j]);
59                                 }
60                         }
61                 } catch (IOException e) {
62                         e.printStackTrace();
63                 }
64                 return hits;
65         }
66
67         public Hits getMethodInfo(String ident) {
68                 Hits hits = null;
69                 try {
70 //                      Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
71                         Query query = new TermQuery(new Term("m", ident));
72                         hits = fSearcher.search(query);
73                         int hitCount = hits.length();
74                         Document doc;
75                         for (int i = 0; (i < hitCount && i < 10); i++) {
76                                 doc = hits.doc(i);
77                                 for (int j = 0; j < doc.getValues("m").length; j++) {
78                                         System.out.println(doc.getValues("m")[j]);
79                                 }
80                         }
81                 } catch (IOException e) {
82                         e.printStackTrace();
83                 }
84                 return hits;
85         }
86         public Hits getAttributeInfo(String ident) {
87                 Hits hits = null;
88                 try {
89 //                      Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
90                         Query query = new TermQuery(new Term("a", ident));
91                         hits = fSearcher.search(query);
92                         int hitCount = hits.length();
93                         Document doc;
94                         for (int i = 0; (i < hitCount && i < 10); i++) {
95                                 doc = hits.doc(i);
96                                 for (int j = 0; j < doc.getValues("a").length; j++) {
97                                         System.out.println(doc.getValues("a")[j]);
98                                 }
99                         }
100                 } catch (IOException e) {
101                         e.printStackTrace();
102                 }
103                 return hits;
104         }
105 }