List of usage examples for org.apache.solr.search SolrCache put
public V put(K key, V value);
From source file:com.downtree.tourbus.search.TBRequestHandler.java
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) { m_numRequests++;//from w ww . ja v a 2s .c om // TODO: test if lucene will accept an escaped ';', otherwise // we need to un-escape them before we pass to QueryParser try { String sreq = req.getQueryString(); String debug = U.getParam(req, CommonParams.DEBUG_QUERY, params.debugQuery); String defaultField = U.getParam(req, CommonParams.DF, params.df); // find fieldnames to return (fieldlist) String fl = U.getParam(req, CommonParams.FL, params.fl); int flags = 0; if (fl != null) { flags |= U.setReturnFields(fl, rsp); } if (sreq == null) throw new SolrException(400, "Missing queryString"); List<String> commands = StrUtils.splitSmart(sreq, ';'); String qs = commands.size() >= 1 ? commands.get(0) : ""; Query query = QueryParsing.parseQuery(qs, defaultField, req.getSchema()); // If the first non-query, non-filter command is a simple sort on an // indexed field, then // we can use the Lucene sort ability. Sort sort = null; if (commands.size() >= 2) { QueryParsing.SortSpec sortSpec = QueryParsing.parseSort(commands.get(1), req.getSchema()); if (sortSpec != null) { sort = sortSpec.getSort(); // ignore the count for now... it's currently only // controlled by start & limit on req // count = sortSpec.getCount(); } } // TB stuff DocSet filter = null; String latStr = U.getParam(req, "lat", null); String longStr = U.getParam(req, "long", null); String radiusStr = U.getParam(req, "radius", null); String docType = U.getParam(req, "docType", null); if (latStr != null && longStr != null && radiusStr != null && docType != null) { String key = getFilterCacheKey(latStr, longStr, radiusStr, docType); SolrCache cache = req.getSearcher().getCache("locationFilterCache"); filter = (DocSet) cache.get(key); if (filter == null) { LocationFilter locFilter = new LocationFilter(docType, Double.parseDouble(latStr), Double.parseDouble(longStr), Double.parseDouble(radiusStr)); filter = req.getSearcher().convertFilter(locFilter); cache.put(key, filter); m_filterCacheMisses++; } else { m_filterCacheHits++; } } DocList results = req.getSearcher().getDocList(query, filter, sort, req.getStart(), req.getLimit()); rsp.add(null, results); try { NamedList dbg = U.doStandardDebug(req, qs, query, results, params); if (null != dbg) rsp.add("debug", dbg); } catch (Exception e) { SolrException.logOnce(SolrCore.log, "Exception durring debug", e); rsp.add("exception_during_debug", SolrException.toStr(e)); } } catch (SolrException e) { rsp.setException(e); m_numErrors++; return; } catch (Exception e) { SolrException.log(SolrCore.log, e); rsp.setException(e); m_numErrors++; return; } }
From source file:com.ifactory.press.db.solr.search.ScoringParentQParser.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Filter getFilter(Query parentList) {
SolrCache parentCache = req.getSearcher().getCache(CACHE_NAME);
// lazily retrieve from solr cache
Filter filter = null;// w w w. jav a 2 s . c o m
if (parentCache != null) {
filter = (Filter) parentCache.get(parentList);
}
Filter result;
if (filter == null) {
result = createParentFilter(parentList);
if (parentCache != null) {
parentCache.put(parentList, result);
}
} else {
result = filter;
}
return result;
}
From source file:com.indoqa.solr.spatial.corridor.query.route.LineStringUtils.java
License:Apache License
@SuppressWarnings("unchecked") public static LineString parse(String corridorLineString, SolrIndexSearcher indexSearcher) throws SyntaxError { if (corridorLineString == null) { throw new SyntaxError("Parameter corridor.route must be set and a valid LineString!"); }/* ww w. j a v a 2s .c om*/ SolrCache<String, LineString> lineStringCache = indexSearcher.getCache("corridorLineStrings"); LineString lineString = lineStringCache.get(corridorLineString); if (lineString == null) { lineString = parseWkt(corridorLineString); lineStringCache.put(corridorLineString, lineString); } return lineString; }
From source file:org.opencommercesearch.lucene.queries.function.valuesource.BoostValueSourceParser.java
License:Apache License
/** * Loads the boosts for the given boostId through the API. * * @param boostId is the boost id//from w w w.ja v a 2 s.c o m * @return the boost mappings */ private Map<String, Float> loadBoosts(String boostId, SolrCache<String, Map<String, Float>> cache) { Map<String, Float> boosts = cache.get(boostId); if (boosts != null) { if (log.isDebugEnabled()) log.debug("Found " + boosts.size() + " for " + boostId + " in cache"); return boosts; } boosts = Collections.emptyMap(); try { String uri = boostApiHost + "/v1/boosts/" + boostId + "?limit=" + boostLimit; HttpGet get = new HttpGet(uri); HttpResponse response = defaultClient.execute(get); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); JSONObject json = new JSONObject(EntityUtils.toString(entity)); boosts = new HashMap<String, Float>(); if (json.has("boosts")) { JSONArray boostArray = json.getJSONArray("boosts"); if (boostArray != null) { for (int i = 0; i < boostArray.length(); i++) { JSONObject boost = boostArray.getJSONObject(i); if (boost.has("id") && boost.has("value")) { boosts.put(boost.getString("id"), ((Double) boost.get("value")).floatValue()); } } } } log.info("Found " + boosts.size() + " for " + boostId); cache.put(boostId, boosts); return boosts; } else if (statusCode == HttpStatus.SC_NOT_FOUND) { log.info("No boosts found for " + boostId); cache.put(boostId, boosts); } else { log.error("Cannot retrieve boosts for " + boostId + ". API response code was " + statusCode); } } catch (ClientProtocolException ex) { log.error("Cannot retrieve boosts for " + boostId, ex); } catch (IOException ex) { log.error("Cannot retrieve boosts for " + boostId, ex); } return boosts; }
From source file:org.opencommercesearch.search.BoostCacheRegenerator.java
License:Apache License
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException { long time = System.currentTimeMillis(); if (time - loadTime > ttlMs) { log.info("Boost ttl exceeded, stopping regeneration"); newCache.clear();/*www . ja va 2s . c o m*/ loadTime = time; return false; } newCache.put(oldKey, oldVal); return true; }