Interoperable interactive geometry for Europe
I forgot my login data
Register


Report a bug


Fan club

Quick Intro Videos
click to start movie
Create A Simple
GeoGebra Resource (25Mb)
click to start movie
Filing a review
click to start movie
Find a Resource

SPONSORS
This platform is brought to you by the intergeo project, funded under the eContent Plus programme of the European commission and by partners

import com.xpn.xwiki.XWiki import com.xpn.xwiki.XWikiContext import org.apache.lucene.queryParser.QueryParser import org.apache.lucene.search.Query import org.apache.lucene.search.BooleanQuery import org.apache.lucene.search.BooleanClause import org.apache.lucene.search.TermQuery import org.apache.lucene.search.Hits import org.apache.lucene.index.Term import com.xpn.xwiki.plugin.lucene.LucenePluginApi import org.curriki.xwiki.plugin.lucene.CurrikiAnalyzer import org.apache.commons.logging.LogFactory import org.apache.commons.logging.Log import javax.servlet.http.HttpServletRequest import org.apache.lucene.analysis.Analyzer import org.curriki.xwiki.plugin.curriki.CurrikiPluginApi import com.xpn.xwiki.web.XWikiMessageTool import com.xpn.xwiki.plugin.lucene.I2GLuceneProfile

public class GroovyCursor implements Iterator {

static Log LOG = LogFactory.getLog("pages.AdvancedSearch.GroovyCursor");

public GroovyCursor() {}

public void init(XWiki xwiki, XWikiContext context, LucenePluginApi plugin, XWikiMessageTool msg) { this.plugin = plugin this.xwiki = xwiki; this.context = context; this.msg = msg; this.analyzer = CurrikiAnalyzer.getInstance(context.getLanguage(),context, I2GLuceneProfile.getInstance()); }

private XWiki xwiki; private XWikiContext context; private LucenePluginApi plugin; private XWikiMessageTool msg; private Analyzer analyzer;

private String sortFields = "relevance";

private ArrayList warnMessages = new ArrayList(); private QueryParser parser; private Hits hits; private int pos = 0; private int start = 0, max = Integer.MAX_VALUE; private int maxPageLength = 20; private static must = BooleanClause.Occur.MUST, mustNot = BooleanClause.Occur.MUST_NOT, should= BooleanClause.Occur.SHOULD;

public Set getSetFromParams(HttpServletRequest request,String name) { if(name==null || request==null) return Collections.EMPTY_SET; String] values = request.getParameterValues(name); if(values==null.query; if(tq instanceof TermQuery && fieldName==tq.term.field()) { String fragId = tq.term.text(); def newTermQuery = new TermQuery(new Term(ancestorFieldName,fragId)); newTermQuery.setBoost(tq.boost); q2.add(newTermQuery, q.clausesi?.occur); if(fragId.endsWith("_r") && fragId.length()>2) { newTermQuery = new TermQuery(new Term(ancestorFieldName,fragId.substring(0,fragId.length()-2))); newTermQuery.setBoost(tq.boost); q2.add(newTermQuery, q.clausesi?.occur); } } } BooleanQuery ret = new BooleanQuery(); ret.add(q,should); ret.add(q2,should); bq.add(ret,must); return true; } else { bq.add(q,must); return true; } }

private boolean addAuthorQuery(BooleanQuery bq, String fieldName, String authorQ, Analyzer analyzer) { if(authorQ==null || "".equals(authorQ.trim())) return false; BooleanQuery q = getQueryForAuthorsLike(authorQ, fieldName, analyzer); if(q==null || q.getClauses().length==0) { warnMessages.add(msg.get("search.form.no-author-found")); return false } bq.add(q, must); return true; }

