You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/03/26 22:02:44 UTC
[10/22] git commit: [#2835] ticket:288 Use 'dismax' parser for wiki
search, better match on title
[#2835] ticket:288 Use 'dismax' parser for wiki search, better match on title
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/87972940
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/87972940
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/87972940
Branch: refs/heads/master
Commit: 879729401792f6378f766fdb30c8179bc23dfa95
Parents: a9f0bdb
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Mar 7 11:52:11 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 20:57:36 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/artifact.py | 6 +++---
ForgeWiki/forgewiki/model/wiki.py | 6 ++++--
ForgeWiki/forgewiki/wiki_main.py | 22 ++++++++++++++++------
3 files changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/87972940/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 4c24a1c..95da7dd 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -208,12 +208,11 @@ class Artifact(MappedClass):
"""
Subclasses should override this, providing a dictionary of solr_field => value.
These fields & values will be stored by solr. Subclasses should call the
- super() index() and then extend it with more fields. All these fields will be
- included in the 'text' field (done by search.solarize())
+ super() index() and then extend it with more fields.
The _s and _t suffixes, for example, follow solr dynamic field naming
pattern.
- You probably want to override at least title_s and text to have
+ You probably want to override at least title, title_s and text to have
meaningful search results and email senders.
"""
@@ -222,6 +221,7 @@ class Artifact(MappedClass):
id=self.index_id(),
mod_date_dt=self.mod_date,
title_s='Artifact %s' % self._id,
+ title='Artifact %s' % self._id,
project_id_s=str(project._id),
project_name_t=project.name,
project_shortname_t=project.shortname,
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/87972940/ForgeWiki/forgewiki/model/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/model/wiki.py b/ForgeWiki/forgewiki/model/wiki.py
index dac92c7..c477b91 100644
--- a/ForgeWiki/forgewiki/model/wiki.py
+++ b/ForgeWiki/forgewiki/model/wiki.py
@@ -46,9 +46,10 @@ class PageHistory(Snapshot):
def index(self):
result = Snapshot.index(self)
+ title = '%s (version %d)' % (self.original().title, self.version)
result.update(
- title_s='Version %d of %s' % (
- self.version,self.original().title),
+ title_s=title,
+ title=title,
type_s='WikiPage Snapshot',
text=self.data.text)
return result
@@ -130,6 +131,7 @@ class Page(VersionedArtifact, ActivityObject):
result = VersionedArtifact.index(self)
result.update(
title_s=self.title,
+ title=self.title,
version_i=self.version,
type_s='WikiPage',
text=self.text)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/87972940/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index f15c634..e5482ea 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -304,15 +304,25 @@ class RootController(BaseController, DispatchIndex):
if not q:
q = ''
else:
+ # Match on both `title` and `text` by default, using 'dismax' parser.
+ # Score on `title` matches is boosted, so title match is better than body match.
+ # It's 'fuzzier' than standard parser, which matches only on `text`.
+ search_params = {
+ 'qt': 'dismax',
+ 'qf': 'title^2 text',
+ 'pf': 'title^2 text',
+ 'fq': [
+ 'project_id_s:%s' % c.project._id,
+ 'mount_point_s:%s'% c.app.config.options.mount_point,
+ '-deleted_b:true'
+ ]
+ }
+ if not history:
+ search_params['fq'].append('is_history_b:False')
try:
results = search(
q, short_timeout=True, ignore_errors=False,
- rows=limit, start=start,
- fq=[
- 'is_history_b:%s' % history,
- 'project_id_s:%s' % c.project._id,
- 'mount_point_s:%s'% c.app.config.options.mount_point,
- '-deleted_b:true'])
+ rows=limit, start=start, **search_params)
except SolrError as e:
search_error = e
if results: count=results.hits