Skip to content
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

Fix query differences #27

Merged
merged 1 commit into from
Oct 19, 2011
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
6 changes: 4 additions & 2 deletions oedipus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def _filter_value_to_int(self, name, value):
def _sanitize_query(query):
"""Strip control characters that cause problems."""
query = re.sub(r'(?<=\S)\-', '\-', query)
query = query.replace('/', '\\/')
return query.replace('^', '').replace('$', '')

def _sphinx(self):
Expand Down Expand Up @@ -543,8 +544,9 @@ def _raw(self):
if not results:
raise SearchError('Sphinx returned no results.')
if results[0]['status'] == sphinxapi.SEARCHD_ERROR:
raise SearchError('Sphinx had an error while performing a '
'query.')
log.error('Sphinx errored while performing a query: %r',
results[0]['error'])
return {'matches': []}

# We do only one query at a time; return the first one:
return self._results_cache[0]
Expand Down
18 changes: 18 additions & 0 deletions oedipus/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def test_connection_failure(sphinx_client):
assert_raises(SearchError, S(Biscuit)._raw)


@fudge.patch('sphinxapi.SphinxClient')
def test_query_error(sphinx_client):
"""[] should get returned when the query has an error."""
(sphinx_client.expects_call().returns_fake()
.is_a_stub()
.expects('RunQueries').returns([{
'status': 1,
'warning': '',
'error': 'index questions: syntax error'}]))
eq_(S(Biscuit)._raw(), {'matches': []})


@fudge.patch('sphinxapi.SphinxClient')
@fudge.patch('oedipus.settings')
def test_sphinx_max_results_clips(sphinx_client, settings):
Expand All @@ -57,3 +69,9 @@ def test_sphinx_max_results_clips(sphinx_client, settings):
s = S(Biscuit)[0:]
# Do this to trigger the results.
s.count()


def test_sanitize_query():
"""Tests _sanitize_query."""
sq = S._sanitize_query
eq_(sq('google.com/iq'), 'google.com\\/iq')