Skip to content

Commit

Permalink
Dev (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsam authored Aug 12, 2024
2 parents af81532 + 56ada69 commit ca0d0ec
Show file tree
Hide file tree
Showing 32 changed files with 3,988 additions and 3,720 deletions.
200 changes: 100 additions & 100 deletions locale/he/LC_MESSAGES/django.po

Large diffs are not rendered by default.

238 changes: 174 additions & 64 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4418,77 +4418,187 @@ def dummy_search_api(request):
resp['Content-Type'] = "application/json; charset=utf-8"
return resp

def search_sheet(query):
result = []
if query:
query = [
{
'$match': {
'$or': [
{
'sources.outsideBiText.en': {
'$regex': query,
'$options': 'i'
}
}, {
'sources.outsideBiText.he': {
'$regex': query,
'$options': 'i'
}
}
]
}
}, {
'$project': {
'owner': '$owner',
'id': '$id',
'title': '$title',
'sources': {
'$map': {
'input': '$sources',
'as': 'source',
'in': {
'$cond': [
{
'$or': [
{
'$regexMatch': {
'input': '$$source.outsideBiText.en',
'regex': query,
'options': 'i'
}
}, {
'$regexMatch': {
'input': '$$source.outsideBiText.he',
'regex': query,
'options': 'i'
}
}
]
}, {
'outsideBiText': {
'$cond': [
{
'$regexMatch': {
'input': '$$source.outsideBiText.en',
'regex': query,
'options': 'i'
}
}, {
'en': '$$source.outsideBiText.en'
}, {
'he': '$$source.outsideBiText.he'
}
]
},
'node': '$$source.node'
}, '$$REMOVE'
]
}
}
}
}
}, {
'$project': {
'sheet_id': '$id',
'title': '$title',
'owner_id': '$owner',
'sources': {
'$filter': {
'input': '$sources',
'as': 'source',
'cond': {
'$or': {
'$ne': [
'$$source', None
]
}
}
}
}
}
}
]
result = list(db.sheets.aggregate(query))

for item in result:
item.pop('_id', None)
return result

def search_text(chapter_query,title_query):
result = []
if chapter_query:
# data = json.loads(request.body)
# query = data.get('query', '')
print("query: ", chapter_query, "title", title_query)
query = [
{
"$unwind": {
"path": "$chapter",
"includeArrayIndex": "outerIndex"
}
},
{
"$unwind": {
"path": "$chapter",
"includeArrayIndex": "innerIndex"
}
},
{
"$addFields": {
"outerIndex": { "$add": ["$outerIndex", 1] },
"innerIndex": { "$add": ["$innerIndex", 1] }
}
},
{
"$match": {
"$and": [
{ "title": { "$regex": title_query, "$options": "i" } },
{ "chapter": { "$regex": chapter_query, "$options": "i" } }
]
}
},
{
"$group": {
"_id": "$_id",
"language": { "$first": "$language" },
"title": { "$first": "$title" },
"versionSource": { "$first": "$versionSource" },
"versionTitle": { "$first": "$versionTitle" },
"iscompleted": { "$first": "$iscompleted" },
"actualLanguage": { "$first": "$actualLanguage" },
"languageFamilyName": { "$first": "$languageFamilyName" },
"direction": { "$first": "$direction" },
"matchingChapters": {
"$push": {
"chapter": "$chapter",
"index": {
"$concat": [
{ "$toString": "$outerIndex" },
".",
{ "$toString": "$innerIndex" }
]
}
}
}
}
}
]
result = list(db.texts.aggregate(query))
for item in result:
item.pop('_id', None)
return result

@csrf_exempt
def mongo_search_api(request):

print(">>>>>>>>>>>>>>>>>>>>>request>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",request.method)
print(">>>>>>>>>>>>>>>>>>>>>text and sheet search from mongo>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",request.method)
result = {
"text": "",
"sheet": "",
}
if(request.method == "GET"):
try:
chapter_query = urllib.parse.unquote(request.GET.get('chapterQuery', ''))
title_query = urllib.parse.unquote(request.GET.get('titleQuery', ''))

if chapter_query:
# data = json.loads(request.body)
# query = data.get('query', '')
print("query: ", chapter_query, "title", title_query)
query = [
{
"$unwind": {
"path": "$chapter",
"includeArrayIndex": "outerIndex"
}
},
{
"$unwind": {
"path": "$chapter",
"includeArrayIndex": "innerIndex"
}
},
{
"$addFields": {
"outerIndex": { "$add": ["$outerIndex", 1] },
"innerIndex": { "$add": ["$innerIndex", 1] }
}
},
{
"$match": {
"$and": [
{ "title": { "$regex": title_query, "$options": "i" } },
{ "chapter": { "$regex": chapter_query, "$options": "i" } }
]
}
},
{
"$group": {
"_id": "$_id",
"language": { "$first": "$language" },
"title": { "$first": "$title" },
"versionSource": { "$first": "$versionSource" },
"versionTitle": { "$first": "$versionTitle" },
"iscompleted": { "$first": "$iscompleted" },
"actualLanguage": { "$first": "$actualLanguage" },
"languageFamilyName": { "$first": "$languageFamilyName" },
"direction": { "$first": "$direction" },
"matchingChapters": {
"$push": {
"chapter": "$chapter",
"index": {
"$concat": [
{ "$toString": "$outerIndex" },
".",
{ "$toString": "$innerIndex" }
]
}
}
}
}
}
]

result = list(db.texts.aggregate(query))
for item in result:
item.pop('_id', None)
return jsonResponse({'status': 'success', 'result': result})
text = search_text(chapter_query,title_query)
sheet = search_sheet(chapter_query)

result["text"] = text
result["sheet"] = sheet

return jsonResponse({'status': 'success', 'result': result})

except Exception as e:
print({'status': 'error', 'message': str(e)})
return jsonResponse({'status': 'error', 'message': str(e)}, status=500)
Expand Down
4 changes: 2 additions & 2 deletions sefaria/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class SefariaNewUserForm(EmailUserCreationForm):
first_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _("First Name"), 'autocomplete': 'off'}))
last_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _("Last Name"), 'autocomplete': 'off'}))
password1 = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': _("Password"), 'autocomplete': 'off'}))
subscribe_educator = forms.BooleanField(label=_("I am an educator"), help_text=_("I am an educator"), initial=False,
required=False)
# subscribe_educator = forms.BooleanField(label=_("I am an educator"), help_text=_("I am an educator"), initial=False,
# required=False)

captcha_lang = "iw" if get_language() == 'he' else "en"
captcha = ReCaptchaField(
Expand Down
2 changes: 1 addition & 1 deletion static/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ body.hebrew #talmudicPeoplePage #textTocLink {
color: #FFFFFF;
}
.interface-hebrew .onoffswitch-inner:before{
content: "לא";
content: "འགྲིག";
padding-right: 10px;
}
.onoffswitch-inner:after {
Expand Down
Loading

0 comments on commit ca0d0ec

Please sign in to comment.