Skip to content

Commit

Permalink
Merge branch '2844-re-enable-simple-search'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Aug 14, 2012
2 parents ef5e4a0 + 3d33445 commit f314d00
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ckan/config/environment.py
Expand Up @@ -16,7 +16,6 @@
import ckan.model as model
import ckan.plugins as p
import ckan.lib.helpers as h
import ckan.lib.search as search
import ckan.lib.app_globals as app_globals

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -161,6 +160,9 @@ def find_controller(self, controller):

# Init SOLR settings and check if the schema is compatible
#from ckan.lib.search import SolrSettings, check_solr_schema_version

# lib.search is imported here as we need the config enabled and parsed
import ckan.lib.search as search
search.SolrSettings.init(config.get('solr_url'),
config.get('solr_user'),
config.get('solr_password'))
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/search/__init__.py
@@ -1,5 +1,6 @@
import logging
from pylons import config, c
from paste.deploy.converters import asbool

from ckan import model
from ckan.plugins import SingletonPlugin, implements, IDomainObjectModification
Expand Down Expand Up @@ -27,7 +28,7 @@ def text_traceback():
).strip()
return res

SIMPLE_SEARCH = config.get('ckan.simple_search', False)
SIMPLE_SEARCH = asbool(config.get('ckan.simple_search', False))

SUPPORTED_SCHEMA_VERSIONS = ['1.4']

Expand Down
6 changes: 3 additions & 3 deletions ckan/lib/search/sql.py
@@ -1,4 +1,4 @@
from sqlalchemy import or_, and_
from sqlalchemy import or_
from ckan.lib.search.query import SearchQuery
import ckan.model as model

Expand All @@ -17,7 +17,7 @@ def run(self, query):
# no support for faceting atm
self.facets = {}
limit = min(1000, int(query.get('rows', 10)))

q = query.get('q')
ourq = model.Session.query(model.Package.id).filter_by(state='active')

Expand All @@ -34,7 +34,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}

2 changes: 1 addition & 1 deletion ckan/tests/lib/test_simple_search.py
Expand Up @@ -22,7 +22,7 @@ def test_get_all_entity_ids(self):
def test_run_query_basic(self):
res = PackageSearchQuery().run({'q':'annakarenina'})
anna = model.Package.by_name(u'annakarenina')
assert_equal(res, {'results': [anna.id], 'count': 1})
assert_equal(res, {'results': [{'id': anna.id}], 'count': 1})

def test_run_query_home(self):
# This is the query from the CKAN home page
Expand Down

0 comments on commit f314d00

Please sign in to comment.