Subversion Repositories SmartDukaan

Rev

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

Rev 17938 Rev 17944
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
es = None
33
from elasticsearch import Elasticsearch
34
from elasticsearch import Elasticsearch
34
from shop2020.config.client.ConfigClient import ConfigClient
35
from shop2020.config.client.ConfigClient import ConfigClient
35
 
36
 
36
DataService.initialize(db_hostname="localhost")
37
DataService.initialize(db_hostname="localhost")
37
mc = MemCache("127.0.0.1")
38
mc = MemCache("127.0.0.1")
38
config_client = ConfigClient()
39
config_client = ConfigClient()
39
elastic_search_host = config_client.get_property('elastic_search_host')
40
elastic_search_host = config_client.get_property('elastic_search_host')
40
elastic_search_port = config_client.get_property('elastic_search_port')
41
elastic_search_port = config_client.get_property('elastic_search_port')
41
es = Elasticsearch([{'host': elastic_search_host, 'port': elastic_search_port}])
-
 
-
 
42
 
42
 
43
 
43
 
44
 
44
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM",7:"HOMESHOP18.COM"}
45
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM",7:"HOMESHOP18.COM"}
45
 
46
 
46
COLLECTION_MAP = {
47
COLLECTION_MAP = {
Line 50... Line 51...
50
                  'SkuSchemeDetails':'skuBundleId',
51
                  'SkuSchemeDetails':'skuBundleId',
51
                  'DealPoints':'skuBundleId',
52
                  'DealPoints':'skuBundleId',
52
                  'FeaturedDeals': 'skuBundleId'
53
                  'FeaturedDeals': 'skuBundleId'
53
                  }
54
                  }
54
 
55
 
-
 
56
def get_elastic_search_connection():
-
 
57
    global es
-
 
58
    if es is None:
-
 
59
        print "Establishing connection with elastic search %s host and port %s"%(elastic_search_host,elastic_search_port)
-
 
60
        es = Elasticsearch([{'host': elastic_search_host, 'port': elastic_search_port}])
-
 
61
        return es
-
 
62
    return es
-
 
63
    
-
 
64
 
55
def get_mongo_connection(host='localhost', port=27017):
65
def get_mongo_connection(host='localhost', port=27017):
56
    global con
66
    global con
57
    if con is None:
67
    if con is None:
58
        print "Establishing connection %s host and port %d" %(host,port)
68
        print "Establishing connection %s host and port %d" %(host,port)
59
        try:
69
        try:
Line 1832... Line 1842...
1832
                    item[0]['filterLink'] = '/category/'+str(int(item[0]['category_id']))+'?filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
1842
                    item[0]['filterLink'] = '/category/'+str(int(item[0]['category_id']))+'?filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
1833
                    item[0]['filterText'] = 'More %s'%(item[0]['subCategory'])
1843
                    item[0]['filterText'] = 'More %s'%(item[0]['subCategory'])
1834
                except:
1844
                except:
1835
                    item[0]['filterLink'] = ''
1845
                    item[0]['filterLink'] = ''
1836
                    item[0]['filterText'] = ""
1846
                    item[0]['filterText'] = ""
-
 
1847
            try:
-
 
1848
                if item[0]['source_id']==4:
-
 
1849
                    item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
-
 
1850
                    if item_availability_info is None or len(item_availability_info)==0:
-
 
1851
                        item[0]['availabilityInfo'] = [{}]
-
 
1852
                    else:
-
 
1853
                        item[0]['availabilityInfo'] = item_availability_info
-
 
1854
            except:
-
 
1855
                item[0]['availabilityInfo'] = [{}]
1837
        
1856
        
1838
            temp.append(item[0])
1857
            temp.append(item[0])
1839
        if len(temp) > 1:
1858
        if len(temp) > 1:
1840
            temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
1859
            temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
1841
        dealsListMap.append(temp)
1860
        dealsListMap.append(temp)
Line 2415... Line 2434...
2415
          ]
2434
          ]
2416
        }
2435
        }
2417
      }
2436
      }
2418
    }
2437
    }
2419
    
2438
    
2420
    result =  es.search(index="my_index", body=payload, from_=offset, size=limit)
2439
    result =  get_elastic_search_connection().search(index="my_index", body=payload, from_=offset, size=limit)
2421
    totalCount= result['hits']['total']
2440
    totalCount= result['hits']['total']
2422
    temp = []
2441
    temp = []
2423
    bundles = []
2442
    bundles = []
2424
    if len(result['hits']['hits']) > 0:
2443
    if len(result['hits']['hits']) > 0:
2425
        for x in result['hits']['hits']:
2444
        for x in result['hits']['hits']:
Line 2452... Line 2471...
2452
          ]
2471
          ]
2453
        }
2472
        }
2454
      }
2473
      }
2455
    }
2474
    }
2456
    
2475
    
2457
    result =  es.search(index="my_index", body=payload)
2476
    result =  get_elastic_search_connection().search(index="my_index", body=payload)
2458
    totalCount= result['hits']['total']
2477
    totalCount= result['hits']['total']
2459
    return {'searchTerm':searchTerm,'count':totalCount}
2478
    return {'searchTerm':searchTerm,'count':totalCount}
2460
            
2479
            
2461
def main():
2480
def main():
-
 
2481
    import time
-
 
2482
    for i in range(0,10):
2462
    result = getCountForSearchText(20, "apple")
2483
        result = getCountForSearchText(20, "iph")
2463
    print result
2484
        print result
2464
    for x in getDealsForSearchText(20, "apple",0,20):
-
 
2465
        print x
2485
        time.sleep(20)
2466
 
2486
    
2467
if __name__=='__main__':
2487
if __name__=='__main__':
2468
    main()
2488
    main()
2469
 
2489
 
2470
 
2490