Skip to content

Fix #212 - Allow configuration of the search index #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tests/search/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_reindex(self, monkeypatch):
monkeypatch.setattr(os, "urandom", urandom)

models = pretend.stub()
config = pretend.stub(hosts=[], get=lambda *a: {})
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

index = Index(models, config)
index.es = pretend.stub(
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_reindex_no_alias(self, monkeypatch):
monkeypatch.setattr(os, "urandom", urandom)

models = pretend.stub()
config = pretend.stub(hosts=[], get=lambda *a: {})
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

index = Index(models, config)
index.es = pretend.stub(
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_reindex_no_alias(self, monkeypatch):

def test_update_alias(self):
models = pretend.stub()
config = pretend.stub(hosts=[], get=lambda *a: {})
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

index = Index(models, config)
index.es = pretend.stub(
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_update_alias(self):

def test_update_alias_no_old_index(self):
models = pretend.stub()
config = pretend.stub(hosts=[], get=lambda *a: {})
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

def _get_alias(idx):
raise TransportError(404, "Fake 404")
Expand All @@ -160,7 +160,7 @@ def _get_alias(idx):

def test_update_alias_exception(self):
models = pretend.stub()
config = pretend.stub(hosts=[], get=lambda *a: {})
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

def _get_alias(idx):
raise TransportError(500, "Fake 500")
Expand Down
1 change: 1 addition & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_basic_instantiation():
"url": "redis://localhost:6379/0"
},
"search": {
"index": "warehouse",
"hosts": [],
},
"logging": {
Expand Down
3 changes: 3 additions & 0 deletions warehouse/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ site:
name: Warehouse
url: /

search:
index: warehouse

paths:
documentation: data/packagedocs

Expand Down
8 changes: 4 additions & 4 deletions warehouse/search/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

class Index(object):

_index = "warehouse"

def __init__(self, db, config):
self.db = db
self.config = config
Expand All @@ -37,14 +35,16 @@ def __init__(self, db, config):

self.types = AttributeDict()

self._index = config.index

def register(self, type_):
obj = type_(self)
self.types[obj._type] = obj

def reindex(self, index=None, alias=True, keep_old=False):
def reindex(self, alias=True, keep_old=False):
# Generate an Index Name for Warehouse
index = "".join([
index if index is not None else self._index,
self._index,
binascii.hexlify(os.urandom(4)),
])

Expand Down