Skip to content

Commit

Permalink
[#2844,search/sql][s]: minor fixes to have SQL-only (no solr) CKAN wo…
Browse files Browse the repository at this point in the history
…rking again.

* NB: have not fully tested but main pages (front page, search etc) are working
  • Loading branch information
rufuspollock committed Aug 13, 2012
1 parent 0d0e5a0 commit 031fee9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions ckan/lib/search/__init__.py
Expand Up @@ -27,7 +27,10 @@ def text_traceback():
).strip()
return res

SIMPLE_SEARCH = config.get('ckan.simple_search', False)
# Used to check config dict here and set this constant
# However, no longer effective as config dict seems not to be set up when this
# module is loaded
SIMPLE_SEARCH = False

SUPPORTED_SCHEMA_VERSIONS = ['1.4']

Expand Down Expand Up @@ -55,10 +58,14 @@ def text_traceback():

SOLR_SCHEMA_FILE_OFFSET = '/admin/file/?file=schema.xml'

if SIMPLE_SEARCH:
import sql as sql
_INDICES['package'] = NoopSearchIndex
_QUERIES['package'] = sql.PackageSearchQuery
def check_for_and_setup_sql_search():
SIMPLE_SEARCH = bool(config.get('ckan.simple_search', False))
if SIMPLE_SEARCH:
import sql as sql
_INDICES['package'] = NoopSearchIndex
_QUERIES['package'] = sql.PackageSearchQuery

check_for_and_setup_sql_search()


def _normalize_type(_type):
Expand Down Expand Up @@ -254,6 +261,9 @@ def check_solr_schema_version(schema_file=None):

import urllib2

# call this again here as the config dict is now setup and this called
# early in boot up process
check_for_and_setup_sql_search()
if SIMPLE_SEARCH:
# Not using the SOLR search backend
return False
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/search/sql.py
Expand Up @@ -13,6 +13,7 @@ def get_all_entity_ids(self, max_results=100):
return [r.id for r in q]

def run(self, query):
query = dict(query)
assert isinstance(query, dict)
# no support for faceting atm
self.facets = {}
Expand All @@ -34,7 +35,7 @@ def makelike(field):
ourq = ourq.filter(subq)
self.count = ourq.count()
ourq = ourq.limit(limit)
self.results = [r[0] for r in ourq.all()]
self.results = [{'id': r[0]} for r in ourq.all()]

return {'results': self.results, 'count': self.count}

0 comments on commit 031fee9

Please sign in to comment.