def delete_doc(sender, **kwargs): idmodel = (kwargs['instance']) try: solr_conf = settings.CID['solr'] solr = Solr(solr_conf['addr']) collection = solr.get_collection(solr_conf['collection']) collection.delete([idmodel.id]) collection.commit() except SolrError as e: raise e
def update_doc(sender, **kwargs): idmodel = (kwargs['instance']) doc = important_date_to_index_doc(idmodel) try: solr_conf = settings.CID['solr'] solr = Solr(solr_conf['addr']) collection = solr.get_collection(solr_conf['collection']) collection.add([doc]) collection.commit() except SolrError as e: raise e
def search(query, fields=None, faset_params=None, hl=None, sort=None, start=0, rows=10): if sort is None: sort = [] if hl is None: hl = [] if fields is None: fields = ['id'] solr_conf = settings.CID['solr'] solr = Solr(solr_conf['addr']) collection = solr.get_collection(solr_conf['collection']) result = collection.search(query, fields, faset_params, hl, sort, start, rows) return result
def index_important_dates(): solr_conf = settings.CID['solr'] solr = Solr(solr_conf['addr']) collection = solr.get_collection(solr_conf['collection']) docs = [] for idmodel in ImportantDate.objects.all().iterator(): doc = important_date_to_index_doc(idmodel) docs.append(doc) if len(docs) > 10: collection.add(docs) docs = [] if docs: collection.add(docs) collection.commit()
def update_doc(sender, **kwargs): idmodel = (kwargs['instance']) types = [] for type in idmodel.type.all(): types.append(type.get_variant_display()) doc = { 'id': idmodel.id, } if types: doc['type_s'] = types if idmodel.fio: doc['fio_t'] = idmodel.fio if idmodel.org_title: doc['org_title_t'] = idmodel.org_title if idmodel.org_title: doc['event_title_t'] = idmodel.event_title if idmodel.geo_title: doc['geo_title_t'] = idmodel.geo_title if idmodel.theme: doc['theme_t'] = idmodel.theme if idmodel.description: doc['description_t'] = strip_tags(idmodel.description) if idmodel.literature: doc['literature_t'] = strip_tags(idmodel.literature) try: solr_conf = settings.CID['solr'] solr = Solr(solr_conf['addr']) collection = solr.get_collection(solr_conf['collection']) collection.add([doc]) collection.commit() except SolrError as e: raise e
def index(request): year = request.GET.get('year', None) month = request.GET.get('month', None) day = request.GET.get('day', None) theme = request.GET.get('theme', None) type = request.GET.get('type', None) events = [] errors = [] limit_on_page = 15 prnt = request.GET.get('print', None) if prnt: limit_on_page = 1000 attr = request.GET.get('attr', None) search=False q = request.GET.get('q', None) y = request.GET.get('y', None) events_page = None if attr and q: attrs, values = extract_request_query_attrs(request) query = construct_query(attrs=attrs, values=values) solr_conf = settings.CID['solr'] solr = Solr(solr_conf['addr']) collection = solr.get_collection(solr_conf['collection']) result = collection.search(query, ['id']) paginator = Paginator(result, limit_on_page) page = request.GET.get('page') try: events_page = paginator.page(page) except PageNotAnInteger: events_page = paginator.page(1) except EmptyPage: events_page = paginator.page(paginator.num_pages) docs = result.get_docs() ids = [] for doc in docs: ids.append(doc['id']) events = get_records(ids) events_page.object_list = events search = True #events_page = result if y: events_page = None events = ImportantDate.get_ids_by_year(year=y) if not search and not y: q = Q() try: if year: errors += int_validator(year, u'Год') errors += max_validator(int(year), 9999, u'Год') errors += min_validator(int(year), 1, u'Год') q = q & Q(date__year=year) if month: errors += int_validator(month, u'Месяц') errors += max_validator(int(month), 12, u'Месяц') errors += min_validator(int(month), 1, u'Месяц') q = q & Q(date__month=month) if day: errors += int_validator(day, u'День') errors += max_validator(int(day), 31, u'День') errors += min_validator(int(day), 1, u'День') q = q & Q(date__day=day) if theme: errors += int_validator(theme, u'Тема') q = q & Q(theme_id=int(theme)) if type: errors += int_validator(type, u'Тип') q = q & Q(type__id=int(type)) except ValueError as e: pass if not errors: events_page = get_page(request, ImportantDate.objects.filter(q).order_by('date'), limit_on_page) events = events_page.object_list now = datetime.datetime.now() #themes = Theme.objects.all() types = Type.objects.all() template = 'cid/frontend/index.html' if prnt: template = 'cid/frontend/print.html' return render(request, template, { 'now': now, 'events': events, 'events_page': events_page, #'themes': themes, 'types': types, 'errors': errors })