Created
January 2, 2020 16:52
-
-
Save ianibo/b75bc3c73f872c2fef25a1aeaafe9620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.grape.Grape | |
Grape.addResolver(name:'mvnRepository', root:'http://central.maven.org/maven2/') | |
Grape.addResolver(name:'kint', root:'http://nexus.k-int.com/content/repositories/releases') | |
Grape.grab(group:'org.apache.lucene', module:'lucene-queryparser', version:'8.4.0') | |
import org.apache.lucene.search.Query; | |
import org.apache.lucene.queryparser.classic.QueryParser; | |
private void interpret(Query q, int depth) { | |
println("${q} - ${q.class.name}"); | |
switch ( q.class ) { | |
case org.apache.lucene.search.TermQuery: | |
println("TermQuery"); | |
break; | |
case org.apache.lucene.search.BooleanQuery: | |
println("Boolean ${q}"); | |
q.clauses.each { clause -> | |
interpret(clause.getQuery(), depth+1); | |
} | |
break; | |
default: | |
println("Unhandled: ${q.class.name}"); | |
break; | |
} | |
} | |
def queries = [ | |
'title:fred', | |
'title:"fred phrase search"', | |
'title:fred author:freda', | |
'title:fred ( author:freda AND author:jane )' | |
] | |
org.apache.lucene.analysis.standard.StandardAnalyzer analyzer = new org.apache.lucene.analysis.standard.StandardAnalyzer(); | |
queries.each { qrystr -> | |
println("Parse ${qrystr}"); | |
Query q = new QueryParser("title", analyzer).parse(qrystr); | |
println("Parsed into ${q}"); | |
interpret(q,0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment