本文整理汇总了Python中search.conf.SOLR_URL类的典型用法代码示例。如果您正苦于以下问题:Python SOLR_URL类的具体用法?Python SOLR_URL怎么用?Python SOLR_URL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SOLR_URL类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: admin_collection_template
def admin_collection_template(request, collection_id):
hue_collection = Collection.objects.get(id=collection_id)
solr_collection = SolrApi(SOLR_URL.get(), request.user).collection_or_core(hue_collection)
sample_data = {}
if request.method == 'POST':
hue_collection.result.update_from_post(request.POST)
hue_collection.result.save()
return HttpResponse(json.dumps({}), mimetype="application/json")
solr_query = {}
solr_query['collection'] = hue_collection.name
solr_query['q'] = ''
solr_query['fq'] = ''
solr_query['rows'] = 5
solr_query['start'] = 0
solr_query['facets'] = 0
try:
response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)
sample_data = json.dumps(response["response"]["docs"])
except PopupException, e:
message = e
try:
message = json.loads(e.message.message)['error']['msg'] # Try to get the core error
except:
pass
request.error(_('No preview available, some facets are invalid: %s') % message)
LOG.exception(e)
开发者ID:2013Commons,项目名称:hue,代码行数:29,代码来源:views.py
示例2: create_collection
def create_collection(self, name, fields, unique_key_field='id', df='text'):
"""
Create solr collection or core and instance dir.
Create schema.xml file so that we can set UniqueKey field.
"""
if self.is_solr_cloud_mode():
# solrcloud mode
# Need to remove path afterwards
tmp_path, solr_config_path = utils.copy_configs(fields, unique_key_field, df, True)
# Create instance directory.
solrctl_path = get_solrctl_path()
process = subprocess.Popen([solrctl_path, "instancedir", "--create", name, solr_config_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
})
status = process.wait()
# Don't want directories laying around
shutil.rmtree(tmp_path)
if status != 0:
LOG.error("Could not create instance directory.\nOutput: %s\nError: %s" % process.communicate())
raise PopupException(_('Could not create instance directory. '
'Check if solr_zk_ensemble and solrctl_path are correct in Hue config [indexer].'))
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_collection(name):
# Delete instance directory if we couldn't create a collection.
process = subprocess.Popen([solrctl_path, "instancedir", "--delete", name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
})
if process.wait() != 0:
LOG.error("Cloud not delete collection.\nOutput: %s\nError: %s" % process.communicate())
raise PopupException(_('Could not create collection. Check error logs for more info.'))
else:
# Non-solrcloud mode
# Create instance directory locally.
instancedir = os.path.join(conf.CORE_INSTANCE_DIR.get(), name)
if os.path.exists(instancedir):
raise PopupException(_("Instance directory %s already exists! Please remove it from the file system.") % instancedir)
tmp_path, solr_config_path = utils.copy_configs(fields, unique_key_field, df, False)
shutil.move(solr_config_path, instancedir)
shutil.rmtree(tmp_path)
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_core(name, instancedir):
# Delete instance directory if we couldn't create a collection.
shutil.rmtree(instancedir)
raise PopupException(_('Could not create collection. Check error logs for more info.'))
开发者ID:Lt-Pone,项目名称:hue,代码行数:57,代码来源:controller.py
示例3: fields_data
def fields_data(self, user):
schema_fields = SolrApi(SOLR_URL.get(), user).fields(self.name)
schema_fields = schema_fields['schema']['fields']
dynamic_fields = SolrApi(SOLR_URL.get(), user).fields(self.name, dynamic=True)
dynamic_fields = dynamic_fields['fields']
schema_fields.update(dynamic_fields)
return sorted([{'name': str(field), 'type': str(attributes.get('type', ''))}
for field, attributes in schema_fields.iteritems()])
开发者ID:jessica9421,项目名称:hue,代码行数:11,代码来源:models.py
示例4: get_fields
def get_fields(self, collection_or_core_name):
try:
field_data = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()).fields(collection_or_core_name)
fields = self._format_flags(field_data['schema']['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 = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()).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
开发者ID:zhxing,项目名称:hue,代码行数:15,代码来源:controller.py
示例5: get_terms
def get_terms(request):
result = {'status': -1, 'message': 'Error'}
try:
collection = json.loads(request.POST.get('collection', '{}'))
analysis = json.loads(request.POST.get('analysis', '{}'))
field = analysis['name']
properties = {
'terms.limit': 25,
'terms.prefix': analysis['terms']['prefix']
# lower
# limit
# mincount
# maxcount
}
result['terms'] = SolrApi(SOLR_URL.get(), request.user).terms(collection['name'], field, properties)
result['terms'] = pairwise2(field, [], result['terms']['terms'][field])
result['status'] = 0
result['message'] = ''
except Exception, e:
result['message'] = force_unicode(e)
if 'not currently supported' in result['message']:
result['status'] = 1
result['message'] = _('This field does not support stats')
开发者ID:QLGu,项目名称:hue,代码行数:27,代码来源:views.py
示例6: get_terms
def get_terms(request):
result = {"status": -1, "message": "Error"}
try:
collection = json.loads(request.POST.get("collection", "{}"))
analysis = json.loads(request.POST.get("analysis", "{}"))
field = analysis["name"]
properties = {
"terms.limit": 25,
"terms.prefix": analysis["terms"]["prefix"]
# lower
# limit
# mincount
# maxcount
}
result["terms"] = SolrApi(SOLR_URL.get(), request.user).terms(collection["name"], field, properties)
result["terms"] = pairwise2(field, [], result["terms"]["terms"][field])
result["status"] = 0
result["message"] = ""
except Exception, e:
result["message"] = force_unicode(e)
if "not currently supported" in result["message"]:
result["status"] = 1
result["message"] = _("This field does not support stats")
开发者ID:cloudera,项目名称:hue,代码行数:27,代码来源:views.py
示例7: index
def index(request):
hue_collections = Collection.objects.filter(enabled=True)
if not hue_collections:
if request.user.is_superuser:
return admin_collections(request, True)
else:
return no_collections(request)
initial_collection = request.COOKIES.get('hueSearchLastCollection', 0)
search_form = QueryForm(request.GET, initial_collection=initial_collection)
response = {}
error = {}
solr_query = {}
hue_collection = None
if search_form.is_valid():
collection_id = search_form.cleaned_data['collection']
solr_query['q'] = search_form.cleaned_data['query'].encode('utf8')
solr_query['fq'] = search_form.cleaned_data['fq']
if search_form.cleaned_data['sort']:
solr_query['sort'] = search_form.cleaned_data['sort']
solr_query['rows'] = search_form.cleaned_data['rows'] or 15
solr_query['start'] = search_form.cleaned_data['start'] or 0
solr_query['facets'] = search_form.cleaned_data['facets'] or 1
try:
hue_collection = Collection.objects.get(id=collection_id)
solr_query['collection'] = hue_collection.name
response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)
except Exception, e:
error['message'] = unicode(str(e), "utf8")
开发者ID:cmriadmin,项目名称:hue,代码行数:32,代码来源:views.py
示例8: index
def index(request):
hue_collections = Collection.objects.filter(enabled=True)
if not hue_collections:
if request.user.is_superuser:
return admin_collections(request, True)
else:
return no_collections(request)
init_collection = initial_collection(request, hue_collections)
search_form = QueryForm(request.GET, initial_collection=init_collection)
response = {}
error = {}
solr_query = {}
if search_form.is_valid():
try:
collection_id = search_form.cleaned_data['collection']
hue_collection = Collection.objects.get(id=collection_id)
solr_query = search_form.solr_query_dict
response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)
solr_query['total_pages'] = int(math.ceil((float(response['response']['numFound']) / float(solr_query['rows']))))
solr_query['search_time'] = response['responseHeader']['QTime']
except Exception, e:
error['title'] = force_unicode(e.title) if hasattr(e, 'title') else ''
error['message'] = force_unicode(str(e))
开发者ID:bag-of-projects,项目名称:hue,代码行数:29,代码来源:views.py
示例9: get_all_indexes
def get_all_indexes(self):
indexes = []
try:
indexes = self.get_solr_collection().keys()
except:
pass
return indexes + SolrApi(SOLR_URL.get(), self.user).cores().keys()
开发者ID:15580056814,项目名称:hue,代码行数:7,代码来源:search_controller.py
示例10: create_collection
def create_collection(self, name, fields, unique_key_field='id', df='text'):
"""
Create solr collection or core and instance dir.
Create schema.xml file so that we can set UniqueKey field.
"""
if self.is_solr_cloud_mode():
# solrcloud mode
# Need to remove path afterwards
tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True)
zc = ZookeeperClient(hosts=get_solr_ensemble(), read_only=False)
root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
config_root_path = '%s/%s' % (solr_config_path, 'conf')
try:
zc.copy_path(root_node, config_root_path)
except Exception, e:
zc.delete_path(root_node)
raise PopupException(_('Error in copying Solr configurations.'), detail=e)
# Don't want directories laying around
shutil.rmtree(tmp_path)
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_collection(name):
# Delete instance directory if we couldn't create a collection.
try:
zc.delete_path(root_node)
except Exception, e:
raise PopupException(_('Error in deleting Solr configurations.'), detail=e)
开发者ID:renxiawang,项目名称:hue,代码行数:30,代码来源:controller.py
示例11: _fetch_collections
def _fetch_collections(request):
from libsolr.api import SolrApi
from search.conf import SOLR_URL
path = request.GET['path']
item = None
name = None
if path:
item = path
if '/' in path:
item, name = path.split('/')
api = SolrApi(SOLR_URL.get(), request.user)
if not item:
return {"databases": ["collections", "configs", "admin"]}
elif item and name:
return {"authorizable_link": "/indexer/#edit/%s" % name, "extended_columns": [], "columns": [], "partition_keys": []}
elif item == 'collections':
return {"tables_meta": [{"comment": None, "type": "Table", "name": col} for col in api.collections2()]}
elif item == 'configs':
return {"tables_meta": [{"comment": None, "type": "Table", "name": conf} for conf in api.configs()]}
elif item == 'admin':
return {"tables_meta": [{"comment": None, "type": "Table", "name": 'collections'}, {"comment": None, "type": "Table", "name": "cores"}]}
else:
raise PopupException(_('Authorizable %s could not be retrieved') % path)
开发者ID:cloudera,项目名称:hue,代码行数:27,代码来源:sentry.py
示例12: test_query
def test_query(self):
collection = Collection2(user=self.user, name='log_analytics_demo')
collection = json.loads(collection.get_json(self.user))
query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
SolrApi(SOLR_URL.get(), self.user).query(collection['collection'], query)
开发者ID:277800076,项目名称:hue,代码行数:7,代码来源:tests.py
示例13: update_document
def update_document(request):
result = {'status': -1, 'message': 'Error'}
if not can_edit_index(request.user):
result['message'] = _('Permission to edit the document denied')
return JsonResponse(result)
try:
collection = json.loads(request.POST.get('collection', '{}'))
document = json.loads(request.POST.get('document', '{}'))
doc_id = request.POST.get('id')
if document['hasChanged']:
edits = {
"id": doc_id,
}
version = None # If there is a version, use it to avoid potential concurrent update conflicts
for field in document['details']:
if field['hasChanged']:
edits[field['key']] = {"set": field['value']}
if field['key'] == '_version_':
version = field['value']
if SolrApi(SOLR_URL.get(), request.user).update(collection['name'], json.dumps([edits]), content_type='json', version=version):
result['status'] = 0
result['message'] = _('Document successfully updated.')
else:
result['status'] = 0
result['message'] = _('Document has no modifications to change.')
except Exception, e:
result['message'] = force_unicode(e)
开发者ID:qccash,项目名称:hue,代码行数:33,代码来源:views.py
示例14: get_all_indexes
def get_all_indexes(self, show_all=False):
indexes = []
try:
indexes = self.get_solr_collections().keys()
except:
LOG.exception('failed to get indexes')
try:
indexes += SolrApi(SOLR_URL.get(), self.user).aliases().keys()
except:
LOG.exception('failed to get index aliases')
if show_all or not indexes:
return indexes + SolrApi(SOLR_URL.get(), self.user).cores().keys()
else:
return indexes
开发者ID:18600597055,项目名称:hue,代码行数:16,代码来源:search_controller.py
示例15: get_all_indexes
def get_all_indexes(self, show_all=False):
indexes = []
try:
indexes = self.get_solr_collection().keys()
except:
pass
try:
indexes += SolrApi(SOLR_URL.get(), self.user).aliases().keys()
except:
pass
if show_all or not indexes:
return indexes + SolrApi(SOLR_URL.get(), self.user).cores().keys()
else:
return indexes
开发者ID:alei76,项目名称:hue,代码行数:16,代码来源:search_controller.py
示例16: _create_facet
def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_type):
properties = {
'sort': 'desc',
'canRange': False,
'stacked': False,
'limit': 10,
'mincount': 0,
'isDate': False,
'andUp': False, # Not used yet
}
solr_api = SolrApi(SOLR_URL.get(), user)
range_properties = _new_range_facet(solr_api, collection, facet_field, widget_type)
if range_properties:
facet_type = 'range'
properties.update(range_properties)
elif widget_type == 'hit-widget':
facet_type = 'query'
else:
facet_type = 'field'
if widget_type == 'map-widget':
properties['scope'] = 'world'
properties['mincount'] = 1
properties['limit'] = 100
return {
'id': facet_id,
'label': facet_label,
'field': facet_field,
'type': facet_type,
'widgetType': widget_type,
'properties': properties
}
开发者ID:Altiscale,项目名称:hue,代码行数:35,代码来源:views.py
示例17: zkensemble
def zkensemble():
"""
ZooKeeper Ensemble
"""
from search.conf import SOLR_URL
parsed = urlparse(SOLR_URL.get())
return "%s:2181/solr" % (parsed.hostname or 'localhost')
开发者ID:Ile2,项目名称:hue,代码行数:7,代码来源:conf.py
示例18: zkensemble
def zkensemble():
"""
Try to guess the value if no values are specified.
"""
from django.conf import settings
if 'zookeeper' in settings.INSTALLED_APPS:
try:
# Backward compatibility until Hue 4
from zookeeper.conf import CLUSTERS
clusters = CLUSTERS.get()
if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
return '%s' % clusters['default'].HOST_PORTS.get()
except:
LOG.warn('Could not get zookeeper ensemble from the zookeeper app')
if 'search' in settings.INSTALLED_APPS:
try:
from search.conf import SOLR_URL
parsed = urlparse(SOLR_URL.get())
return "%s:2181" % (parsed.hostname or 'localhost')
except:
LOG.warn('Could not get zookeeper ensemble from the search app')
return "localhost:2181"
开发者ID:orenmazor,项目名称:hue,代码行数:26,代码来源:conf.py
示例19: admin_collection_schema
def admin_collection_schema(request, collection_id):
hue_collection = Collection.objects.get(id=collection_id)
solr_schema = SolrApi(SOLR_URL.get(), request.user).schema(hue_collection.name)
content = {
'solr_schema': solr_schema.decode('utf-8')
}
return HttpResponse(json.dumps(content), mimetype="application/json")
开发者ID:Web5design,项目名称:hue,代码行数:8,代码来源:views.py
示例20: get_new_cores
def get_new_cores(self):
try:
solr_cores = SolrApi(SOLR_URL.get()).cores()
for name in Collection.objects.values_list('name', flat=True):
solr_cores.pop(name, None)
except Exception, e:
solr_cores = []
LOG.warn('No Single core setup on Solr server: %s' % e)
开发者ID:Roxasora,项目名称:hue,代码行数:8,代码来源:search_controller.py
注:本文中的search.conf.SOLR_URL类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论