def index(self, conn=None): """conn is Solr connection""" # tags = list(self.tags) description = [self.description or ''] if self.tags and self.tags != list(set(self.tags)): self.tags = list(set(self.tags)) self.save() doc = { 'id': unicode(self.id), 'res_id': unicode(self.id), 'res_type': settings.SOLR_ACCT, 'title': self.name, 'short_description': self.description, 'description': u'\n'.join(description), 'keywords': u', '.join(list(self.tags)), 'loc_labels': [] # [', '.join([loc.label, loc.place_name]) for loc in self.locations] } result = [] if self.locations: for i, loc in enumerate(self.locations): loc_doc = deepcopy(doc) loc_doc['id'] = u'%s_%s' % (unicode(self.id), i) loc_doc['pt_location'] = [lat_lon_to_str(loc)] loc_doc['loc_labels'] = [unicode(loc)] result.append(loc_doc) else: result = [doc] if conn: conn.add(result) return result
def index(self, conn=None): """conn is Solr connection""" if self.status == STATUS_BAD: return None tags = [] accounts = [] collections = [] description = [self.description] for obj in self.curations: tags.extend(obj.tags) accounts.append(unicode(obj.owner.id)) if hasattr(obj.owner, 'in_collections'): collections.extend(obj.owner.in_collections) description.extend([obj.note or u'', unicode(obj.data) or u'']) if obj.owner == self.owner: if self.tags != obj.tags: self.tags = obj.tags self.save() doc = { 'id': unicode(self.id), 'res_id': unicode(self.id), 'res_type': settings.SOLR_RES, 'title': self.title, 'short_description': self.description, 'description': u'\n'.join(description), 'keywords': u', '.join(list(set(tags))), 'accounts': u', '.join(accounts), 'collections': u', '.join(set([str(c.id) for c in collections])), 'uri': self.uri, 'loc_labels': [ ] # [', '.join([loc.label, loc.place_name]) for loc in self.locations] } if self.calendar_event: doc['event_start'] = self.calendar_event.start #.date() if self.calendar_event.end: doc['event_end'] = self.calendar_event.end #.date() result = [] if self.locations: for i, loc in enumerate(self.locations): loc_doc = deepcopy(doc) loc_doc['id'] = u'%s_%s' % (unicode(self.id), i) loc_doc['pt_location'] = [lat_lon_to_str(loc)] loc_doc['loc_labels'] = [unicode(loc)] result.append(loc_doc) else: result = [doc] if conn: conn.add(result) return result
def index(self, conn=None): """conn is Solr connection""" if self.status == STATUS_BAD: return None tags = [] accounts = [] collections = [] description = [self.description] for obj in self.curations: tags.extend(obj.tags) accounts.append(unicode(obj.owner.id)) if hasattr(obj.owner, "in_collections"): collections.extend(obj.owner.in_collections) description.extend([obj.note or u"", unicode(obj.data) or u""]) if obj.owner == self.owner: if self.tags != obj.tags: self.tags = obj.tags self.save() doc = { "id": unicode(self.id), "res_id": unicode(self.id), "res_type": settings.SOLR_RES, "title": self.title, "short_description": self.description, "description": u"\n".join(description), "keywords": u", ".join(list(set(tags))), "accounts": u", ".join(accounts), "collections": u", ".join(set([str(c.id) for c in collections])), "uri": self.uri, "loc_labels": [], # [', '.join([loc.label, loc.place_name]) for loc in self.locations] } if self.calendar_event: doc["event_start"] = self.calendar_event.start # .date() if self.calendar_event.end: doc["event_end"] = self.calendar_event.end # .date() result = [] if self.locations: for i, loc in enumerate(self.locations): loc_doc = deepcopy(doc) loc_doc["id"] = u"%s_%s" % (unicode(self.id), i) loc_doc["pt_location"] = [lat_lon_to_str(loc)] loc_doc["loc_labels"] = [unicode(loc)] result.append(loc_doc) else: result = [doc] if conn: conn.add(result) return result
def find_by_place(name, kwords, loc_boost=None, start=0, max=None, accounts=None, collections=None, event=None, res_type=settings.SOLR_RES): loc = get_or_create_location(name) if loc: kw = { 'start': start, 'rows': minmax(0, settings.SOLR_ROWS, max, settings.SOLR_ROWS), 'fl': '*,score', # 'fq': 'accounts:(4d9c3ced89cb162e5e000000 OR 4d9b99d889cb16665c000000) ', 'qt': 'resources', 'sfield': 'pt_location', 'pt': lat_lon_to_str(loc['lat_lon']), 'bf': 'recip(geodist(),2,200,20)^%s' % (loc_boost or settings.SOLR_LOC_BOOST_DEFAULT), 'sort': 'score desc', } fq = _make_fq(event, accounts, collections, res_type) if fq: kw['fq'] = fq conn = Solr(settings.SOLR_URL) return loc, conn.search(kwords.strip() if kwords else '', **kw) else: return None, None