Example #1
0
class SearchApi(DashboardApi):
    def __init__(self, user, cluster):
        DashboardApi.__init__(self, user, cluster)
        self.api = SolrApi(SOLR_URL.get(), self.user)

    def query(self, collection, query, facet=None):
        if facet:
            collection['template']['rows'] = 0
            collection['facets'] = [facet]
        response = self.api.query(collection, query)
        return augment_solr_response(response, collection, query)

    def datasets(self, show_all=False):  # True if non Solr Cloud
        client = SolrClient(user=self.user)
        show_all = show_all or not client.is_solr_cloud_mode()
        return [
            index['name']
            for index in client.get_indexes(include_cores=show_all)
        ]

    def fields(self, collection):
        return self.api.fields(collection)

    def schema_fields(self, collection):
        return self.api.fields(collection)

    def luke(self, collection):
        return self.api.luke(collection)

    def stats(self, collection, field, query=None, facet=''):
        return self.api.stats(collection, field, query, facet)

    def get(self, collection, doc_id):
        return self.api.get(collection, doc_id)
Example #2
0
class SearchApi(DashboardApi):

  def __init__(self, user, cluster):
    DashboardApi.__init__(self, user, cluster)
    self.api = SolrApi(SOLR_URL.get(), self.user)

  def query(self, collection, query, facet=None):
    if facet:
      collection['template']['rows'] = 0
      collection['facets'] = [facet]
    response = self.api.query(collection, query)
    return augment_solr_response(response, collection, query)

  def datasets(self, show_all=False): # True if non Solr Cloud
    client = SolrClient(user=self.user)
    show_all = show_all or not client.is_solr_cloud_mode()
    return [index['name'] for index in client.get_indexes(include_cores=show_all)]

  def fields(self, collection):
    return self.api.fields(collection)

  def schema_fields(self, collection):
    return self.api.fields(collection)

  def luke(self, collection):
    return self.api.luke(collection)

  def stats(self, collection, field, query=None, facet=''):
    return self.api.stats(collection, field, query, facet)

  def get(self, collection, doc_id):
    return self.api.get(collection, doc_id)
Example #3
0
class SearchApi(DashboardApi):
    def __init__(self, user):
        DashboardApi.__init__(self, user)
        self.api = SolrApi(SOLR_URL.get(), self.user)

    def query(self, collection, query, facet=None):
        response = self.api.query(collection, query)
        return augment_solr_response(response, collection, query)

    def datasets(self, show_all=False):
        client = SolrClient(user=self.user)
        return [
            index['name']
            for index in client.get_indexes(include_cores=show_all)
        ]

    def fields(self, collection):
        return self.api.fields(collection)

    def schema_fields(self, collection):
        return self.api.fields(collection)

    def luke(self, collection):
        return self.api.luke(collection)

    def stats(self, collection, field, query=None, facet=''):
        return self.api.stats(collection, field, query, facet)

    def get(self, collection, doc_id):
        return self.api.get(collection, doc_id)
Example #4
0
class SearchApi(DashboardApi):

  def __init__(self, user):
    DashboardApi.__init__(self, user)
    self.api = SolrApi(SOLR_URL.get(), self.user)

  def query(self, collection, query, facet=None):
    response = self.api.query(collection, query)
    return augment_solr_response(response, collection, query)

  def datasets(self, show_all=False):
    return SearchController(self.user).get_all_indexes(show_all=show_all)

  def fields(self, collection):
    return self.api.fields(collection)

  def schema_fields(self, collection):
    return self.api.fields(collection)

  def luke(self, collection):
    return self.api.luke(collection)

  def stats(self, collection, field, query=None, facet=''):
    return self.api.stats(collection, field, query, facet)

  def get(self, collection, doc_id):
    return self.api.get(collection, doc_id)
Example #5
0
    def get_fields(self, collection_or_core_name):
        api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())

        try:
            field_data = api.fields(collection_or_core_name)
            fields = self._format_flags(field_data['schema']['fields'])
        except Exception as e:
            LOG.warn('/luke call did not succeed: %s' % e)
            try:
                fields = api.schema_fields(collection_or_core_name)
                fields = Collection2._make_luke_from_schema_fields(fields)
            except:
                LOG.exception(
                    _('Could not fetch fields for collection %s.') %
                    collection_or_core_name)
                raise PopupException(
                    _('Could not fetch fields for collection %s. See logs for more info.'
                      ) % collection_or_core_name)

        try:
            uniquekey = api.uniquekey(collection_or_core_name)
        except:
            LOG.exception(
                _('Could not fetch unique key for collection %s.') %
                collection_or_core_name)
            raise PopupException(
                _('Could not fetch unique key for collection %s. See logs for more info.'
                  ) % collection_or_core_name)

        return uniquekey, fields
Example #6
0
 def fields_data(self, user, name):
   api = SolrApi(SOLR_URL.get(), user)
   try:
     schema_fields = api.fields(name)
     schema_fields = schema_fields['schema']['fields']
   except Exception, e:
     LOG.warn('/luke call did not succeed: %s' % e)
     fields = api.schema_fields(name)
     schema_fields = Collection2._make_luke_from_schema_fields(fields)
Example #7
0
 def fields_data(self, user, name):
     api = SolrApi(SOLR_URL.get(), user)
     try:
         schema_fields = api.fields(name)
         schema_fields = schema_fields['schema']['fields']
     except Exception, e:
         LOG.warn('/luke call did not succeed: %s' % e)
         fields = api.schema_fields(name)
         schema_fields = Collection2._make_luke_from_schema_fields(fields)
Example #8
0
  def get_fields(self, collection_or_core_name):
    api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())

    try:
      field_data = api.fields(collection_or_core_name)
      fields = self._format_flags(field_data['schema']['fields'])
    except Exception, e:
      LOG.warn('/luke call did not succeed: %s' % e)
      try:
        fields = api.schema_fields(collection_or_core_name)
        fields = Collection2._make_luke_from_schema_fields(fields)
      except:
        LOG.exception(_('Could not fetch fields for collection %s.') % collection_or_core_name)
        raise PopupException(_('Could not fetch fields for collection %s. See logs for more info.') % collection_or_core_name)
Example #9
0
  def update_collection(self, name, fields):
    """
    Only create new fields
    """
    api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
    # Create only new fields
    # Fields that already exist, do not overwrite since there is no way to do that, currently.
    old_field_names = api.fields(name)['schema']['fields'].keys()
    new_fields = filter(lambda field: field['name'] not in old_field_names, fields)
    new_fields_filtered = []
    for field in new_fields:
      new_field = {}
      for attribute in filter(lambda attribute: attribute in field, ALLOWED_FIELD_ATTRIBUTES):
        new_field[attribute] = field[attribute]
      new_fields_filtered.append(new_field)

    api.add_fields(name, new_fields_filtered)
Example #10
0
  def update_collection(self, name, fields):
    """
    Only create new fields
    """
    api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
    # Create only new fields
    # Fields that already exist, do not overwrite since there is no way to do that, currently.
    old_field_names = api.fields(name)['schema']['fields'].keys()
    new_fields = filter(lambda field: field['name'] not in old_field_names, fields)
    new_fields_filtered = []
    for field in new_fields:
      new_field = {}
      for attribute in filter(lambda attribute: attribute in field, ALLOWED_FIELD_ATTRIBUTES):
        new_field[attribute] = field[attribute]
      new_fields_filtered.append(new_field)

    api.add_fields(name, new_fields_filtered)