Skip to content

Commit

Permalink
Removing the auto-generated syntax classes from git tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla committed Apr 12, 2013
1 parent 43efed5 commit 7305b8c
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 26,444 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ contrib/invenio/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/FixIn
contrib/invenio/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/FixInvenioParser.java
contrib/invenio/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/InvenioLexer.java
contrib/invenio/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/InvenioParser.java
contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/ADS.tokens
contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/ADSLexer.java
contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/ADSParser.java
contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/parser/ADSSyntaxParser.java

# a symbolic links to other grammars in contrib/invenio
contrib/antlrqueryparser/grammars/*Invenio.*
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.apache.lucene.queryparser.flexible.aqp.parser;

import org.apache.commons.lang.NotImplementedException;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import org.apache.solr.search.FunctionQParser;

public class AqpSubqueryParser {

private boolean canBeAnalyzed = false;

public boolean canBeAnalyzed() {
return canBeAnalyzed ;
}

public Query parse(FunctionQParser fp) throws ParseException {
throw new NotImplementedException();
}

public AqpSubqueryParser configure(boolean canBeAnalyzed) {
this.canBeAnalyzed=canBeAnalyzed;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.apache.lucene.queryparser.flexible.aqp.parser;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.solr.search.QParser;


public class AqpSubqueryParserFull extends AqpSubqueryParser {

private QParser parser = null;
private Class<?>[] qtypes = null;
private ReentrantLock parsingLock = new ReentrantLock();

public QParser getParser() {
return parser;
}
public Class[] getQtypes() {
return qtypes;
}

public Query simplify(Query query) {
if (query instanceof BooleanQuery) {
List<BooleanClause>clauses = ((BooleanQuery) query).clauses();
if (clauses.size()==1 && ((BooleanQuery) query).getBoost() == 1.0) {
Query q = clauses.get(0).getQuery();
if (q.toString().toString().equals("")) return null;
if (q instanceof DisjunctionMaxQuery && ((DisjunctionMaxQuery) q).getDisjuncts().size()==1) {
return ((DisjunctionMaxQuery) q).getDisjuncts().get(0);
}
return q;
}
}
return query;
}

public Query reParse(Query query, QParser qp, Class<?>...types) throws ParseException {
parsingLock.lock();
try {
parser = qp;
qtypes = types;
swimDeep(query);
return query;
}
finally {
parser = null;
qtypes = null;
parsingLock.unlock();
}
}

protected boolean isWanted(Query query) {
for (Class<?>type : qtypes) {
if (type.isInstance(query)) {
return true;
}
}
return false;
}

protected Query swimDeep(TermQuery query) throws ParseException {
if (parser != null && qtypes != null && isWanted(query)) {
parser.setString(query.toString());
Query newQ = parser.parse();
newQ.setBoost(query.getBoost());
return newQ;
}
return query;
}

protected Query swimDeep(DisjunctionMaxQuery query) throws ParseException {
ArrayList<Query> parts = query.getDisjuncts();
for (int i=0;i<parts.size();i++) {
Query oldQ = parts.get(i);
parts.set(i, swimDeep(oldQ));
}
return query;

}

protected Query swimDeep(BooleanQuery query) throws ParseException {
List<BooleanClause>clauses = query.clauses();
for (int i=0;i<clauses.size();i++) {
BooleanClause c = clauses.get(i);
Query qq = swimDeep(c.getQuery());
c.setQuery(qq);
}
return query;
}

protected Query swimDeep(Query query) throws ParseException {
if (query instanceof BooleanQuery) {
return swimDeep((BooleanQuery) query);
}
else if (query instanceof DisjunctionMaxQuery) {
return swimDeep((DisjunctionMaxQuery) query);
}
else if (query instanceof TermQuery) {
return swimDeep((TermQuery) query);
}
return query;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void test() throws Exception {

assert sw.toString().contains("\"bibcode\":[\"xxxxxxxxxxxxx\"],");
assert sw.toString().contains("\"title\":[\"head\"]");
//System.out.println(sw.toString());
System.out.println(sw.toString());



Expand Down Expand Up @@ -152,7 +152,7 @@ public void test() throws Exception {
responseWriter.write(sw,req,rsp);
req.close();

//System.out.println(sw.toString());
System.out.println(sw.toString());
assert sw.toString().contains("angels\t3\t2");


Expand Down
Loading

0 comments on commit 7305b8c

Please sign in to comment.