1 package net.sourceforge.phpdt.core.tests.lucene;
3 import java.io.IOException;
4 import java.util.ArrayList;
7 import org.apache.lucene.document.Document;
8 import org.apache.lucene.index.IndexReader;
9 import org.apache.lucene.index.Term;
10 import org.apache.lucene.index.TermEnum;
11 import org.apache.lucene.search.Hits;
12 import org.apache.lucene.search.IndexSearcher;
13 import org.apache.lucene.search.PrefixQuery;
14 import org.apache.lucene.search.Query;
15 import org.apache.lucene.search.TermQuery;
17 public class PHPSearcher {
18 private IndexSearcher fSearcher;
20 // private StandardAnalyzer analyzer;
22 public PHPSearcher(String indexPath) {
24 fSearcher = new IndexSearcher(indexPath);
25 // analyzer = new StandardAnalyzer();
26 } catch (IOException e) {
31 public Hits getClassInfo(String ident) {
34 Query query = new TermQuery(new Term("c", ident));
35 hits = fSearcher.search(query);
36 int hitCount = hits.length();
38 for (int i = 0; (i < hitCount && i < 10); i++) {
40 for (int j = 0; j < doc.getValues("c").length; j++) {
41 System.out.println(doc.getValues("c")[j]);
44 } catch (IOException e) {
50 public Hits getIncludeInfo(String ident) {
53 // Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
54 Query query = new TermQuery(new Term("i", ident));
55 hits = fSearcher.search(query);
56 int hitCount = hits.length();
58 for (int i = 0; (i < hitCount && i < 10); i++) {
60 for (int j = 0; j < doc.getValues("i").length; j++) {
61 System.out.println(doc.getValues("i")[j]);
64 } catch (IOException e) {
70 public Hits getFunctionInfo(String ident) {
73 // Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
74 Query query = new TermQuery(new Term("f", ident));
75 hits = fSearcher.search(query);
76 int hitCount = hits.length();
78 for (int i = 0; (i < hitCount && i < 10); i++) {
80 for (int j = 0; j < doc.getValues("f").length; j++) {
81 System.out.println(doc.getValues("f")[j]);
84 } catch (IOException e) {
90 public Hits getMethodInfo(String ident) {
93 // Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
94 Query query = new TermQuery(new Term("m", ident));
95 hits = fSearcher.search(query);
96 int hitCount = hits.length();
98 for (int i = 0; (i < hitCount && i < 10); i++) {
100 for (int j = 0; j < doc.getValues("m").length; j++) {
101 System.out.println(doc.getValues("m")[j]);
104 } catch (IOException e) {
110 public Hits getAttributeInfo(String ident) {
113 // Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
114 Query query = new TermQuery(new Term("a", ident));
115 hits = fSearcher.search(query);
116 int hitCount = hits.length();
118 for (int i = 0; (i < hitCount && i < 10); i++) {
120 for (int j = 0; j < doc.getValues("a").length; j++) {
121 System.out.println(doc.getValues("a")[j]);
124 } catch (IOException e) {
130 public List getAttributePrefix(String prefix) {
132 ArrayList list = new ArrayList();
134 Query query = new PrefixQuery(new Term("a", prefix));
135 hits = fSearcher.search(query);
136 int hitCount = hits.length();
137 int len = prefix.length();
139 for (int i = 0; (i < hitCount && i < 10); i++) {
141 for (int j = 0; j < doc.getValues("a").length; j++) {
142 if (prefix.equals(doc.getValues("a")[j].substring(0, len))) {
143 list.add(doc.getValues("a")[j]);
147 } catch (IOException e) {
150 System.out.println(list.toString());
154 public List getPrefixes(String path, String fld, String prefix) {
155 ArrayList list = new ArrayList();
157 IndexReader reader = IndexReader.open(path);
158 Term target = new Term(fld, prefix);
159 int len = prefix.length();
160 TermEnum tenum = reader.terms(target);
164 if (term == null || !term.field().equals(fld) || !prefix.equals(term.text().substring(0, len))) {
167 list.add(term.text());
168 } while (tenum.next());
170 } catch (IOException e) {
173 System.out.println(list.toString());