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
db9cf10c
Commit
db9cf10c
authored
May 15, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the new SetOps for mass union/intersection.
parent
f4c2c29b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
26 deletions
+11
-26
lib/python/Products/ZCTextIndex/ParseTree.py
lib/python/Products/ZCTextIndex/ParseTree.py
+11
-26
No files found.
lib/python/Products/ZCTextIndex/ParseTree.py
View file @
db9cf10c
...
@@ -14,8 +14,10 @@
...
@@ -14,8 +14,10 @@
"""Generic parser support: exception and parse tree nodes."""
"""Generic parser support: exception and parse tree nodes."""
from
BTrees.IIBTree
import
difference
,
weightedIntersection
,
weightedUnion
from
BTrees.IIBTree
import
difference
from
Products.ZCTextIndex.NBest
import
NBest
from
Products.ZCTextIndex.SetOps
import
mass_weightedIntersection
,
\
mass_weightedUnion
class
QueryError
(
Exception
):
class
QueryError
(
Exception
):
pass
pass
...
@@ -67,19 +69,13 @@ class AndNode(ParseTreeNode):
...
@@ -67,19 +69,13 @@ class AndNode(ParseTreeNode):
Nots
=
[]
Nots
=
[]
for
subnode
in
self
.
getValue
():
for
subnode
in
self
.
getValue
():
if
subnode
.
nodeType
()
==
"NOT"
:
if
subnode
.
nodeType
()
==
"NOT"
:
Nots
.
append
(
subnode
.
getValue
().
executeQuery
(
index
))
Nots
.
append
(
(
subnode
.
getValue
().
executeQuery
(
index
),
1
))
else
:
else
:
L
.
append
(
subnode
.
executeQuery
(
index
))
L
.
append
(
(
subnode
.
executeQuery
(
index
),
1
))
assert
L
assert
L
L
.
sort
(
lambda
x
,
y
:
cmp
(
len
(
x
),
len
(
y
)))
set
=
mass_weightedIntersection
(
L
)
set
=
L
[
0
]
for
x
in
L
[
1
:]:
dummy
,
set
=
weightedIntersection
(
set
,
x
)
if
Nots
:
if
Nots
:
Nots
.
sort
(
lambda
x
,
y
:
cmp
(
len
(
x
),
len
(
y
)))
notset
=
mass_weightedUnion
(
Nots
)
notset
=
Nots
[
0
]
for
x
in
Nots
[
1
:]:
dummy
,
notset
=
weightedUnion
(
notset
,
x
)
set
=
difference
(
set
,
notset
)
set
=
difference
(
set
,
notset
)
return
set
return
set
...
@@ -88,20 +84,9 @@ class OrNode(ParseTreeNode):
...
@@ -88,20 +84,9 @@ class OrNode(ParseTreeNode):
_nodeType
=
"OR"
_nodeType
=
"OR"
def
executeQuery
(
self
,
index
):
def
executeQuery
(
self
,
index
):
# Balance unions as closely as possible, smallest to largest.
weighted
=
[(
node
.
executeQuery
(
index
),
1
)
allofem
=
self
.
getValue
()
for
node
in
self
.
getValue
()]
merge
=
NBest
(
len
(
allofem
))
return
mass_weightedUnion
(
weighted
)
for
subnode
in
allofem
:
result
=
subnode
.
executeQuery
(
index
)
merge
.
add
(
result
,
len
(
result
))
while
len
(
merge
)
>
1
:
# Merge the two smallest so far, and add back to the queue.
x
,
dummy
=
merge
.
pop_smallest
()
y
,
dummy
=
merge
.
pop_smallest
()
dummy
,
z
=
weightedUnion
(
x
,
y
)
merge
.
add
(
z
,
len
(
z
))
result
,
dummy
=
merge
.
pop_smallest
()
return
result
class
AtomNode
(
ParseTreeNode
):
class
AtomNode
(
ParseTreeNode
):
...
...
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