Exemple #1
0
def design_schema(request, index):
    if request.method == 'POST':
        pass  # TODO: Support POST for update?

    result = {'status': -1, 'message': ''}

    try:
        searcher = IndexController(request.user)
        unique_key, fields = searcher.get_index_schema(index)

        result['status'] = 0
        formatted_fields = []
        for field in fields:
            formatted_fields.append({
                'name':
                field,
                'type':
                fields[field]['type'],
                'required':
                fields[field].get('required', None),
                'indexed':
                fields[field].get('indexed', None),
                'stored':
                fields[field].get('stored', None),
                'multivalued':
                fields[field].get('multivalued', None),
            })
        result['fields'] = formatted_fields
        result['unique_key'] = unique_key
    except Exception, e:
        result['message'] = _('Could not get index schema: %s') % e
Exemple #2
0
def delete_indexes(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

  indexes = json.loads(request.POST.get('indexes', '[]'))

  if not indexes:
    response['message'] = _('No indexes to remove.')
  else:
    searcher = IndexController(request.user)

    for index in indexes:
      if index['type'] == 'collection':
        searcher.delete_collection(index['name'])
      elif index['type'] == 'alias':
        searcher.delete_alias(index['name'])
      else:
        LOG.warn('We could not delete: %s' % index)

    response['status'] = 0
    response['message'] = _('Indexes removed!')

  return JsonResponse(response)
Exemple #3
0
def design_schema(request, index):
  if request.method == 'POST':
    pass # TODO: Support POST for update?

  result = {'status': -1, 'message': ''}

  try:
    searcher = IndexController(request.user)
    unique_key, fields = searcher.get_index_schema(index)

    result['status'] = 0
    formatted_fields = []
    for field in fields:
      formatted_fields.append({
        'name': field,
        'type': fields[field]['type'],
        'required': fields[field].get('required', None),
        'indexed': fields[field].get('indexed', None),
        'stored': fields[field].get('stored', None),
        'multivalued': fields[field].get('multivalued', None),
      })
    result['fields'] = formatted_fields
    result['unique_key'] = unique_key
  except Exception, e:
    result['message'] = _('Could not get index schema: %s') % e
Exemple #4
0
def indexer(request):
    if not request.user.has_hue_permission(action="access", app='search'):
        raise PopupException(_('Missing permission.'), error_code=403)

    searcher = IndexController(request.user)
    indexes = searcher.get_indexes()

    for index in indexes:
        index['isSelected'] = False

    return render(
        'indexer.mako', request, {
            'is_embeddable':
            request.GET.get('is_embeddable', False),
            'indexes_json':
            json.dumps(indexes),
            'fields_json':
            json.dumps([field.name for field in FIELD_TYPES]),
            'operators_json':
            json.dumps([operator.to_dict() for operator in OPERATORS]),
            'file_types_json':
            json.dumps([
                format_.format_info()
                for format_ in get_file_indexable_format_types()
            ]),
            'default_field_type':
            json.dumps(Field().to_dict())
        })
Exemple #5
0
def indexes(request):
    searcher = IndexController(request.user)
    indexes = searcher.get_indexes()

    for index in indexes:
        index['isSelected'] = False

    return render('indexes.mako', request,
                  {'indexes_json': json.dumps(indexes)})
Exemple #6
0
def indexes(request):
  searcher = IndexController(request.user)
  indexes = searcher.get_indexes()

  for index in indexes:
    index['isSelected'] = False

  return render('indexes.mako', request, {
      'indexes_json': json.dumps(indexes)
  })
Exemple #7
0
def indexes(request):
    if not request.user.has_hue_permission(action="access", app='search'):
        raise PopupException(_('Missing permission.'), error_code=403)

    searcher = IndexController(request.user)
    indexes = searcher.get_indexes()

    for index in indexes:
        index['isSelected'] = False

    return render('indexes.mako', request,
                  {'indexes_json': json.dumps(indexes)})
Exemple #8
0
def indexer(request):
  searcher = IndexController(request.user)
  indexes = searcher.get_indexes()

  for index in indexes:
    index['isSelected'] = False

  return render('indexer.mako', request, {
      'indexes_json': json.dumps(indexes),
      'fields_json' : json.dumps([field.name for field in Field.TYPES]),
      'operators_json' : json.dumps([operator.to_dict() for operator in Field.OPERATORS])
  })
Exemple #9
0
def indexer(request):
  searcher = IndexController(request.user)
  indexes = searcher.get_indexes()

  for index in indexes:
    index['isSelected'] = False

  return render('indexer.mako', request, {
      'indexes_json': json.dumps(indexes),
      'fields_json' : json.dumps([field.name for field in FIELD_TYPES]),
      'operators_json' : json.dumps([operator.to_dict() for operator in OPERATORS]),
      'file_types_json' : json.dumps([format_.format_info() for format_ in get_format_types()]),
      'default_field_type' : json.dumps(Field().to_dict())
  })
Exemple #10
0
def indexer(request):
    searcher = IndexController(request.user)
    indexes = searcher.get_indexes()

    for index in indexes:
        index['isSelected'] = False

    return render(
        'indexer.mako', request, {
            'indexes_json':
            json.dumps(indexes),
            'fields_json':
            json.dumps([field.name for field in FIELD_TYPES]),
            'operators_json':
            json.dumps([operator.to_dict() for operator in OPERATORS]),
            'file_types_json':
            json.dumps(
                [format_.format_info() for format_ in get_format_types()]),
            'default_field_type':
            json.dumps(Field().to_dict())
        })
Exemple #11
0
def delete_indexes(request):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    response = {'status': -1}

    indexes = json.loads(request.POST.get('indexes', '[]'))

    if not indexes:
        response['message'] = _('No indexes to remove.')
    else:
        searcher = IndexController(request.user)

        for index in indexes:
            if index['type'] == 'collection':
                searcher.delete_index(index['name'])
            elif index['type'] == 'alias':
                searcher.delete_alias(index['name'])
            else:
                LOG.warn('We could not delete: %s' % index)

        response['status'] = 0
        response['message'] = _('Indexes removed!')

    return JsonResponse(response)
Exemple #12
0
def create_index(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

  name = request.POST.get('name')

  if name:
    searcher = IndexController(request.user)

    try:
      collection = searcher.create_index(name,
                                         request.POST.get('fields', get_default_fields()),
                                         request.POST.get('uniqueKeyField', 'id'),
                                         request.POST.get('df', 'text'))

      response['status'] = 0
      response['collection'] = collection
      response['message'] = _('Index created!')
    except Exception, e:
      response['message'] = _('Index could not be created: %s') % e
Exemple #13
0
def create_index(request):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    response = {'status': -1}

    name = request.POST.get('name')

    if name:
        searcher = IndexController(request.user)

        try:
            collection = searcher.create_index(
                name, request.POST.get('fields', get_default_fields()),
                request.POST.get('uniqueKeyField', 'id'),
                request.POST.get('df', 'text'))

            response['status'] = 0
            response['collection'] = collection
            response['message'] = _('Index created!')
        except Exception, e:
            response['message'] = _('Index could not be created: %s') % e