Skip to content

Commit

Permalink
some fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
amirkamran committed Jun 22, 2017
1 parent 9290ff9 commit 0f88b59
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion js/piwik_charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
18 changes: 16 additions & 2 deletions scripts/luc/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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] = {}
Expand Down Expand Up @@ -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)

Expand Down
31 changes: 21 additions & 10 deletions scripts/search_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -13,67 +17,74 @@ 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')
seg = request.args.get('segment', None)
sid = [2, 4]
if seg == "views":
sid = 2
segment = "[email protected]/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):
Expand Down

0 comments on commit 0f88b59

Please sign in to comment.