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
86cef76b
Commit
86cef76b
authored
Jul 04, 2005
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Collector #1815: ZCTextIndex accepts (again) sequences of strings to be indexed.
parent
dfb00ea7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
7 deletions
+53
-7
doc/CHANGES.txt
doc/CHANGES.txt
+3
-0
lib/python/Products/ZCTextIndex/IIndex.py
lib/python/Products/ZCTextIndex/IIndex.py
+3
-0
lib/python/Products/ZCTextIndex/ZCTextIndex.py
lib/python/Products/ZCTextIndex/ZCTextIndex.py
+24
-7
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
+23
-0
No files found.
doc/CHANGES.txt
View file @
86cef76b
...
...
@@ -34,6 +34,9 @@ Zope Changes
Bugs fixed
- Collector #1815: ZCTextIndex accepts (again) sequences of strings to
be indexed.
- Collector #1812: Fixed key error in ZSQL ZMI/Test
- Fixed CMFBTreeFolder for CMF 1.5+
...
...
lib/python/Products/ZCTextIndex/IIndex.py
View file @
86cef76b
...
...
@@ -68,6 +68,9 @@ class IIndex(Interface.Base):
"""Add a document with the specified id and text to the index. If a
document by that id already exists, replace its text with the new
text provided
text may be either a string (Unicode or otherwise) or a list
of strings from which to extract the terms under which to
index the source document.
"""
def
unindex_doc
(
docid
):
...
...
lib/python/Products/ZCTextIndex/ZCTextIndex.py
View file @
86cef76b
...
...
@@ -152,7 +152,14 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## Pluggable Index APIs ##
def
index_object
(
self
,
documentId
,
obj
,
threshold
=
None
):
""" wrapper to handle indexing of multiple attributes """
"""Wrapper for index_doc() handling indexing of multiple attributes.
Enter the document with the specified documentId in the index
under the terms extracted from the indexed text attributes,
each of which should yield either a string or a list of
strings (Unicode or otherwise) to be passed to index_doc().
"""
# XXX We currently ignore subtransaction threshold
# needed for backward compatibility
try
:
fields
=
self
.
_indexed_attrs
...
...
@@ -168,12 +175,22 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
text
=
text
()
if
text
is
None
:
continue
all_texts
.
append
(
text
)
if
all_texts
:
return
self
.
index
.
index_doc
(
documentId
,
' '
.
join
(
all_texts
))
else
:
return
0
# To index each attribute separately, we could use the
# following line, but we have preferred to make a single
# call to index_doc() for all attributes together.
# res += self.index.index_doc(documentId, text)
if
text
:
if
isinstance
(
text
,
(
list
,
tuple
,
)):
all_texts
.
extend
(
text
)
else
:
all_texts
.
append
(
text
)
# Check that we're sending only strings
all_texts
=
filter
(
lambda
text
:
isinstance
(
text
,
basestring
),
\
all_texts
)
if
all_texts
:
return
self
.
index
.
index_doc
(
documentId
,
all_texts
)
return
res
def
unindex_object
(
self
,
docid
):
if
self
.
index
.
has_doc
(
docid
):
...
...
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
View file @
86cef76b
...
...
@@ -151,6 +151,29 @@ class ZCIndexTestsBase:
nbest
,
total
=
zc_index
.
query
(
'foo alpha gamma'
)
self
.
assertEqual
(
len
(
nbest
),
0
)
def
testListAttributes
(
self
):
lexicon
=
PLexicon
(
'lexicon'
,
''
,
Splitter
(),
CaseNormalizer
(),
StopWordRemover
())
caller
=
LexiconHolder
(
self
.
lexicon
)
zc_index
=
ZCTextIndex
(
'name'
,
None
,
caller
,
self
.
IndexFactory
,
'text1,text2'
,
'lexicon'
)
doc
=
Indexable2
(
'Hello Tim'
,
\
[
'Now is the winter of our discontent'
,
'Made glorious summer by this sun of York'
,
])
zc_index
.
index_object
(
1
,
doc
)
nbest
,
total
=
zc_index
.
query
(
'glorious'
)
self
.
assertEqual
(
len
(
nbest
),
1
)
nbest
,
total
=
zc_index
.
query
(
'York Tim'
)
self
.
assertEqual
(
len
(
nbest
),
1
)
nbest
,
total
=
zc_index
.
query
(
'Tuesday Tim York'
)
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