Lines 52-57
Link Here
|
52 |
import java.io.InputStream; |
52 |
import java.io.InputStream; |
53 |
import java.util.ArrayList; |
53 |
import java.util.ArrayList; |
54 |
import java.util.Arrays; |
54 |
import java.util.Arrays; |
|
|
55 |
import java.util.BitSet; |
55 |
import java.util.Comparator; |
56 |
import java.util.Comparator; |
56 |
import java.util.Iterator; |
57 |
import java.util.Iterator; |
57 |
import java.util.LinkedHashMap; |
58 |
import java.util.LinkedHashMap; |
Lines 67-77
Link Here
|
67 |
import org.apache.lucene.index.Term; |
68 |
import org.apache.lucene.index.Term; |
68 |
import org.apache.lucene.search.BooleanClause; |
69 |
import org.apache.lucene.search.BooleanClause; |
69 |
import org.apache.lucene.search.BooleanQuery; |
70 |
import org.apache.lucene.search.BooleanQuery; |
70 |
import org.apache.lucene.search.Hit; |
71 |
import org.apache.lucene.search.Collector; |
71 |
import org.apache.lucene.search.Hits; |
|
|
72 |
import org.apache.lucene.search.IndexSearcher; |
72 |
import org.apache.lucene.search.IndexSearcher; |
73 |
import org.apache.lucene.search.PrefixQuery; |
73 |
import org.apache.lucene.search.PrefixQuery; |
|
|
74 |
import org.apache.lucene.search.Scorer; |
74 |
import org.apache.lucene.search.TermQuery; |
75 |
import org.apache.lucene.search.TermQuery; |
|
|
76 |
import org.apache.lucene.search.TopDocs; |
75 |
import org.apache.lucene.store.FSDirectory; |
77 |
import org.apache.lucene.store.FSDirectory; |
76 |
import org.openide.filesystems.FileUtil; |
78 |
import org.openide.filesystems.FileUtil; |
77 |
import org.openide.util.Exceptions; |
79 |
import org.openide.util.Exceptions; |
Lines 125-131
Link Here
|
125 |
|
127 |
|
126 |
private static synchronized IndexSearcher getIndexSearcher() throws Exception { |
128 |
private static synchronized IndexSearcher getIndexSearcher() throws Exception { |
127 |
if (indexReader == null) { |
129 |
if (indexReader == null) { |
128 |
FSDirectory dir = FSDirectory.getDirectory(getDefaultIndexLocation()); |
130 |
FSDirectory dir = FSDirectory.open(getDefaultIndexLocation()); |
129 |
indexReader = IndexReader.open(dir); |
131 |
indexReader = IndexReader.open(dir); |
130 |
} |
132 |
} |
131 |
//TODO shall the searcher be stored as field?? |
133 |
//TODO shall the searcher be stored as field?? |
Lines 144-155
Link Here
|
144 |
PrefixQuery pq = new PrefixQuery(new Term(FIELD_ID, grp)); |
146 |
PrefixQuery pq = new PrefixQuery(new Term(FIELD_ID, grp)); |
145 |
bq.add(new BooleanClause(pq, BooleanClause.Occur.SHOULD)); |
147 |
bq.add(new BooleanClause(pq, BooleanClause.Occur.SHOULD)); |
146 |
} |
148 |
} |
147 |
Hits hits = searcher.search(bq); |
149 |
final BitSetCollector searchRes = new BitSetCollector(); |
148 |
Iterator it = hits.iterator(); |
150 |
searcher.search(bq, searchRes); |
|
|
151 |
final BitSet bitSet = searchRes.getMatchedDocs(); |
149 |
TreeSet<String> toRet = new TreeSet<String>(); |
152 |
TreeSet<String> toRet = new TreeSet<String>(); |
150 |
while (it.hasNext()) { |
153 |
for (int docNum = bitSet.nextSetBit(0); docNum >= 0; docNum = bitSet.nextSetBit(docNum+1)) { |
151 |
Hit hit = (Hit) it.next(); |
154 |
Document doc = searcher.getIndexReader().document(docNum); |
152 |
Document doc = hit.getDocument(); |
|
|
153 |
//TODO shall we somehow pick just one version fom a given plugin here? how? |
155 |
//TODO shall we somehow pick just one version fom a given plugin here? how? |
154 |
String prefix = doc.getField(FIELD_PREFIX).stringValue(); |
156 |
String prefix = doc.getField(FIELD_PREFIX).stringValue(); |
155 |
String goals = doc.getField(FIELD_GOALS).stringValue(); |
157 |
String goals = doc.getField(FIELD_GOALS).stringValue(); |
Lines 173-187
Link Here
|
173 |
IndexSearcher searcher = getIndexSearcher(); |
175 |
IndexSearcher searcher = getIndexSearcher(); |
174 |
String id = groupId + "|" + artifactId + "|" + version; //NOI18N |
176 |
String id = groupId + "|" + artifactId + "|" + version; //NOI18N |
175 |
TermQuery tq = new TermQuery(new Term(FIELD_ID, id)); |
177 |
TermQuery tq = new TermQuery(new Term(FIELD_ID, id)); |
176 |
Hits hits = searcher.search(tq); |
178 |
final BitSetCollector searchRes = new BitSetCollector(); |
177 |
if (hits.length() == 0) { |
179 |
searcher.search(tq, searchRes); |
|
|
180 |
final BitSet bitSet = searchRes.getMatchedDocs(); |
181 |
if (bitSet.isEmpty()) { |
178 |
return null; |
182 |
return null; |
179 |
} |
183 |
} |
180 |
Iterator it = hits.iterator(); |
|
|
181 |
TreeSet<String> toRet = new TreeSet<String>(); |
184 |
TreeSet<String> toRet = new TreeSet<String>(); |
182 |
while (it.hasNext()) { //well should be just one anyway.. |
185 |
for (int docNum = bitSet.nextSetBit(0); docNum >= 0; docNum = bitSet.nextSetBit(docNum+1)) { |
183 |
Hit hit = (Hit) it.next(); |
186 |
Document doc = searcher.getIndexReader().document(docNum); |
184 |
Document doc = hit.getDocument(); |
|
|
185 |
String goals = doc.getField(FIELD_GOALS).stringValue(); |
187 |
String goals = doc.getField(FIELD_GOALS).stringValue(); |
186 |
String[] gls = StringUtils.split(goals, " "); //NOI18N |
188 |
String[] gls = StringUtils.split(goals, " "); //NOI18N |
187 |
for (String goal : gls) { |
189 |
for (String goal : gls) { |
Lines 204-218
Link Here
|
204 |
IndexSearcher searcher = getIndexSearcher(); |
206 |
IndexSearcher searcher = getIndexSearcher(); |
205 |
String id = groupId + "|" + artifactId + "|" + version; //NOI18N |
207 |
String id = groupId + "|" + artifactId + "|" + version; //NOI18N |
206 |
TermQuery tq = new TermQuery(new Term(FIELD_ID, id)); |
208 |
TermQuery tq = new TermQuery(new Term(FIELD_ID, id)); |
207 |
Hits hits = searcher.search(tq); |
209 |
final BitSetCollector searchRes = new BitSetCollector(); |
208 |
if (hits.length() == 0) { |
210 |
searcher.search(tq, searchRes); |
|
|
211 |
final BitSet bitSet = searchRes.getMatchedDocs(); |
212 |
if (bitSet.isEmpty()) { |
209 |
return null; |
213 |
return null; |
210 |
} |
214 |
} |
211 |
Iterator it = hits.iterator(); |
|
|
212 |
TreeSet<ParameterDetail> toRet = new TreeSet<ParameterDetail>(new PComparator()); |
215 |
TreeSet<ParameterDetail> toRet = new TreeSet<ParameterDetail>(new PComparator()); |
213 |
while (it.hasNext()) { //well should be just one anyway.. |
216 |
for (int docNum = bitSet.nextSetBit(0); docNum >= 0; docNum = bitSet.nextSetBit(docNum+1)) { |
214 |
Hit hit = (Hit) it.next(); |
217 |
Document doc = searcher.getIndexReader().document(docNum); |
215 |
Document doc = hit.getDocument(); |
|
|
216 |
String goals = doc.getField(FIELD_GOALS).stringValue(); |
218 |
String goals = doc.getField(FIELD_GOALS).stringValue(); |
217 |
String[] gls = StringUtils.split(goals, " "); //NOI18N |
219 |
String[] gls = StringUtils.split(goals, " "); //NOI18N |
218 |
for (String goal : gls) { |
220 |
for (String goal : gls) { |
Lines 263-277
Link Here
|
263 |
assert prefix != null; |
265 |
assert prefix != null; |
264 |
IndexSearcher searcher = getIndexSearcher(); |
266 |
IndexSearcher searcher = getIndexSearcher(); |
265 |
TermQuery tq = new TermQuery(new Term(FIELD_PREFIX, prefix)); |
267 |
TermQuery tq = new TermQuery(new Term(FIELD_PREFIX, prefix)); |
266 |
Hits hits = searcher.search(tq); |
268 |
final BitSetCollector searchRes = new BitSetCollector(); |
267 |
if (hits.length() == 0) { |
269 |
searcher.search(tq, searchRes); |
|
|
270 |
final BitSet bitSet = searchRes.getMatchedDocs(); |
271 |
if (bitSet.isEmpty()) { |
268 |
return null; |
272 |
return null; |
269 |
} |
273 |
} |
270 |
Iterator it = hits.iterator(); |
|
|
271 |
TreeSet<String> toRet = new TreeSet<String>(); |
274 |
TreeSet<String> toRet = new TreeSet<String>(); |
272 |
while (it.hasNext()) { //well should be just one anyway.. |
275 |
for (int docNum = bitSet.nextSetBit(0); docNum >= 0; docNum = bitSet.nextSetBit(docNum+1)) { |
273 |
Hit hit = (Hit) it.next(); |
276 |
Document doc = searcher.getIndexReader().document(docNum); |
274 |
Document doc = hit.getDocument(); |
|
|
275 |
String id = doc.getField(FIELD_ID).stringValue(); |
277 |
String id = doc.getField(FIELD_ID).stringValue(); |
276 |
toRet.add(id); |
278 |
toRet.add(id); |
277 |
} |
279 |
} |
Lines 304-318
Link Here
|
304 |
} |
306 |
} |
305 |
bq.add(bq2, BooleanClause.Occur.SHOULD); //why doesn't MUST work? |
307 |
bq.add(bq2, BooleanClause.Occur.SHOULD); //why doesn't MUST work? |
306 |
|
308 |
|
307 |
Hits hits = searcher.search(bq); |
309 |
final BitSetCollector searchRes = new BitSetCollector(); |
308 |
if (hits.length() == 0) { |
310 |
searcher.search(bq, searchRes); |
|
|
311 |
final BitSet bitSet = searchRes.getMatchedDocs(); |
312 |
if (bitSet.isEmpty()) { |
309 |
return null; |
313 |
return null; |
310 |
} |
314 |
} |
311 |
Iterator it = hits.iterator(); |
|
|
312 |
LinkedHashMap<String, List<String>> toRet = new LinkedHashMap<String, List<String>>(); |
315 |
LinkedHashMap<String, List<String>> toRet = new LinkedHashMap<String, List<String>>(); |
313 |
while (it.hasNext()) { //well should be just one anyway.. |
316 |
for (int docNum = bitSet.nextSetBit(0); docNum >= 0; docNum = bitSet.nextSetBit(docNum+1)) { |
314 |
Hit hit = (Hit) it.next(); |
317 |
Document doc = searcher.getIndexReader().document(docNum); |
315 |
Document doc = hit.getDocument(); |
|
|
316 |
Field prefixed = doc.getField(PREFIX_FIELD_CYCLE + packaging); |
318 |
Field prefixed = doc.getField(PREFIX_FIELD_CYCLE + packaging); |
317 |
if (prefixed != null) { |
319 |
if (prefixed != null) { |
318 |
String mapping = prefixed.stringValue(); |
320 |
String mapping = prefixed.stringValue(); |
Lines 505-509
Link Here
|
505 |
} |
507 |
} |
506 |
|
508 |
|
507 |
} |
509 |
} |
|
|
510 |
|
511 |
|
512 |
private static final class BitSetCollector extends Collector { |
508 |
|
513 |
|
|
|
514 |
private int docBase; |
515 |
private final BitSet bits = new BitSet(); |
516 |
|
517 |
public BitSet getMatchedDocs() { |
518 |
return this.bits; |
519 |
} |
520 |
|
521 |
|
522 |
@Override |
523 |
public void setScorer(Scorer scorer) { |
524 |
//Todo: ignoring scorer for now, if ordering accoring to score needed |
525 |
// this will need to be implemented |
526 |
} |
527 |
|
528 |
// accept docs out of order (for a BitSet it doesn't matter) |
529 |
@Override |
530 |
public boolean acceptsDocsOutOfOrder() { |
531 |
return true; |
532 |
} |
533 |
|
534 |
@Override |
535 |
public void collect(int doc) { |
536 |
bits.set(doc + docBase); |
537 |
} |
538 |
|
539 |
@Override |
540 |
public void setNextReader(IndexReader reader, int docBase) { |
541 |
this.docBase = docBase; |
542 |
} |
543 |
|
544 |
} |
545 |
|
509 |
} |
546 |
} |