diff --git a/js/piwik_charts.js b/js/piwik_charts.js index 3e9b00b..4d5daf1 100644 --- a/js/piwik_charts.js +++ b/js/piwik_charts.js @@ -82,7 +82,7 @@ loadData = function(what, date, period, segment) { } if(!(period in already_loaded_dates[segment][what] && date in already_loaded_dates[segment][what][period])) { return $.getJSON(base_url + what + params, function(data) { - loaded_data[segment][what] = $.extend(true, loaded_data[segment][what], data); + loaded_data[segment][what] = $.extend(true, loaded_data[segment][what], data["response"]); if(!(period in already_loaded_dates[segment][what])) already_loaded_dates[segment][what][period] = {}; if(!(date in already_loaded_dates[segment][what][period])) already_loaded_dates[segment][what][period][date] = true; }); diff --git a/scripts/luc/searcher.py b/scripts/luc/searcher.py index 8500a40..91b7a62 100644 --- a/scripts/luc/searcher.py +++ b/scripts/luc/searcher.py @@ -7,6 +7,7 @@ from org.apache.lucene.store import SimpleFSDirectory from org.apache.lucene.queryparser.classic import QueryParser from urllib.parse import unquote_plus +import re def create_query(dmy, typ, period="year", site_id=None, segment=None, handle=None): @@ -247,6 +248,19 @@ def search_urls(self, dmy=None, period='year', site_id=None, segment=None): else: url = unquote_plus(doc["label"]).split("?")[0] + if ".continue" in url: + url = "/".join(url.split("/")[:-1]) + + if url.startswith("services"): + if url.startswith("services/treex-web/api/v1/results"): + url = "services/treex-web/api/v1/results" + if url.startswith("services/treex-web/result"): + url = "services/treex-web/result" + + url = re.sub(r'(services/pmltq/index#!/treebank/.+/query)/.+', '\\1', url) + + url = re.sub(r'/(\./)+', '/', url) + if period == 'year': if year not in results: results[year] = {} @@ -281,9 +295,9 @@ def search_urls(self, dmy=None, period='year', site_id=None, segment=None): return results - def search_handle(self, dmy=None, period='year', site_id=None, handle=None): + def search_handle(self, dmy=None, period='year', site_id=None, handle=None, segment=None): - q = create_query(dmy, "urls", period=period, site_id=site_id, handle=handle) + q = create_query(dmy, "urls", period=period, site_id=site_id, handle=handle, segment=segment) print(q) docs = self.search(q) diff --git a/scripts/search_application.py b/scripts/search_application.py index 1e89a0f..4bbc46a 100644 --- a/scripts/search_application.py +++ b/scripts/search_application.py @@ -2,8 +2,12 @@ from flask import Flask, request, jsonify app = Flask(__name__) +app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False +app.config['JSON_AS_ASCII'] = False index = "path_to_index_folder" +s = searcher.Searcher(index) + @app.route('/') def home(): @@ -13,57 +17,61 @@ def home(): @app.route('/views') def search_views(): - s = searcher.Searcher(index) dmy = request.args.get('date', None) period = request.args.get('period', 'year') if dmy: dmy = dmy.split("-") seg = request.args.get('segment', None) seg, sid = which_segment(seg) - return jsonify(s.search_views(dmy=dmy, period=period, site_id=sid, segment=seg)) + res = dict() + res["response"] = s.search_views(dmy=dmy, period=period, site_id=sid, segment=seg) + return jsonify(res) @app.route('/visits') def search_visits(): - s = searcher.Searcher(index) dmy = request.args.get('date', None) period = request.args.get('period', 'year') if dmy: dmy = dmy.split("-") seg = request.args.get('segment', None) seg, sid = which_segment(seg) - return jsonify(s.search_visits(dmy=dmy, period=period, site_id=sid, segment=seg)) + res = dict() + res["response"] = s.search_visits(dmy=dmy, period=period, site_id=sid, segment=seg) + return jsonify(res) @app.route('/country') def search_country(): - s = searcher.Searcher(index) dmy = request.args.get('date', None) period = request.args.get('period', 'year') if dmy: dmy = dmy.split("-") seg = request.args.get('segment', None) seg, sid = which_segment(seg) - return jsonify(s.search_country(dmy=dmy, period=period, site_id=sid, segment=seg)) + res = dict() + res["response"] = s.search_country(dmy=dmy, period=period, site_id=sid, segment=seg) + return jsonify(res) @app.route('/urls') def search_urls(): - s = searcher.Searcher(index) dmy = request.args.get('date', None) period = request.args.get('period', 'year') if dmy: dmy = dmy.split("-") seg = request.args.get('segment', None) seg, sid = which_segment(seg, route="urls") - return jsonify(s.search_urls(dmy=dmy, period=period, site_id=sid, segment=seg)) + res = dict() + res["response"] = s.search_urls(dmy=dmy, period=period, site_id=sid, segment=seg) + return jsonify(res) @app.route('/handle') def search_hanlde(): - s = searcher.Searcher(index) dmy = request.args.get('date', None) period = request.args.get('period', 'year') + segment = None if dmy: dmy = dmy.split("-") h = request.args.get('h') @@ -71,9 +79,12 @@ def search_hanlde(): sid = [2, 4] if seg == "views": sid = 2 + segment = "pageUrl=@lindat.mff.cuni.cz/repository/xmlui/handle" elif seg == "downloads": sid = 4 - return jsonify(s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h)) + res = dict() + res["response"] = s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h, segment=segment) + return jsonify(res) def which_segment(seg, route=None):