use of lucee.runtime.search.SearchCollection in project Lucee by lucee.
the class Search method doStartTag.
@Override
public int doStartTag() throws PageException {
// SerialNumber sn = pageContext.getConfig().getSerialNumber();
// if(sn.getVersion()==SerialNumber.VERSION_COMMUNITY)
// throw new SecurityException("no access to this functionality with the "+sn.getStringVersion()+" version of Lucee");
final String v = "VARCHAR", d = "DOUBLE";
String[] cols = new String[] { "title", "url", "summary", "score", "recordssearched", "key", "custom1", "custom2", "custom3", "custom4", "categoryTree", "category", "context", "size", "rank", "author", "type", "collection" };
// TODO support context
String[] types = new String[] { v, v, v, d, d, v, v, v, v, v, v, v, v, d, d, v, v, v };
SearchData data = pageContext.getConfig().getSearchEngine(pageContext).createSearchData(suggestions);
// this is already here to make sure the classloader load this sinstance
SuggestionItem item = null;
lucee.runtime.type.Query qry = new QueryImpl(cols, types, 0, "query");
SearchCollection collection;
long time = System.currentTimeMillis();
AddionalAttrs.setAddionalAttrs(contextBytes, contextPassages, contextHighlightBegin, contextHighlightEnd);
try {
for (int i = 0; i < collections.length; i++) {
collection = collections[i];
startrow = collection.search(data, qry, criteria, collection.getLanguage(), type, startrow, maxrows, categoryTree, category);
if (maxrows >= 0 && qry.getRecordcount() >= maxrows)
break;
}
pageContext.setVariable(name, qry);
} catch (SearchException se) {
throw Caster.toPageException(se);
} finally {
AddionalAttrs.removeAddionalAttrs();
}
time = System.currentTimeMillis() - time;
Double recSearched = new Double(data.getRecordsSearched());
int len = qry.getRecordcount();
for (int i = 1; i <= len; i++) {
qry.setAt("recordssearched", i, recSearched);
}
// status
if (status != null) {
Struct sct = new StructImpl();
pageContext.setVariable(status, sct);
sct.set(FOUND, new Double(qry.getRecordcount()));
sct.set(SEARCHED, recSearched);
sct.set(KeyConstants._time, new Double(time));
// TODO impl this values
Map s = data.getSuggestion();
if (s.size() > 0) {
String key;
Iterator it = s.keySet().iterator();
Struct keywords = new StructImpl();
Struct keywordScore = new StructImpl();
sct.set(KEYWORDS, keywords);
sct.set(KEYWORD_SCORE, keywordScore);
Object obj;
while (it.hasNext()) {
key = (String) it.next();
// the problem is a conflict between the SuggestionItem version from core and extension
obj = s.get(key);
if (obj instanceof SuggestionItem) {
item = (SuggestionItem) obj;
keywords.set(key, item.getKeywords());
keywordScore.set(key, item.getKeywordScore());
} else {
Class clazz = obj.getClass();
try {
keywords.set(key, clazz.getMethod("getKeywords", new Class[0]).invoke(obj, new Object[0]));
keywordScore.set(key, clazz.getMethod("getKeywordScore", new Class[0]).invoke(obj, new Object[0]));
} catch (Exception e) {
}
}
}
String query = data.getSuggestionQuery();
if (query != null) {
String html = StringUtil.replace(query, "<suggestion>", "<b>", false);
html = StringUtil.replace(html, "</suggestion>", "</b>", false);
sct.set("suggestedQueryHTML", html);
String plain = StringUtil.replace(query, "<suggestion>", "", false);
plain = StringUtil.replace(plain, "</suggestion>", "", false);
sct.set("suggestedQuery", plain);
}
}
// if(suggestions!=SUGGESTIONS_NEVER)sct.set("suggestedQuery", "");
// sct.set("keywords", "");
// sct.set("keywordScore", "");
}
return SKIP_BODY;
}
Aggregations