Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_search_mongo():
mongo_query = {"$or": [{"title": {"$options": "i", "$regex": "Cheyenne"}}, {"title": {"$options": "i", "$regex": "technique"}}]}
mongo_query = {"$and": [{"$or": [{"title": {"$options": "i", "$regex": "Cheyenne"}}, {"title": {"$options": "i", "$regex": "technique"}}]}, {"publishers": {"$regex": "press", "$options": 'i'}}]}
search_result = repository_service.search_mongo(None, mongo_query)
print "search_result:"
print jsonbson.dumps_bson(search_result, True)
search_query["filter_types"] = ["Book", "BookPart"]
search_query["rec_class"] = "SearchQuery"
search_query["rec_metajson"] = 1
search_query["result_batch_size"] = 100
search_query["result_bibliographic_styles"] = ["mla"]
search_query["result_offset"] = 0
search_query["result_sorts"] = [{"field": "rec_type", "order": "asc"}]
search_query["search_terms"] = [{"index": "title", "operator": "and", "value": "Cheyenne"}, {"index": "title", "operator": "or", "value": "technique"}]
print "search_query:"
print jsonbson.dumps_json(search_query, True)
search_result = repository_service.search(None, search_query)
print "search_result:"
print jsonbson.dumps_bson(search_result, True)
header += "<title>BibLib HTML export</title>\n"
header += "\n"
header += "\n"
output_file.write(header)
for document in metajson_list:
source_info = ""
if "rec_source" in document and document["rec_source"]:
source_info += document["rec_source"] + ":"
if "rec_id" in document and document["rec_id"]:
source_info += document["rec_id"] + ":"
citation = citations_manager.cite(document, style, "html")
debug = True
if debug:
meta = jsonbson.dumps_bson(document, True)
output_file.write("<pre>" + meta + "</pre>\n")
output_file.write("\n")
output_file.write("<div>" + citation + "</div>\n")
footer = "\n"
footer += ""
output_file.write(footer)
def print_document(document):
logging.info("document : {}".format(jsonbson.dumps_bson(document)))
elif meta_dict["rec_class"] == "Event":
return Event(meta_dict)
elif meta_dict["rec_class"] == "Family":
return Family(meta_dict)
elif meta_dict["rec_class"] == "Field":
return Field(meta_dict)
elif meta_dict["rec_class"] == "Resource":
return Resource(meta_dict)
elif meta_dict["rec_class"] == "Target":
return Target(meta_dict)
elif meta_dict["rec_class"] == "Type":
return Type(meta_dict)
elif meta_dict["rec_class"] == "Collection":
return Collection(meta_dict)
else:
logging.debug(jsonbson.dumps_bson(meta_dict))
logging.warning("Unknown rec_class: {O}".format(meta_dict["rec_class"]))
return Common(meta_dict)
def write_json(item, output_file_path):
#logging.debug("write_json type(item): {}".format(type(item)))
with open(output_file_path, "w") as output_file:
dump = jsonbson.dumps_bson(item, True)
if dump:
output_file.write(dump)