Skip to content

Commit 09f08ce

Browse files
author
Richard Jones
committed
Fix indexer handling of indexed Link properties
1 parent a4d9ecb commit 09f08ce

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fixed:
2323
- Allow binary file content submission via XML-RPC (sf #1995623)
2424
- Don't run old code on newer database (sf #1979556)
2525
- Fix HTML injection into page title
26+
- Fix indexer handling of indexed Link properties (sf #1936876)
2627

2728

2829
2008-03-01 1.4.4

roundup/backends/indexer_common.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: indexer_common.py,v 1.8 2006-11-11 03:01:54 richard Exp $
1+
#$Id: indexer_common.py,v 1.9 2008-08-18 06:57:49 richard Exp $
22
import re, sets
33

44
from roundup import hyperdb
@@ -8,7 +8,7 @@
88
"FOR", "IF", "IN", "INTO", "IS", "IT",
99
"NO", "NOT", "OF", "ON", "OR", "SUCH",
1010
"THAT", "THE", "THEIR", "THEN", "THERE", "THESE",
11-
"THEY", "THIS", "TO", "WAS", "WILL", "WITH"
11+
"THEY", "THIS", "TO", "WAS", "WILL", "WITH"
1212
]
1313

1414
def _isLink(propclass):
@@ -26,7 +26,7 @@ def is_stopword(self, word):
2626

2727
def getHits(self, search_terms, klass):
2828
return self.find(search_terms)
29-
29+
3030
def search(self, search_terms, klass, ignore={}):
3131
'''Display search results looking for [search, terms] associated
3232
with the hyperdb Class "klass". Ignore hits on {class: property}.
@@ -81,14 +81,20 @@ def search(self, search_terms, klass, ignore={}):
8181
del propspec[propname]
8282

8383
# klass.find tells me the klass nodeids the linked nodes relate to
84+
propdefs = klass.getprops()
8485
for resid in klass.find(**propspec):
8586
resid = str(resid)
8687
if not nodeids.has_key(id):
8788
nodeids[resid] = {}
8889
node_dict = nodeids[resid]
8990
# now figure out where it came from
9091
for linkprop in propspec.keys():
91-
for nodeid in klass.get(resid, linkprop):
92+
v = klass.get(resid, linkprop)
93+
# the link might be a Link so deal with a single result or None
94+
if isinstance(propdefs[linkprop], hyperdb.Link):
95+
if v is None: continue
96+
v = [v]
97+
for nodeid in v:
9298
if propspec[linkprop].has_key(nodeid):
9399
# OK, this node[propname] has a winner
94100
if not node_dict.has_key(linkprop):

test/db_test_base.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.98 2008-08-18 06:41:32 richard Exp $
18+
# $Id: db_test_base.py,v 1.99 2008-08-18 06:57:49 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint, sets, base64, os.path
2121

@@ -81,7 +81,8 @@ def setupSchema(db, create, module):
8181
issue = module.IssueClass(db, "issue", title=String(indexme="yes"),
8282
status=Link("status"), nosy=Multilink("user"), deadline=Date(),
8383
foo=Interval(), files=Multilink("file"), assignedto=Link('user'),
84-
priority=Link('priority'), spam=Multilink('msg'))
84+
priority=Link('priority'), spam=Multilink('msg'),
85+
feedback=Link('msg'))
8586
stuff = module.Class(db, "stuff", stuff=String())
8687
session = module.Class(db, 'session', title=String())
8788
msg = module.FileClass(db, "msg", date=Date(),
@@ -858,6 +859,15 @@ def testIndexerSearching(self):
858859
# unindexed stopword
859860
self.assertEquals(self.db.indexer.search(['the'], self.db.issue), {})
860861

862+
def testIndexerSearchingLink(self):
863+
m1 = self.db.msg.create(content="one two")
864+
i1 = self.db.issue.create(messages=[m1])
865+
m2 = self.db.msg.create(content="two three")
866+
i2 = self.db.issue.create(feedback=m2)
867+
self.db.commit()
868+
self.assertEquals(self.db.indexer.search(['two'], self.db.issue),
869+
{i1: {'messages': [m1]}, i2: {'feedback': [m2]}})
870+
861871
def testIndexerSearchMulti(self):
862872
m1 = self.db.msg.create(content="one two")
863873
m2 = self.db.msg.create(content="two three")
@@ -1725,7 +1735,7 @@ def testAddProperty(self):
17251735
keys = props.keys()
17261736
keys.sort()
17271737
self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
1728-
'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
1738+
'creator', 'deadline', 'feedback', 'files', 'fixer', 'foo', 'id', 'messages',
17291739
'nosy', 'priority', 'spam', 'status', 'superseder', 'title'])
17301740
self.assertEqual(self.db.issue.get('1', "fixer"), None)
17311741

@@ -1739,7 +1749,7 @@ def testRemoveProperty(self):
17391749
keys = props.keys()
17401750
keys.sort()
17411751
self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
1742-
'creator', 'deadline', 'files', 'foo', 'id', 'messages',
1752+
'creator', 'deadline', 'feedback', 'files', 'foo', 'id', 'messages',
17431753
'nosy', 'priority', 'spam', 'status', 'superseder'])
17441754
self.assertEqual(self.db.issue.list(), ['1'])
17451755

0 commit comments

Comments
 (0)