|
|
@@ -25,15 +25,12 @@ from itertools import groupby
|
|
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
+from dashboard.facet_builder import _compute_range_facet
|
|
|
from desktop.lib.exceptions_renderable import PopupException
|
|
|
from desktop.conf import SERVER_USER
|
|
|
-from desktop.lib.conf import BoundConfig
|
|
|
from desktop.lib.i18n import force_unicode
|
|
|
from desktop.lib.rest.http_client import HttpClient, RestException
|
|
|
from desktop.lib.rest import resource
|
|
|
-from dashboard.facet_builder import _compute_range_facet
|
|
|
-
|
|
|
-from search.conf import EMPTY_QUERY, SECURITY_ENABLED, SOLR_URL
|
|
|
|
|
|
from libsolr.conf import SSL_CERT_CA_VERIFY
|
|
|
|
|
|
@@ -41,24 +38,25 @@ from libsolr.conf import SSL_CERT_CA_VERIFY
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
+try:
|
|
|
+ from search.conf import EMPTY_QUERY, SECURITY_ENABLED, SOLR_URL
|
|
|
+except ImportError, e:
|
|
|
+ LOG.warn('Solr Search is not enabled')
|
|
|
+
|
|
|
+
|
|
|
def utf_quoter(what):
|
|
|
return urllib.quote(unicode(what).encode('utf-8'), safe='~@#$&()*!+=;,.?/\'')
|
|
|
|
|
|
-def search_enabled():
|
|
|
- return type(SECURITY_ENABLED) == BoundConfig
|
|
|
-
|
|
|
|
|
|
class SolrApi(object):
|
|
|
"""
|
|
|
http://wiki.apache.org/solr/CoreAdmin#CoreAdminHandler
|
|
|
"""
|
|
|
- def __init__(self, solr_url=SOLR_URL.get(), user=None,
|
|
|
- security_enabled=SECURITY_ENABLED.get() if search_enabled() else SECURITY_ENABLED.default,
|
|
|
- ssl_cert_ca_verify=SSL_CERT_CA_VERIFY.get()):
|
|
|
+ def __init__(self, solr_url=SOLR_URL.get(), user=None, security_enabled=False, ssl_cert_ca_verify=SSL_CERT_CA_VERIFY.get()):
|
|
|
self._url = solr_url
|
|
|
self._user = user
|
|
|
self._client = HttpClient(self._url, logger=LOG)
|
|
|
- self.security_enabled = security_enabled
|
|
|
+ self.security_enabled = security_enabled or SECURITY_ENABLED.get()
|
|
|
|
|
|
if self.security_enabled:
|
|
|
self._client.set_kerberos_auth()
|
|
|
@@ -367,6 +365,7 @@ class SolrApi(object):
|
|
|
except Exception, e:
|
|
|
raise PopupException(e, title=_('Error while accessing Solr'))
|
|
|
|
|
|
+ # Deprecated
|
|
|
def create_collection(self, name, shards=1, replication=1):
|
|
|
try:
|
|
|
params = self._get_params() + (
|
|
|
@@ -387,6 +386,44 @@ class SolrApi(object):
|
|
|
except RestException, e:
|
|
|
raise PopupException(e, title=_('Error while accessing Solr'))
|
|
|
|
|
|
+
|
|
|
+ def create_collection2(self, name, config_name=None, shards=1, replication=1, **kwargs):
|
|
|
+ try:
|
|
|
+ params = self._get_params() + (
|
|
|
+ ('action', 'CREATE'),
|
|
|
+ ('name', name),
|
|
|
+ ('numShards', shards),
|
|
|
+ ('replicationFactor', replication),
|
|
|
+ ('wt', 'json')
|
|
|
+ )
|
|
|
+ if config_name:
|
|
|
+ params += (
|
|
|
+ ('collection.configName', config_name),
|
|
|
+ )
|
|
|
+ if kwargs:
|
|
|
+ params += ((key, val) for key, val in kwargs.iteritems())
|
|
|
+
|
|
|
+
|
|
|
+ response = self._root.post('admin/collections', params=params, contenttype='application/json')
|
|
|
+ return self._get_json(response)
|
|
|
+ except RestException, e:
|
|
|
+ raise PopupException(e, title=_('Error while accessing Solr'))
|
|
|
+
|
|
|
+
|
|
|
+ def add_fields(self, name, fields):
|
|
|
+ try:
|
|
|
+ params = self._get_params() + (
|
|
|
+ ('wt', 'json')
|
|
|
+ )
|
|
|
+
|
|
|
+ data = {'add-field': fields}
|
|
|
+
|
|
|
+ response = self._root.post('%(collection)s/schema' % name, params=params, data=json.dumps(data), contenttype='application/json')
|
|
|
+ return self._get_json(response)
|
|
|
+ except RestException, e:
|
|
|
+ raise PopupException(e, title=_('Error while accessing Solr'))
|
|
|
+
|
|
|
+
|
|
|
def create_core(self, name, instance_dir, shards=1, replication=1):
|
|
|
try:
|
|
|
params = self._get_params() + (
|
|
|
@@ -812,6 +849,7 @@ class SolrApi(object):
|
|
|
response = json.loads(response.replace('\x00', ''))
|
|
|
return response
|
|
|
|
|
|
+
|
|
|
def uniquekey(self, collection):
|
|
|
try:
|
|
|
params = self._get_params() + (
|