Esempio n. 1
0
def getSize(request,store_name):
  store = None
  try:
    store = ContentStore.objects.get(name=store_name)
  except ContentStore.DoesNotExist:
    resp = {'ok' : False,'error' : 'store: %s does not exist.' % store_name}
    return HttpResponseNotFound(json.dumps(resp))
  senseiHost = store.broker_host
  senseiPort = store.broker_port
  senseiClient = SenseiClient(senseiHost,senseiPort)
  req = SenseiRequest()
  req.count = 0
  res = senseiClient.doQuery(req)
  resp = {'store':store_name,"size":res.totalDocs}
  return HttpResponse(json.dumps(resp))
Esempio n. 2
0
def getSize(request,store_name):
  store = None
  try:
    store = ContentStore.objects.get(name=store_name)
  except ContentStore.DoesNotExist:
    resp = {'ok' : False,'error' : 'store: %s does not exist.' % store_name}
    return HttpResponseNotFound(json.dumps(resp))
  senseiHost = store.broker_host
  senseiPort = store.broker_port
  senseiClient = SenseiClient(senseiHost,senseiPort)
  req = SenseiRequest()
  req.count = 0
  res = senseiClient.doQuery(req)
  resp = {'store':store_name,"size":res.totalDocs}
  return HttpResponse(json.dumps(resp))
Esempio n. 3
0
  def execute_bql(stmt):
    req = SenseiRequest(stmt)
    store = my_client.store_map.get(req.index)
    if not store:
      print "Store %s does not exist!" % req.index
      return

    client = SenseiClient(store["broker_host"], store["broker_port"])
    if req.stmt_type == "select":
      res = client.doQuery(req)
      res.display(req.get_columns(), 1000)
    elif req.stmt_type == "desc":
      sysinfo = client.getSystemInfo()
      sysinfo.display()
    else:
      print "Wrong command: %s" % stmt
Esempio n. 4
0
 def openStore(self, name, api_key):
   baseurl = 'http://%s:%d/%s' % (self.host, self.port, 'store')
   url = '%s/%s/%s' % (baseurl,'open-store',name)
   urlReq = urllib2.Request(url)
   self.opener.addheaders = [('X-Sin-Api-Key', api_key)]
   res = self.opener.open(urlReq)
   jsonObj = json.loads(res.read())
   
   if not jsonObj['ok']:
     errorMsg = "error: %s" % jsonObj.get('error','unknown error')
     raise Exception(errorMsg)
   
   brokerPort = jsonObj['broker_port']
   senseiPort = jsonObj['sensei_port']
   storeId = jsonObj['id']
   storeConfig = jsonObj.get('config')
   storeCreated = jsonObj['created']
   storeStatus = jsonObj['status']
   description = jsonObj.get('description',None)
   status = jsonObj['status_display']
   
   senseiClient = SenseiClient(self.host, brokerPort)
   sindex = Sindex(storeId,name,api_key,description,storeCreated,baseurl,storeConfig,senseiClient,status,self.cookie_jar)
   while not sindex.available():
     time.sleep(0.5)
   
   return sindex
Esempio n. 5
0
def findDoc(store,id):
  senseiHost = store.broker_host
  senseiPort = store.broker_port
  senseiClient = SenseiClient(senseiHost,senseiPort)
  req = SenseiRequest()
  sel = SenseiSelection("uid")
  sel.addSelection(str(id))
  req.count = 1
  req.fetch = True
  req.selections = [sel]
  res = senseiClient.doQuery(req)
  doc = None
  if res.numHits > 0:
    if res.hits and len(res.hits) > 0:
      hit = res.hits[0]
      doc = hit.srcData
  return doc
Esempio n. 6
0
def find_doc(store,id):
  senseiHost = store.broker_host
  senseiPort = store.broker_port
  senseiClient = SenseiClient(senseiHost,senseiPort)
  req = SenseiRequest()
  sel = SenseiSelection("_uid")
  sel.addSelection(str(id))
  req.count = 1
  req.fetch_stored = True
  req.selections['_uid'] = sel
  res = senseiClient.doQuery(req)
  doc = None
  if res.numHits > 0:
    if res.hits and len(res.hits) > 0:
      hit = res.hits[0]
      doc = hit.get('srcdata')
  return doc
Esempio n. 7
0
sensei_client = SenseiClient(
    sysinfo={
        "lastmodified":
        0,
        "facets": [{
            "runtime": False,
            "name": "tags",
            "props": {
                "column": "tags",
                "depends": "[]",
                "type": "multi",
                "column_type": "string"
            }
        }, {
            "runtime": False,
            "name": "mileage",
            "props": {
                "column": "mileage",
                "range": "[*-12500, 12501-15000, 15001-17500, 17501-*]",
                "type": "range",
                "depends": "[]",
                "column_type": "int"
            }
        }, {
            "runtime": False,
            "name": "category",
            "props": {
                "column": "category",
                "depends": "[]",
                "type": "simple",
                "column_type": "string"
            }
        }, {
            "runtime": False,
            "name": "groupid",
            "props": {
                "column": "groupid",
                "depends": "[]",
                "type": "simple",
                "column_type": "long"
            }
        }, {
            "runtime": False,
            "name": "year",
            "props": {
                "column": "year",
                "range":
                "[1993-1994, 1995-1996, 1997-1998, 1999-2000, 2001-2002]",
                "type": "range",
                "depends": "[]",
                "column_type": "int"
            }
        }, {
            "runtime": False,
            "name": "city",
            "props": {
                "column": "city",
                "separator": "[/]",
                "depends": "[]",
                "type": "path",
                "column_type": "string"
            }
        }, {
            "runtime": False,
            "name": "price",
            "props": {
                "column": "price",
                "range":
                "[*,6700, 6800,9900, 10000,13100, 13200,17300, 17400,*]",
                "type": "range",
                "depends": "[]",
                "column_type": "float"
            }
        }, {
            "runtime": False,
            "name": "makemodel",
            "props": {
                "column": "makemodel",
                "depends": "[]",
                "type": "path",
                "column_type": "string"
            }
        }, {
            "runtime": False,
            "name": "color",
            "props": {
                "column": "color",
                "depends": "[]",
                "type": "simple",
                "column_type": "string"
            }
        }],
        "version":
        "4957216",
        "clusterinfo": [{
            "adminlink": "http://192.168.1.104:8080",
            "nodelink": "192.168.1.104:1234",
            "id": 1,
            "partitions": [0, 1]
        }],
        "numdocs":
        15000
    })