[ckan-changes] commit/ckan: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Sep 1 14:01:27 UTC 2011
2 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/4b32280e0ad9/
changeset: 4b32280e0ad9
branch: feature-1275-solr-search
user: John Glover
date: 2011-09-01 15:55:50
summary: [solr] [1276] Apply weighting to search fields
affected #: 3 files (470 bytes)
--- a/ckan/lib/search/query.py Thu Sep 01 10:41:57 2011 +0100
+++ b/ckan/lib/search/query.py Thu Sep 01 14:55:50 2011 +0100
@@ -4,7 +4,6 @@
from paste.util.multidict import MultiDict
from paste.deploy.converters import asbool
from ckan import model
-from ckan.authz import Authorizer
from common import make_connection, SearchError
import logging
log = logging.getLogger(__name__)
@@ -12,11 +11,15 @@
_open_licenses = None
VALID_SOLR_PARAMETERS = set([
- 'q', 'fl', 'fq', 'rows', 'sort', 'start', 'wt',
+ 'q', 'fl', 'fq', 'rows', 'sort', 'start', 'wt', 'qf',
'filter_by_downloadable', 'filter_by_openness',
'facet', 'facet.mincount', 'facet.limit', 'facet.field'
])
+# for (solr) package searches, this specifies the fields that are searched
+# and their relative weighting
+QUERY_FIELDS = "name^4 title^4 tags^2 groups^2 text"
+
class QueryOptions(dict):
"""
Options specify aspects of the search query which are only tangentially related
@@ -300,7 +303,7 @@
# order by score if no 'sort' term given
order_by = query.get('sort')
if order_by == 'rank' or order_by is None:
- query['sort'] = 'score desc'
+ query['sort'] = 'score desc, name asc'
# show only results from this CKAN instance
fq = query.get('fq', '')
@@ -330,7 +333,12 @@
licenses = ["license_id:%s" % id for id in self.open_licenses]
licenses = " OR ".join(licenses)
query['fq'] += " +(%s) " % licenses
-
+
+ # query field weighting
+ query['defType'] = 'edismax'
+ query['tie'] = '0.5'
+ query['qf'] = query.get('qf', QUERY_FIELDS)
+
conn = make_connection()
try:
data = json.loads(conn.raw_query(**query))
--- a/ckan/tests/functional/test_package.py Thu Sep 01 10:41:57 2011 +0100
+++ b/ckan/tests/functional/test_package.py Thu Sep 01 14:55:50 2011 +0100
@@ -397,7 +397,8 @@
results_page = self.app.get(offset)
assert 'Search - ' in results_page, results_page
results_page = self.main_div(results_page)
- assert 'error while searching' in results_page, results_page
+ # solr's edismax parser won't throw an error, so this should return 0 results
+ assert '>0<' in results_page, results_page
def _check_search_results(self, page, terms, requireds, only_open=False, only_downloadable=False):
form = page.forms['package-search']
--- a/ckan/tests/lib/test_solr_package_search.py Thu Sep 01 10:41:57 2011 +0100
+++ b/ckan/tests/lib/test_solr_package_search.py Thu Sep 01 14:55:50 2011 +0100
@@ -159,14 +159,14 @@
all_pkg_count = all_results['count']
# rank
- # TODO: fix this test
- # options = search.QueryOptions()
- # options.order_by = 'rank'
- # result = search.query_for(model.Package).run(query='penguin', options=options)
- # pkgs = result['results']
- # fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
- # assert fields[0] == 'usa-courts-gov', fields # has penguin three times
- # assert pkgs == all_pkgs, pkgs #default ordering
+ query = {
+ 'q': 'government',
+ 'sort': 'rank'
+ }
+ result = search.query_for(model.Package).run(query)
+ pkgs = result['results']
+ fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
+ assert fields[0] == 'gils', fields # has government in tags, title and notes
# name
query = {
@@ -391,8 +391,10 @@
def setup_class(cls):
setup_test_search_index()
init_data = [{'name':u'test1-penguin-canary',
+ 'title':u'penguin',
'tags':u'canary goose squirrel wombat wombat'},
{'name':u'test2-squirrel-squirrel-canary-goose',
+ 'title':u'squirrel goose',
'tags':u'penguin wombat'},
]
CreateTestData.create_arbitrary(init_data)
@@ -423,9 +425,5 @@
self._do_search(u'canary', self.pkg_names)
def test_1_weighting(self):
- # TODO: fix this test
- from ckan.tests import SkipTest
- raise SkipTest
-
self._do_search(u'penguin', self.pkg_names)
self._do_search(u'goose', self.pkg_names[::-1])
http://bitbucket.org/okfn/ckan/changeset/ce010cae474f/
changeset: ce010cae474f
branch: feature-1275-solr-search
user: John Glover
date: 2011-09-01 16:01:15
summary: [solr] merge with default
affected #: 2 files (306 bytes)
--- a/ckan/controllers/user.py Thu Sep 01 14:55:50 2011 +0100
+++ b/ckan/controllers/user.py Thu Sep 01 15:01:15 2011 +0100
@@ -245,9 +245,12 @@
user_dict = get_action('user_show')(context,data_dict)
- response.set_cookie("ckan_user", user_dict['name'])
- response.set_cookie("ckan_display_name", user_dict['display_name'])
- response.set_cookie("ckan_apikey", user_dict['apikey'])
+ # Max age of cookies: 50 years. Matches time set in templates/user/login.html
+ cookie_timeout=50*365*24*60*60
+
+ response.set_cookie("ckan_user", user_dict['name'], max_age=cookie_timeout)
+ response.set_cookie("ckan_display_name", user_dict['display_name'], max_age=cookie_timeout)
+ response.set_cookie("ckan_apikey", user_dict['apikey'], max_age=cookie_timeout)
h.flash_success(_("Welcome back, %s") % user_dict['display_name'])
h.redirect_to(controller='user', action='me', id=None)
else:
--- a/ckan/templates/user/login.html Thu Sep 01 14:55:50 2011 +0100
+++ b/ckan/templates/user/login.html Thu Sep 01 15:01:15 2011 +0100
@@ -42,6 +42,8 @@
<br/><label for="password">Password:</label><input type="password" name="password" value="" />
+ <!-- 50 year timeout -->
+ <input type="hidden" name="remember" value="1576800000" /><br/></fieldset>
${h.submit('s', _('Login'))} —
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list