package net.sourceforge.phpdt.core.tests.lucene;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.index.TermEnum;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
public class PHPSearcher {
private IndexSearcher fSearcher;
- private StandardAnalyzer analyzer;
+
+ // private StandardAnalyzer analyzer;
public PHPSearcher(String indexPath) {
try {
fSearcher = new IndexSearcher(indexPath);
- analyzer = new StandardAnalyzer();
+ // analyzer = new StandardAnalyzer();
} catch (IOException e) {
e.printStackTrace();
}
public Hits getClassInfo(String ident) {
Hits hits = null;
try {
- Query query = new TermQuery(new Term("c", ident));
+ Query query = new TermQuery(new Term("c", ident));
hits = fSearcher.search(query);
int hitCount = hits.length();
Document doc;
public Hits getIncludeInfo(String ident) {
Hits hits = null;
try {
-// Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
+ // Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
Query query = new TermQuery(new Term("i", ident));
hits = fSearcher.search(query);
int hitCount = hits.length();
public Hits getFunctionInfo(String ident) {
Hits hits = null;
try {
-// Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
+ // Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
Query query = new TermQuery(new Term("f", ident));
hits = fSearcher.search(query);
int hitCount = hits.length();
public Hits getMethodInfo(String ident) {
Hits hits = null;
try {
-// Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
+ // Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
Query query = new TermQuery(new Term("m", ident));
hits = fSearcher.search(query);
int hitCount = hits.length();
}
return hits;
}
+
public Hits getAttributeInfo(String ident) {
Hits hits = null;
try {
-// Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
+ // Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
Query query = new TermQuery(new Term("a", ident));
hits = fSearcher.search(query);
int hitCount = hits.length();
}
return hits;
}
+
+ public List getAttributePrefix(String prefix) {
+ Hits hits = null;
+ ArrayList list = new ArrayList();
+ try {
+ Query query = new PrefixQuery(new Term("a", prefix));
+ hits = fSearcher.search(query);
+ int hitCount = hits.length();
+ int len = prefix.length();
+ Document doc;
+ for (int i = 0; (i < hitCount && i < 10); i++) {
+ doc = hits.doc(i);
+ for (int j = 0; j < doc.getValues("a").length; j++) {
+ if (prefix.equals(doc.getValues("a")[j].substring(0, len))) {
+ list.add(doc.getValues("a")[j]);
+ }
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ System.out.println(list.toString());
+ return list;
+ }
+
+ public List getPrefixes(String path, String fld, String prefix) {
+ ArrayList list = new ArrayList();
+ try {
+ IndexReader reader = IndexReader.open(path);
+ Term target = new Term(fld, prefix);
+ int len = prefix.length();
+ TermEnum tenum = reader.terms(target);
+ Term term;
+ do {
+ term = tenum.term();
+ if (term == null || !term.field().equals(fld) || !prefix.equals(term.text().substring(0, len))) {
+ break;
+ }
+ list.add(term.text());
+ } while (tenum.next());
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ System.out.println(list.toString());
+ return list;
+ }
}