Beispiel #1
0
def create_product():
    if not request.json or not 'productId_s' in request.json:
        abort(400)
    product = _create_product_from_json(request.json)
    SolrClient.add([product])

    return jsonify({'Create Product': product})
Beispiel #2
0
def update_product(product_id):
    if not request.json or not 'productId_s' in request.json:
        abort(400)

    product_old = SolrClient.search(query="productId_s:%s" % product_id)
    if not product_old:
        abort(404)
    SolrClient.delete(query="productId_s:%s" % product_id)
    product_new = _create_product_from_json(request.json)
    SolrClient.add([product_new])
    return jsonify({
        'Old Product': product_old,
        'Updated Product': product_new
    })
Beispiel #3
0
def initialize_database():
    SolrClient.initialize()
Beispiel #4
0
def search_by_brand(brand):
    res = SolrClient.search(query="brand_s:%s" % brand)
    return jsonify({'brand_res': res})
Beispiel #5
0
def search_by_ingredient(ingredient):
    res = SolrClient.search(query="ingredients_ss:%s" % ingredient)
    return jsonify({'ingredient_res': res})
Beispiel #6
0
def search_by_name(name):
    res = SolrClient.search(query="name_s:%s" % name)
    return jsonify({'name_res': res})
Beispiel #7
0
def get_products_list():
    res = SolrClient.search(query='*:*')
    return jsonify({'products': res})
Beispiel #8
0
def delete_product(product_id):
    products = SolrClient.search(query="productId_s:%s" % product_id)
    if len(products) == 0:
        abort(404)
    SolrClient.delete(query=product_id)
    return jsonify({'result': [True, products]})
Beispiel #9
0
from models.product import Product
from solrclient import SolrClient

SolrClient.initialize()
# print(SolrClient.search(query="*:*"))
# print(SolrClient.search(query="brand_s:Acne.org"))
# print(SolrClient.search(query="Acne.org"))

# print(SolrClient.search(query="PEG-80 Sorbitan Laurate"))
# print(SolrClient.search(query="ingredients_ss:PEG-80 Sorbitan Laurate"))
# p1 = Product('nameA','brandA','a.jpg',['ingA','ingAA'],1).json()

# p2 = Product('nameB',"brandB",'a.jpg','ingB',2).json()
# p3 = Product('nameC','brandA','A.jpg',['ingAA'],3).json()
# p4 = Product('nameD','branda','a.jpg',['ingD'],4).json()
# test for update_replace
#
# """
# print(p1)
# SolrClient.add([p1])
# oriData = SolrClient.search(query='a.jpg')[0]
# print('original doc', oriData)
# oriData['brand_s'] = 'brandA_new'
# oriData['name_s'] = 'nameA_new'
# SolrClient.update_replace(oriData,['brand_s','name_s'])
# newData = SolrClient.search(query='a.jpg')[0]
# print('new data', newData)
# """test for update_add
# """
# print(p2)
# print(p3)