Esempio n. 1
0
 def query(self, **kwargs):
     data = solr().raw_query(q=self.q or '*:*',
                             wt='json',
                             sort='score desc, name desc',
                             fq=self.fq,
                             facet='true',
                             facet_field=[f + '.s' for f in self.facets],
                             facet_limit=100,
                             rows=self.limit,
                             start=self.offset)
     return json.loads(data)
Esempio n. 2
0
def index():
    solr_ = solr()
    buf = []
    for i, org in enumerate(model.db.session.query(model.Entity)):
        data = flatten(org.as_dict())
        #pprint(data)
        for k, v in data.items():
            #data[k + '.n'] = v
            if isinstance(v, datetime):
                data[k] = datetime_add_tz(v)
            else:
                data[k + '.s'] = v
        data['id'] = org.id
        buf.append(data)
        if i and i % 50 == 0:
            print "%s ... " % i
            solr_.add_many(buf)
            solr_.commit()
            buf = []
    solr_.add_many(buf)
    solr_.commit()
    solr_.optimize()
Esempio n. 3
0
def index():
    solr_ = solr()
    buf = []
    for i, org in enumerate(model.db.session.query(model.Entity)):
        data = flatten(org.as_dict())
        #pprint(data)
        for k, v in data.items():
            #data[k + '.n'] = v
            if isinstance(v, datetime):
                data[k] = datetime_add_tz(v)
            else:
                data[k + '.s'] = v
        data['id'] = org.id
        buf.append(data)
        if i and i % 50 == 0:
            print "%s ... " % i
            solr_.add_many(buf)
            solr_.commit()
            buf = []
    solr_.add_many(buf)
    solr_.commit()
    solr_.optimize()