Subversion Repositories SmartDukaan

Rev

Rev 17788 | Rev 17937 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17788 Rev 17936
Line 28... Line 28...
28
    import ordereddict
28
    import ordereddict
29
except:
29
except:
30
    pass
30
    pass
31
 
31
 
32
con = None
32
con = None
-
 
33
from elasticsearch import Elasticsearch
-
 
34
from shop2020.config.client.ConfigClient import ConfigClient
33
 
35
 
34
DataService.initialize(db_hostname="localhost")
36
DataService.initialize(db_hostname="localhost")
35
mc = MemCache("127.0.0.1")
37
mc = MemCache("127.0.0.1")
-
 
38
config_client = ConfigClient()
-
 
39
elastic_search_host = config_client.get_property('elastic_search_host')
-
 
40
elastic_search_port = config_client.get_property('elastic_search_port')
-
 
41
es = Elasticsearch([{'host': elastic_search_host, 'port': elastic_search_port}])
-
 
42
 
36
 
43
 
37
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM",7:"HOMESHOP18.COM"}
44
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM",7:"HOMESHOP18.COM"}
38
 
45
 
39
COLLECTION_MAP = {
46
COLLECTION_MAP = {
40
                  'ExceptionalNlc':'skuBundleId',
47
                  'ExceptionalNlc':'skuBundleId',
Line 1734... Line 1741...
1734
    if skuData is None:
1741
    if skuData is None:
1735
        return {}
1742
        return {}
1736
    else:
1743
    else:
1737
        return skuData
1744
        return skuData
1738
    
1745
    
1739
def getDealsForNotification(skuBundleIds):
1746
def getDealsForNotification(skuBundleIds,skipSplitting=False):
-
 
1747
    if not skipSplitting:
1740
    bundles= [int(skuBundleId) for skuBundleId in skuBundleIds.split(',')]
1748
        bundles= [int(skuBundleId) for skuBundleId in skuBundleIds.split(',')]
1741
    print bundles
1749
        print bundles
-
 
1750
    else:
-
 
1751
        bundles = skuBundleIds
1742
    dealsList = []
1752
    dealsList = []
1743
    dealsListMap = []
1753
    dealsListMap = []
1744
    for bundleId in bundles:
1754
    for bundleId in bundles:
1745
        outer_query = []
1755
        outer_query = []
1746
        outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
1756
        outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
Line 2382... Line 2392...
2382
    try:
2392
    try:
2383
        get_mongo_connection().Catalog.DummyUser.update({'_id':data['user_id']},{"$set":data},upsert=False)
2393
        get_mongo_connection().Catalog.DummyUser.update({'_id':data['user_id']},{"$set":data},upsert=False)
2384
        return {'msg':"Data updated successfuly",'response':1}
2394
        return {'msg':"Data updated successfuly",'response':1}
2385
    except:
2395
    except:
2386
        return {'msg':"Unable to update data",'response':0}
2396
        return {'msg':"Unable to update data",'response':0}
2387
 
-
 
2388
    
2397
    
-
 
2398
def getDealsForSearchText(subCategoryId, searchTerm, offset, limit):
-
 
2399
    payload = {
-
 
2400
      "query": {
-
 
2401
        "bool": {
-
 
2402
          "must": [
-
 
2403
            {
-
 
2404
              "match": {
-
 
2405
                    "title": {
-
 
2406
                    "query": searchTerm, 
-
 
2407
                    "operator": "and"
-
 
2408
                    }
-
 
2409
               }
-
 
2410
            },
-
 
2411
            {
-
 
2412
              "match": {
-
 
2413
                "subCategoryId": {
-
 
2414
                  "query": subCategoryId
-
 
2415
                }
-
 
2416
              }
-
 
2417
            }
-
 
2418
          ]
-
 
2419
        }
-
 
2420
      }
-
 
2421
    }
-
 
2422
    
-
 
2423
    result =  es.search(index="my_index", body=payload, from_=offset, size=limit)
-
 
2424
    totalCount= result['hits']['total']
-
 
2425
    temp = []
-
 
2426
    bundles = []
-
 
2427
    if len(result['hits']['hits']) > 0:
-
 
2428
        for x in result['hits']['hits']:
-
 
2429
            tempMap = {}
-
 
2430
            tempMap = {'skuBundleId':x['_source']['id'],'title':x['_source']['title']}
-
 
2431
            temp.append(tempMap)
-
 
2432
            bundles.append(x['_source']['id'])
-
 
2433
    return getDealsForNotification(bundles, skipSplitting=True)
2389
 
2434
 
-
 
2435
def getCountForSearchText(subCategoryId, searchTerm):
-
 
2436
    payload = {
-
 
2437
      "query": {
-
 
2438
        "bool": {
-
 
2439
          "must": [
-
 
2440
            {
-
 
2441
              "match": {
-
 
2442
                    "title": {
-
 
2443
                    "query": searchTerm, 
-
 
2444
                    "operator": "and"
-
 
2445
                    }
-
 
2446
               }
-
 
2447
            },
-
 
2448
            {
-
 
2449
              "match": {
-
 
2450
                "subCategoryId": {
-
 
2451
                  "query": subCategoryId
-
 
2452
                }
-
 
2453
              }
-
 
2454
            }
-
 
2455
          ]
-
 
2456
        }
-
 
2457
      }
-
 
2458
    }
-
 
2459
    
-
 
2460
    result =  es.search(index="my_index", body=payload)
-
 
2461
    totalCount= result['hits']['total']
-
 
2462
    return {'searchTerm':searchTerm,'count':totalCount}
-
 
2463
            
2390
def main():
2464
def main():
2391
    featuredDeals = mc.get("featured_deals")
2465
    result = getCountForSearchText(20, "apple")
2392
    print resetCache("47")
2466
    print result
2393
    print datetime.now()
-
 
2394
    x=  getNewDeals(47, 6, 0, 20, None, None, None)
2467
    for x in getDealsForSearchText(20, "apple",0,20):
2395
    print "=========================="
-
 
2396
    for y in x:
-
 
2397
        print y[0]['skuBundleId'],
-
 
2398
        print '\t',
2468
        print x
2399
        print y[0]['brand']
-
 
2400
    print datetime.now()
-
 
2401
 
-
 
2402
 
-
 
2403
        
-
 
2404
 
2469
 
2405
if __name__=='__main__':
2470
if __name__=='__main__':
2406
    main()
2471
    main()
2407
 
2472
 
-
 
2473