本文整理汇总了Python中seo_pysolr.Solr类的典型用法代码示例。如果您正苦于以下问题:Python Solr类的具体用法?Python Solr怎么用?Python Solr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Solr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_jobs
def add_jobs(jobs, upload_chunk_size=1024):
"""
Loads a solr-ready json list of jobs into solr.
inputs:
:jobs: A list of solr-ready, json-formatted jobs.
outputs:
The number of jobs loaded into solr.
"""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
num_jobs = len(jobs)
# AT&T Showed that large numbers of MOCs can cause import issues due to the size of documents.
# Therefore, when processing AT&T lower the document chunk size.
for job in jobs:
if int(job.get('buid', 0)) == 19389:
logger.warn("AT&T has large amounts of mapped_mocs, that cause problems. Reducing chunk size.")
upload_chunk_size = 64
break
# Chunk them
jobs = chunk(jobs, upload_chunk_size)
for job_group in jobs:
conn.add(list(job_group))
return num_jobs
示例2: clear_solr
def clear_solr(buid):
"""Delete all jobs for a given business unit/job source."""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
hits = conn.search(q="*:*", rows=1, mlt="false", facet="false").hits
logging.info("BUID:%s - SOLR - Deleting all %s jobs" % (buid, hits))
conn.delete(q="buid:%s" % buid)
logging.info("BUID:%s - SOLR - All jobs deleted." % buid)
示例3: bread_box_title_heading
def bread_box_title_heading(title_slug_value, jobs=None):
if (not title_slug_value and not jobs) or not title_slug_value:
return None
if jobs:
job = jobs[0]
if title_slug_value == job.title_slug:
return job.title
else:
for job in jobs:
if title_slug_value == job.title_slug:
return job.title
# Try searching solr for a matching title.
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
try:
search_terms = {
'q': u'title_slug:%s' % title_slug_value,
'fl': 'title, title_slug',
'rows': 1,
}
res = conn.search(**search_terms)
except SolrError:
# Poorly formated title_slug_values can sometimes cause Solr errors.
res = None
if res and res.docs[0].get('title_slug') == title_slug_value:
return res.docs[0]['title']
else:
if title_slug_value:
return title_slug_value.replace('-', ' ').title()
else:
return None
示例4: DirectSEOBase
class DirectSEOBase(TestCase):
def setUp(self):
db_backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
# Set columns that are utf8 in production to utf8
if db_backend == 'mysql':
cursor = connections['default'].cursor()
cursor.execute("alter table seo_customfacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositefacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_company convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_queryredirect convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_tag convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_taggeditem convert to "
"character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositeredirect convert to "
"character set utf8 collate utf8_unicode_ci")
cursor.execute("alter table django_redirect convert to "
"character set utf8 collate utf8_unicode_ci")
setattr(settings, 'ROOT_URLCONF', 'dseo_urls')
setattr(settings, "PROJECT", 'dseo')
clear_url_caches()
self.base_middleware_classes = settings.MIDDLEWARE_CLASSES
middleware_classes = self.base_middleware_classes + (
'wildcard.middleware.WildcardMiddleware',
'middleware.RedirectOverrideMiddleware')
setattr(settings, 'MIDDLEWARE_CLASSES', middleware_classes)
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
"social_links.context_processors.social_links_context",
"seo.context_processors.site_config_context",
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
context._standard_context_processors = None
self.conn = Solr('http://127.0.0.1:8983/solr/seo')
self.conn.delete(q="*:*")
cache.clear()
clear_url_caches()
setattr(settings, 'MEMOIZE', False)
def tearDown(self):
from django.conf import settings
from django.template import context
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS',
self.base_context_processors)
context._standard_context_processors = None
setattr(settings, 'MIDDLEWARE_CLASSES',
self.base_middleware_classes)
示例5: _solr_results_chunk
def _solr_results_chunk(tup, buid, step):
"""
Takes a (start_index, stop_index) tuple and gets the results in that
range from the Solr index.
"""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
results = conn.search("*:*", fq="buid:%s" % buid, fl="uid",
rows=step, start=tup[0], facet="false",
mlt="false").docs
return set([i['uid'] for i in results if 'uid' in i])
示例6: setUp
def setUp(self):
super(ImportJobsTestCase, self).setUp()
self.businessunit = BusinessUnitFactory(id=0)
self.buid_id = self.businessunit.id
self.filepath = os.path.join(DATA_DIR, '0', 'dseo_feed_%s.xml' % self.buid_id)
self.solr_settings = {
'default': {'URL': 'http://127.0.0.1:8983/solr/seo'}
}
self.solr = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
示例7: remove_expired_jobs
def remove_expired_jobs(buid, active_jobs, upload_chunk_size=1024):
"""
Given a job source id and a list of active jobs for that job source,
Remove the jobs on solr that are not among the active jobs.
"""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
count = conn.search("*:*", fq="buid:%s" % buid, facet="false",
mlt="false").hits
old_jobs = conn.search("*:*", fq="buid:%s" % buid, facet="false",
rows=count, mlt="false").docs
active_ids = set(j['id'] for j in active_jobs)
old_ids = set(j['id'] for j in old_jobs)
expired = old_ids - active_ids
chunks = chunk(list(expired), upload_chunk_size)
for jobs in chunks:
query = "id:(%s)" % " OR ".join([str(x) for x in jobs])
conn.delete(q=query)
return expired
示例8: add_jobs
def add_jobs(jobs, upload_chunk_size=1024):
"""
Loads a solr-ready json list of jobs into solr.
inputs:
:jobs: A list of solr-ready, json-formatted jobs.
outputs:
The ids of jobs loaded into solr.
"""
conn = Solr(settings.HAYSTACK_CONNECTIONS["default"]["URL"])
# Chunk them
jobs = chunk(jobs, upload_chunk_size)
job_ids = list()
for job_group in jobs:
job_group = list(job_group)
conn.add(job_group)
job_ids.extend(j["id"] for j in job_group)
return job_ids
示例9: MyJobsBase
class MyJobsBase(TestCase):
def setUp(self):
from django.conf import settings
setattr(settings, 'ROOT_URLCONF', 'myjobs_urls')
cache.clear()
clear_url_caches()
self.ms_solr = Solr('http://127.0.0.1:8983/solr/seo')
self.ms_solr.delete(q='*:*')
setattr(settings, "PROJECT", 'myjobs')
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
'mymessages.context_processors.message_lists',
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
setattr(settings, 'MEMOIZE', False)
def tearDown(self):
self.ms_solr.delete(q='*:*')
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS',
self.base_context_processors)
示例10: delete_by_guid
def delete_by_guid(guids):
"""
Removes a jobs from solr by guid.
inputs:
:guids: A list of guids
outputs:
The number of jobs that were requested to be deleted. This may
be higher than the number of actual jobs deleted if a guid
passed in did not correspond to a job in solr.
"""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
if not guids:
return 0
num_guids = len(guids)
guids = chunk(guids)
for guid_group in guids:
delete_str = " OR ".join(guid_group)
conn.delete(q="guid: (%s)" % delete_str)
return num_guids
示例11: setUp
def setUp(self):
db_backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
# Set columns that are utf8 in production to utf8
if db_backend == 'mysql':
cursor = connections['default'].cursor()
cursor.execute("alter table seo_customfacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositefacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_company convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_tag convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_taggeditem convert to "
"character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositeredirect convert to "
"character set utf8 collate utf8_unicode_ci")
cursor.execute("alter table django_redirect convert to "
"character set utf8 collate utf8_unicode_ci")
setattr(settings, 'ROOT_URLCONF', 'dseo_urls')
setattr(settings, "PROJECT", 'dseo')
clear_url_caches()
self.base_middleware_classes = settings.MIDDLEWARE_CLASSES
middleware_classes = self.base_middleware_classes + (
'wildcard.middleware.WildcardMiddleware', )
setattr(settings, 'MIDDLEWARE_CLASSES', middleware_classes)
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
"social_links.context_processors.social_links_context",
"seo.context_processors.site_config_context",
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
context._standard_context_processors = None
self.conn = Solr('http://127.0.0.1:8983/solr/seo')
self.conn.delete(q="*:*")
cache.clear()
clear_url_caches()
# Change the solr engine to one that has been extended
# for testing purposes.
self.default_engine = settings.HAYSTACK_CONNECTIONS['default']['ENGINE']
self.engine = 'seo.tests.setup.TestDESolrEngine'
settings.HAYSTACK_CONNECTIONS['default']['ENGINE'] = self.engine
haystack_connections.reload('default')
setattr(settings, 'MEMOIZE', False)
示例12: __init__
def __init__(self, connection_alias, **connection_options):
"""
Inputs:
:HTTP_AUTH_USERNAME: Username used for http authentication
:HTTP_AUTH_PASSWORD: Password used for http authentication
"""
super(DESolrSearchBackend, self).__init__(connection_alias,
**connection_options)
user = connection_options.get("HTTP_AUTH_USERNAME")
passwd = connection_options.get("HTTP_AUTH_PASSWORD")
self.conn = Solr(connection_options['URL'], auth=(user, passwd),
timeout=self.timeout)
示例13: setUp
def setUp(self):
super(SiteTestCase, self).setUp()
self.conn = Solr("http://127.0.0.1:8983/solr/seo")
self.conn.delete(q="*:*")
self.businessunit = factories.BusinessUnitFactory(id=0)
self.buid = self.businessunit.id
self.filepath = os.path.join(import_jobs.DATA_DIR, "dseo_feed_%s.xml" % self.buid)
SeoSite.objects.all().delete()
self.site = factories.SeoSiteFactory(id=1)
self.configuration = factories.ConfigurationFactory(status=2)
self.configuration.save()
self.site.configurations.clear()
self.site.configurations.add(self.configuration)
示例14: setUp
def setUp(self):
settings.ROOT_URLCONF = "myjobs_urls"
settings.PROJECT = "myjobs"
self.app_access = AppAccessFactory()
self.activities = [
ActivityFactory(name=activity, app_access=self.app_access)
for activity in [
"create communication record", "create contact",
"create partner saved search", "create partner", "create role",
"create tag", "create user", "delete tag", "delete partner",
"delete role", "delete user", "read contact",
"read communication record", "read partner saved search",
"read partner", "read role", "read user", "read tag",
"update communication record", "update contact",
"update partner", "update role", "update tag", "update user",
"read outreach email address", "create outreach email address",
"delete outreach email address",
"update outreach email address", "read outreach record",
"convert outreach record"]]
self.company = CompanyFactory(app_access=[self.app_access])
# this role will be populated by activities on a test-by-test basis
self.role = RoleFactory(company=self.company, name="Admin")
self.user = UserFactory(roles=[self.role], is_staff=True)
cache.clear()
clear_url_caches()
self.ms_solr = Solr(settings.SOLR['seo_test'])
self.ms_solr.delete(q='*:*')
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
'mymessages.context_processors.message_lists',
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
setattr(settings, 'MEMOIZE', False)
self.patcher = patch('urllib2.urlopen', return_file())
self.mock_urlopen = self.patcher.start()
self.client = TestClient()
self.client.login_user(self.user)
示例15: setUp
def setUp(self):
super(JobFeedTestCase, self).setUp()
self.businessunit = BusinessUnitFactory(id=0)
self.buid_id = self.businessunit.id
self.numjobs = 14
self.testdir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'data')
self.company = CompanyFactory()
self.company.job_source_ids.add(self.businessunit)
self.company.save()
self.conn = Solr("http://127.0.0.1:8983/solr/seo")
self.emptyfeed = os.path.join(self.testdir, "dseo_feed_0.no_jobs.xml")
self.malformed_feed = os.path.join(self.testdir, 'dseo_malformed_feed_0.xml')
self.invalid_feed = os.path.join(self.testdir, 'dseo_invalid_feed_0.xml')
self.unused_field_feed = os.path.join(self.testdir, 'dseo_feed_1.xml')
self.no_onet_feed = os.path.join(self.testdir, 'dseo_feed_no_onets.xml')
#Ensures DATA_DIR used by import_jobs.download_feed_file exists
data_path = DATA_DIR
if not os.path.exists(data_path):
os.mkdir(data_path)