Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
75964156
Commit
75964156
authored
May 17, 2005
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Collector #1784: fixed handling of multiple attributes in ZCTextIndex
parent
06e3b28b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
14 deletions
+42
-14
doc/CHANGES.txt
doc/CHANGES.txt
+2
-0
lib/python/Products/ZCTextIndex/ZCTextIndex.py
lib/python/Products/ZCTextIndex/ZCTextIndex.py
+13
-14
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
+27
-0
No files found.
doc/CHANGES.txt
View file @
75964156
...
...
@@ -31,6 +31,8 @@ Zope Changes
Bugs fixed
- Collector #1784: fixed handling of multiple attributes in ZCTextIndex
- Don't copy '.svn' directories from skeleton into an instance
(thanks to Dale Hirt for the patch).
...
...
lib/python/Products/ZCTextIndex/ZCTextIndex.py
View file @
75964156
...
...
@@ -159,22 +159,21 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
except
:
fields
=
[
self
.
_fieldname
]
res
=
0
all_texts
=
[]
for
attr
in
fields
:
res
+=
self
.
_index_object
(
documentId
,
obj
,
threshold
,
attr
)
return
res
def
_index_object
(
self
,
docid
,
obj
,
threshold
=
None
,
attr
=
None
):
# XXX We currently ignore subtransaction threshold
text
=
getattr
(
obj
,
self
.
_fieldname
,
None
)
if
text
is
None
:
return
0
if
safe_callable
(
text
):
text
=
text
(
)
if
text
is
Non
e
:
text
=
getattr
(
obj
,
attr
,
None
)
if
text
is
None
:
continue
if
safe_callable
(
text
):
text
=
text
()
if
text
is
None
:
continue
all_texts
.
append
(
text
)
if
all_texts
:
return
self
.
index
.
index_doc
(
documentId
,
' '
.
join
(
all_texts
)
)
els
e
:
return
0
count
=
self
.
index
.
index_doc
(
docid
,
text
)
return
count
def
unindex_object
(
self
,
docid
):
if
self
.
index
.
has_doc
(
docid
):
...
...
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
View file @
75964156
...
...
@@ -39,6 +39,11 @@ class Indexable:
def
__init__
(
self
,
text
):
self
.
text
=
text
class
Indexable2
:
def
__init__
(
self
,
text1
,
text2
):
self
.
text1
=
text1
self
.
text2
=
text2
class
LexiconHolder
(
Acquisition
.
Implicit
):
def
__init__
(
self
,
lexicon
):
self
.
lexicon
=
lexicon
...
...
@@ -115,6 +120,7 @@ class ZCIndexTestsBase:
'lexicon'
)
self
.
index
=
self
.
zc_index
.
index
def
parserFailure
(
self
,
query
):
self
.
assertRaises
(
ParseError
,
self
.
zc_index
.
query
,
query
)
...
...
@@ -124,6 +130,27 @@ class ZCIndexTestsBase:
if
n
:
self
.
assertEqual
(
r
[
0
][
0
],
1
)
def
testMultipleAttributes
(
self
):
lexicon
=
PLexicon
(
'lexicon'
,
''
,
Splitter
(),
CaseNormalizer
(),
StopWordRemover
())
caller
=
LexiconHolder
(
self
.
lexicon
)
zc_index
=
ZCTextIndex
(
'name'
,
None
,
caller
,
self
.
IndexFactory
,
'text1,text2'
,
'lexicon'
)
doc
=
Indexable2
(
'foo bar'
,
'alpha omega'
)
zc_index
.
index_object
(
1
,
doc
)
nbest
,
total
=
zc_index
.
query
(
'foo'
)
self
.
assertEqual
(
len
(
nbest
),
1
)
nbest
,
total
=
zc_index
.
query
(
'foo alpha'
)
self
.
assertEqual
(
len
(
nbest
),
1
)
nbest
,
total
=
zc_index
.
query
(
'foo alpha gamma'
)
self
.
assertEqual
(
len
(
nbest
),
0
)
def
testStopWords
(
self
):
# the only non-stopword is question
text
=
(
"to be or not to be "
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment