Skip to content

Commit

Permalink
Better elastic search
Browse files Browse the repository at this point in the history
  • Loading branch information
pdonorio committed Oct 10, 2017
1 parent 067df6f commit 584a4f7
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 63 deletions.
43 changes: 24 additions & 19 deletions confs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
User configuration
"""

import sys
import os
import re
import argparse
Expand All @@ -18,29 +19,33 @@

#############################
# Command line arguments

def my_cli_arguments():
arg = argparse.ArgumentParser(description='REST API server based on Flask')
arg.add_argument("--no-security", action="store_false", dest='security',
help='force removal of login authentication on resources')
arg.add_argument("--debug", action="store_true", dest='debug',
help='enable debugging mode')
arg.add_argument(
"--remove-old", action="store_true", dest='rm',
help='force removal of previous new tables')
arg.set_defaults(security=True, debug=False)
return arg.parse_args()

args = None
default_debug = False
is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")

if not is_gunicorn:
args = my_cli_arguments()
default_debug = args.debug
if 'operations.py' not in sys.argv[0]:

def my_cli_arguments():
arg = argparse.ArgumentParser(
description='REST API server based on Flask')
arg.add_argument(
"--no-security", action="store_false", dest='security',
help='force removal of login authentication on resources')
arg.add_argument(
"--debug", action="store_true", dest='debug',
help='enable debugging mode')
arg.add_argument(
"--remove-old", action="store_true", dest='rm',
help='force removal of previous new tables')
arg.set_defaults(security=True, debug=False)
return arg.parse_args()

is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")

if not is_gunicorn:
args = my_cli_arguments()
default_debug = args.debug

DEBUG = os.environ.get('API_DEBUG', default_debug)
#DEBUG = True
# DEBUG = True

###################################################
###################################################
Expand Down
14 changes: 11 additions & 3 deletions operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
Operations based on services pre-installed
"""

import sys
from operations import rethink2elastic as r2e
from operations import rethink
# from restapi import get_logger
# logger = get_logger(__name__)
from restapi import get_logger
log = get_logger(__name__)

skip_lexique = True
if len(sys.argv) > 1:
skip_lexique = bool(int(sys.argv[1]))

#########################
# RETHINKDB
Expand All @@ -19,10 +24,13 @@
# rethink.build_zoom(force=False)
# rethink.medium_expo_thumbnail(force=False)
# rethink.fix_languages()
# rethink.some_operation()
rethink.some_operation()
# rethink.find_word(['sucre', 'atlas', 'nympha'])
# exit(1)

#########################
# RETHINKDB 2 ELASTICSEARCH
log.info("Skipping Lexique creation? %s", skip_lexique)

# r2e.make()
# FIXME
Expand Down
28 changes: 27 additions & 1 deletion operations/rethink.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

######################
# Parameters
if args.rm:
if args is not None and args.rm:
log.info("Remove previous data")
tables = query.list_tables()
if tin in tables:
Expand Down Expand Up @@ -94,6 +94,32 @@ def convert_schema():
# check_indexes(t2in)


def find_word(tofind=[]):

def find(words):
for word in tofind:
if word in words.lower():
log.info("ID: %s has %s", element.get('record'), word)
return True
return False

table = query.get_table_query('datadocs')

for element in table.run():
try:
image = element.get('images', []).pop()
except IndexError:
continue
# pp(image)

texts = image.get('transcriptions', [])
texts.extend(list(image.get('translations', {}).values()))
for words in texts:
if words is not None:
if find(words):
break


def some_operation():

# x = "48167161-d5ce-4ed0-afef-cb2a710eab17"
Expand Down

0 comments on commit 584a4f7

Please sign in to comment.