-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added opasQueryHelper with QueryTextToSolr to parse form text query fields and translate to Solr syntax - Went through a brief testing to see what libraries are required and then to produce a minimal set. Works on initial clean install testing. - changeed banners to depend on client relative image folder (for now)
- Loading branch information
Showing
6 changed files
with
139 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# pylint: disable=C0321,C0103,C0301,E1101,C0303,E1004,C0330,R0915,R0914,W0703,C0326 | ||
|
||
""" | ||
opasQueryHelper | ||
This library is meant to hold parsing and other functions which support query translation to Solr | ||
2019.1205.1 - First version | ||
""" | ||
__author__ = "Neil R. Shapiro" | ||
__copyright__ = "Copyright 2019, Psychoanalytic Electronic Publishing" | ||
__license__ = "Apache 2.0" | ||
__version__ = "2019.1205.1" | ||
__status__ = "Development" | ||
|
||
import re | ||
|
||
class QueryTextToSolr(): | ||
def __init__(self): | ||
regex_token_quoted = "[\^]?[\'\"][^\'\"]+[\'\"]" | ||
regex_token_word = "(?P<word>[^\|\^\&\(\"\'\s)]+)" | ||
# regex_word_or_quoted = f"{regex_token_quoted}|{regex_token_word}" | ||
# token_not = re.compile("\sAND\s", re.IGNORECASE) | ||
|
||
self.counter = 0 | ||
self.token_quoted = re.compile(regex_token_quoted, re.IGNORECASE) | ||
self.token_or = re.compile("\sOR\s", re.IGNORECASE) | ||
self.token_and = re.compile("\sAND\s", re.IGNORECASE) | ||
self.token_word = re.compile(regex_token_word, re.IGNORECASE) | ||
|
||
def markup(self, str_input, label_word): | ||
def quotedrepl(matchobj): | ||
self.counter += 1 | ||
return f'QS{self.counter}' | ||
|
||
self.counter = 0 | ||
token_list = self.token_quoted.findall(str_input) | ||
ret_val = self.token_quoted.sub(quotedrepl, str_input) | ||
ret_val = self.token_or.sub(" || ", ret_val) | ||
ret_val = self.token_and.sub(" && ", ret_val) | ||
ret_val = self.token_word.sub(f"{label_word}:\g<word>", ret_val) | ||
counter2 = 1 | ||
# take care of ^ to - before quotes go back | ||
ret_val = re.sub("\^\s*\(", "-(", ret_val) | ||
for n in token_list: | ||
ret_val = re.sub(f"QS{counter2}", n, ret_val) | ||
counter2 += 1 | ||
|
||
ptn_token_not = f"{label_word}:(\^)" | ||
ptn_token_not2 = f"(\^){label_word}:" | ||
ret_val = re.sub(ptn_token_not, f"-{label_word}:", ret_val) | ||
ret_val = re.sub(ptn_token_not2, f"-{label_word}:", ret_val) | ||
|
||
# debug only | ||
# print (str_input, ":", ret_val) | ||
return ret_val | ||
|
||
# ------------------------------------------------------------------------------------------------------- | ||
# run it! | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
print ("Running in Python %s" % sys.version_info[0]) | ||
|
||
|
||
tests = ["dog or 'fred flints*' and 'barney rubble'", | ||
"dog and cat and ^provided", | ||
"dog and (cat or flea)", | ||
"dog and ^(cat or flea)", | ||
"dog or 'fred flintstone' and ^'barney rubble'", | ||
"fr* and flintstone or ^barney", | ||
"dog and (cat and flea)", | ||
"dog or cat", | ||
"fleet footed", | ||
"dog and ^cat or ^mouse and pig or hawk", | ||
"dog AND cat or 'mouse pig'", | ||
"dog AND cat or ^'mouse pig bird'", | ||
"'freudian slip' or 'exposure therapy'" | ||
] | ||
|
||
label_word = "text_xml" | ||
for n in tests: | ||
mu = QueryTextToSolr() | ||
print (n, ":", mu.markup(n, label_word)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
# updated 20191120 | ||
aiofiles==0.4.0 | ||
asn1crypto==0.24.0 | ||
bcrypt==3.1.7 | ||
certifi==2019.6.16 | ||
cffi==1.12.3 | ||
certifi==2019.11.28 | ||
cffi==1.13.2 | ||
chardet==3.0.4 | ||
Click==7.0 | ||
cryptography==2.7 | ||
dnspython==1.16.0 | ||
EbookLib==0.17.1 | ||
email-validator==1.0.4 | ||
fastapi==0.38.1 | ||
future==0.17.1 | ||
email-validator==1.0.5 | ||
fastapi==0.44.1 | ||
future==0.18.2 | ||
h11==0.8.1 | ||
html5lib==1.0.1 | ||
idna==2.8 | ||
itsdangerous==1.1.0 | ||
lxml==4.4.1 | ||
passlib==1.7.1 | ||
Pillow==6.2.0 | ||
lxml==4.4.2 | ||
parse==1.6.5 | ||
passlib==1.7.2 | ||
Pillow==6.2.1 | ||
pycparser==2.19 | ||
pydantic==0.32.2 | ||
pydantic==1.2 | ||
PyJWT==1.7.1 | ||
PyMySQL==0.9.3 | ||
PyPDF2==1.26.0 | ||
python-multipart==0.0.5 | ||
reportlab==3.5.28 | ||
reportlab==3.5.32 | ||
requests==2.22.0 | ||
six==1.12.0 | ||
sqlalchemy=-1.3.11 | ||
starlette==0.12.8 | ||
treelib==1.5.5 | ||
urllib3==1.25.3 | ||
uvicorn==0.9.0 | ||
six==1.13.0 | ||
SQLAlchemy==1.3.11 | ||
starlette==0.12.9 | ||
urllib3==1.25.7 | ||
uvicorn==0.10.8 | ||
webencodings==0.5.1 | ||
websockets==8.0.2 | ||
xhtml2pdf==0.2.3 | ||
websockets==8.1 | ||
xhtml2pdf==0.2.3 |