Skip to content

Commit cacae7c

Browse files
author
Richard Jones
committed
full-text search wasn't coping with multiple multilinks to the same class
1 parent 437492f commit cacae7c

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ are given with the most recent entry first.
44
2006-??-?? 1.3.1
55
Fixed:
66
- setup.py had broken reference to roundup.cgi (sf bug 1593573)
7+
- full-text search wasn't coping with multiple multilinks to the same class
78

89

910
2006-09-11 1.3.0

roundup/backends/indexer_common.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: indexer_common.py,v 1.7 2006-10-04 01:12:00 richard Exp $
1+
#$Id: indexer_common.py,v 1.8 2006-11-11 03:01:54 richard Exp $
22
import re, sets
33

44
from roundup import hyperdb
@@ -41,14 +41,16 @@ def search(self, search_terms, klass, ignore={}):
4141
designator_propname = {}
4242
for nm, propclass in klass.getprops().items():
4343
if _isLink(propclass):
44-
designator_propname[propclass.classname] = nm
44+
designator_propname.setdefault(propclass.classname,
45+
[]).append(nm)
4546

4647
# build a dictionary of nodes and their associated messages
4748
# and files
4849
nodeids = {} # this is the answer
4950
propspec = {} # used to do the klass.find
50-
for propname in designator_propname.values():
51-
propspec[propname] = {} # used as a set (value doesn't matter)
51+
for l in designator_propname.values():
52+
for propname in l:
53+
propspec[propname] = {} # used as a set (value doesn't matter)
5254

5355
# don't unpack hits entries as sqlite3's Row can't be unpacked :(
5456
for entry in hits:
@@ -70,14 +72,14 @@ def search(self, search_terms, klass, ignore={}):
7072
continue
7173

7274
# it's a linked class - set up to do the klass.find
73-
linkprop = designator_propname[classname] # eg, msg -> messages
74-
propspec[linkprop][nodeid] = 1
75+
for linkprop in designator_propname[classname]:
76+
propspec[linkprop][nodeid] = 1
7577

7678
# retain only the meaningful entries
7779
for propname, idset in propspec.items():
7880
if not idset:
7981
del propspec[propname]
80-
82+
8183
# klass.find tells me the klass nodeids the linked nodes relate to
8284
for resid in klass.find(**propspec):
8385
resid = str(resid)

test/db_test_base.py

Lines changed: 19 additions & 5 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.80 2006-11-09 05:44:51 richard Exp $
18+
# $Id: db_test_base.py,v 1.81 2006-11-11 03:01:54 richard Exp $
1919

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

@@ -78,7 +78,7 @@ def setupSchema(db, create, module):
7878
issue = module.IssueClass(db, "issue", title=String(indexme="yes"),
7979
status=Link("status"), nosy=Multilink("user"), deadline=Date(),
8080
foo=Interval(), files=Multilink("file"), assignedto=Link('user'),
81-
priority=Link('priority'))
81+
priority=Link('priority'), spam=Multilink('msg'))
8282
stuff = module.Class(db, "stuff", stuff=String())
8383
session = module.Class(db, 'session', title=String())
8484
msg = module.FileClass(db, "msg", date=Date(),
@@ -772,6 +772,20 @@ def testIndexerSearching(self):
772772
# unindexed stopword
773773
self.assertEquals(self.db.indexer.search(['the'], self.db.issue), {})
774774

775+
def testIndexerSearchMulti(self):
776+
m1 = self.db.msg.create(content="one two")
777+
m2 = self.db.msg.create(content="two three")
778+
i1 = self.db.issue.create(messages=[m1])
779+
i2 = self.db.issue.create(spam=[m2])
780+
self.db.commit()
781+
self.assertEquals(self.db.indexer.search([], self.db.issue), {})
782+
self.assertEquals(self.db.indexer.search(['one'], self.db.issue),
783+
{i1: {'messages': [m1]}})
784+
self.assertEquals(self.db.indexer.search(['two'], self.db.issue),
785+
{i1: {'messages': [m1]}, i2: {'spam': [m2]}})
786+
self.assertEquals(self.db.indexer.search(['three'], self.db.issue),
787+
{i2: {'spam': [m2]}})
788+
775789
def testReindexingChange(self):
776790
search = self.db.indexer.search
777791
issue = self.db.issue
@@ -1542,7 +1556,7 @@ def testAddProperty(self):
15421556
keys.sort()
15431557
self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
15441558
'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
1545-
'nosy', 'priority', 'status', 'superseder', 'title'])
1559+
'nosy', 'priority', 'spam', 'status', 'superseder', 'title'])
15461560
self.assertEqual(self.db.issue.get('1', "fixer"), None)
15471561

15481562
def testRemoveProperty(self):
@@ -1556,7 +1570,7 @@ def testRemoveProperty(self):
15561570
keys.sort()
15571571
self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
15581572
'creator', 'deadline', 'files', 'foo', 'id', 'messages',
1559-
'nosy', 'priority', 'status', 'superseder'])
1573+
'nosy', 'priority', 'spam', 'status', 'superseder'])
15601574
self.assertEqual(self.db.issue.list(), ['1'])
15611575

15621576
def testAddRemoveProperty(self):
@@ -1571,7 +1585,7 @@ def testAddRemoveProperty(self):
15711585
keys.sort()
15721586
self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
15731587
'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
1574-
'nosy', 'priority', 'status', 'superseder'])
1588+
'nosy', 'priority', 'spam', 'status', 'superseder'])
15751589
self.assertEqual(self.db.issue.list(), ['1'])
15761590

15771591
class ROTest(MyTestCase):

0 commit comments

Comments
 (0)