private BooleanQuery getQueryForAuthorsLike(String like, String fieldname, Analyzer analyzer) { BooleanQuery bq = new BooleanQuery(); Query q = new QueryParser("XWiki.XWikiUsers.first_name",analyzer).parse(like); bq.add(q, should); q= new QueryParser("XWiki.XWikiUsers.first_name.stemmed",analyzer).parse(like); q.setBoost(0.5f); bq.add(q, should); q=new QueryParser("XWiki.XWikiUsers.last_name",analyzer).parse(like); bq.add(q, should); q=new QueryParser("XWiki.XWikiUsers.last_name.stemmed",analyzer).parse(like); q.setBoost(0.5f); bq.add(q, should); bq.add(new QueryParser("XWiki.XWikiUsers.email",analyzer).parse(like), should); bq.add(new QueryParser("XWiki.XWikiUsers.affiliation",analyzer).parse(like), should); q=new QueryParser("XWiki.XWikiUsers.affiliation.stemmed",analyzer).parse(like); q.setBoost(0.5f); bq.add(q, should); Query ftQ = new QueryParser("ft",analyzer).parse(like); ftQ.setBoost(0.5f); bq.add(ftQ,should); BooleanQuery bq2 = new BooleanQuery(); bq2.add(bq,must); bq2.add(new TermQuery(new Term("object","XWiki.XWikiUsers")),must); LOG.warn("author query " + bq2); BooleanQuery r = new BooleanQuery(); Hits h = plugin.getLuceneHits(bq2,null); LOG.warn("obtained " + h.length() + " hits."); if(h.length()==0) return null; int max = Math.min(h.length(),500); for(int i in 0..(max-1)) { String t = h.doc(i).get("fullname"); r.add(new TermQuery(new Term(fieldname,t)),should); } if(r.getClauses().length==0) return null; else return r; }

// ============================================================================================ public boolean executeQuery(Query q, String start, String max) { if(q==null) return false; LOG.warn("Launching query " + q); this.hits = plugin.getLuceneHits(q,sortFields.split(",")); LOG.warn("Hits " + this.hits + " of size " + hits.length()); if(start!=null && start.length()>0) pos = Integer.parseInt(start); if(max!=null && max.length()>0) this.max = Integer.parseInt(max); else this.max = pos+maxPageLength; if(pos<0 || pos>=hits.length()) pos = 0; this.start = pos; this.max = Math.min(this.max, hits.length()) return hits.length()>0; }

public String cleanUp(String s) { if(s==null) return ""; return s.replaceAll("<^+>","") }

public Object next() { Object r=null; if(pos>=0 && pos public int getPos() { return pos;}

public int getStart() { return start;} public int getMax() { return max; }

public int getNumHits() { return hits.length(); }

public boolean hasNext() { return hits!=null && pos public float getScore() { return hits.score(pos); }

public boolean hasNextPage() { return max < hits.length(); }

public boolean hasPreviousPage() { return start>0; }

public int getNextPageStart() { return start+maxPageLength; } public int getPreviousPageStart() { return start- maxPageLength; }

public String getURLtoHereWithoutStart(HttpServletRequest request) { String queryString = request.getQueryString(); if(queryString==null) queryString = ""; queryString = queryString.replaceAll("&start=0-9?+",""); return request.getContextPath() + "/" + request.getServletPath() + request.getPathInfo()+ "?" + queryString; }

public void remove() { throw new UnsupportedOperationException(); }

private String lang3toLang2(String lang3) { return msg.get("languages3_2." + lang3); }

private String remapFileTypes(String type) { if(type==null || type.length()==0) return null; if("cabri".equals(type)) { return "cabri2plusfile cabri2plusFile cabri2File cabri2file fig"; } else if("g2w".equals(type)) return "g2w"; else if ("wiris".equals(type)) return "wirishtml" else if("txt".equals(type)) return "txt tracenpocheFile" else return type; }

public ArrayList getWarnMessages() { return warnMessages; }

private void trash() { def doc = xwiki.getDocument("XWiki.SouryLavergne",context); println("doc is " + doc); println(); def ddoc = doc.getDocument(); println("ddoc is " + ddoc + " of class " + ddoc.getClass()); println();

for (className in ddoc.getxWikiObjects().keySet()) { for (obj in ddoc.getObjects(className)) { println "" println ("


") println " obj (" + className + "): " + obj;

StringBuffer contentText = new StringBuffer(); for(baseProperty in obj.getProperties()) { if (baseProperty.getValue() != null) { contentText.append(baseProperty.getValue().toString()); contentText.append(" "); } } println "text: " + contentText;

} }

}

}