BooleanQuery q = new BooleanQuery();
q.add(q1, Occur.MUST);
q.add(q2, Occur.MUST);
if (s != null && s.trim().length() > 0) {
SimpleAnalyzer analyzer = new SimpleAnalyzer(Version.LUCENE_36);
if (s.indexOf(":") == -1) {
// the query we need:
// "projectId":projectId AND "type":type AND ("prefix":s* OR
// "localPart":s* OR "label":s* OR "description":s*)
BooleanQuery q3 = new BooleanQuery();
q3.add(new WildcardQuery(new Term("prefix", s + "*")),
Occur.SHOULD);
TokenStream stream = analyzer.tokenStream("localPart",
new StringReader(s));
// get the TermAttribute from the TokenStream
CharTermAttribute termAtt = (CharTermAttribute) stream
.addAttribute(CharTermAttribute.class);
stream.reset();
while (stream.incrementToken()) {
String tmp = termAtt.toString() + "*";
q3.add(new WildcardQuery(new Term("localPart", tmp)),
Occur.SHOULD);
}
stream.close();
stream.end();
stream = analyzer.tokenStream("description",
new StringReader(s));
// get the TermAttribute from the TokenStream
termAtt = (CharTermAttribute) stream
.addAttribute(CharTermAttribute.class);
stream.reset();
while (stream.incrementToken()) {
String tmp = termAtt.toString() + "*";
q3.add(new WildcardQuery(new Term("description", tmp)),
Occur.SHOULD);
}
stream.close();
stream.end();
stream = analyzer.tokenStream("label", new StringReader(s));
// get the TermAttribute from the TokenStream
termAtt = (CharTermAttribute) stream
.addAttribute(CharTermAttribute.class);
stream.reset();
while (stream.incrementToken()) {
String tmp = termAtt.toString() + "*";
q3.add(new WildcardQuery(new Term("label", tmp)),
Occur.SHOULD);
}
stream.close();
stream.end();
q.add(q3, Occur.MUST);
return q;
} else {
// the query we need:
// "projectId":projectId AND "type":type AND ("prefix":p1 AND
// "localPart":s*)
String p1 = s.substring(0, s.indexOf(":"));
String p2 = s.substring(s.indexOf(":") + 1);
BooleanQuery q3 = new BooleanQuery();
q3.add(new TermQuery(new Term("prefix", p1)), Occur.SHOULD);
BooleanQuery q4 = new BooleanQuery();
TokenStream stream = analyzer.tokenStream("localPart",
new StringReader(p2));
// get the TermAttribute from the TokenStream
CharTermAttribute termAtt = (CharTermAttribute) stream
.addAttribute(CharTermAttribute.class);