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)
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()