Fixing search to work with recent changes.

This commit is contained in:
Dave Dash 2011-03-04 12:51:03 -08:00
Родитель 01ab88bd0e
Коммит 92e01f8e6a
4 изменённых файлов: 24 добавлений и 21 удалений

Просмотреть файл

@ -343,23 +343,7 @@ class PackageRevision(BaseModel):
self.set_version('copy')
return save_return
@es_required
def refresh_index(self, es, bulk=False):
data = djangoutils.get_values(self)
try:
if self.latest:
deps = self.latest.dependencies.all()
data['dependencies'] = [dep.package.id for dep in deps]
except PackageRevision.DoesNotExist:
pass
es.index(data, settings.ES_INDEX, self.get_type_name(), self.id,
bulk=bulk)
log.debug('Package %d added to search index.' % self.id)
@es_required
def remove_from_index(self, es):
es.delete(settings.ES_INDEX, self.get_type_name(), self.id)
log.debug('Package %d removed from search index.' % self.id)
def get_next_revision_number(self):
"""
@ -1256,6 +1240,24 @@ class Package(BaseModel):
if self.version_name:
self.version_name = alphanum_plus(self.version_name)
@es_required
def refresh_index(self, es, bulk=False):
data = djangoutils.get_values(self)
try:
if self.latest:
deps = self.latest.dependencies.all()
data['dependencies'] = [dep.package.id for dep in deps]
except PackageRevision.DoesNotExist:
pass
es.index(data, settings.ES_INDEX, self.get_type_name(), self.id,
bulk=bulk)
log.debug('Package %d added to search index.' % self.id)
@es_required
def remove_from_index(self, es):
es.delete(settings.ES_INDEX, self.get_type_name(), self.id)
log.debug('Package %d removed from search index.' % self.id)
class Module(BaseModel):
"""

Просмотреть файл

@ -20,7 +20,7 @@ def create_library(name):
def create_package(name, type):
u = User.objects.get(username='john')
return Package.objects.create(name=name, author=u, type=type)
return Package.objects.create(full_name=name, author=u, type=type)
# TODO: liberate - this can go in either test_utils or a separate library.
@ -30,10 +30,10 @@ class ESTestCase(test_utils.TestCase):
"""
@classmethod
def setUpClass(cls):
cls.old_ES_DISABLED = settings.ES_DISABLED
settings.ES_DISABLED = False
if not hasattr(settings, 'ES_BIN'):
raise SkipTest
cls.old_ES_DISABLED = settings.ES_DISABLED
settings.__dict__['ES_DISABLED'] = False
cls.es = get_es()
cls.es.delete_index_if_exists(settings.ES_INDEX)
@ -43,7 +43,7 @@ class ESTestCase(test_utils.TestCase):
@classmethod
def tearDownClass(cls):
settings.ES_DISABLED = cls.old_ES_DISABLED
settings.__dict__['ES_DISABLED'] = cls.old_ES_DISABLED
class TestSearch(ESTestCase):

Просмотреть файл

@ -9,5 +9,5 @@ def get_es():
"""Return one es object."""
global _es
if not _es:
_es = ES(settings.ES_HOSTS, default_indexes=[settings.ES_INDEX])
_es = ES(settings.ES_HOSTS, default_indexes=[settings.ES_INDEX], dump_curl="/tmp/t")
return _es

Просмотреть файл

@ -1 +1,2 @@
ES_INDEX = 'test_flightdeck'
ES_DISABLED = True # Do not run ES for tests unless you have to.