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
993856e5
Commit
993856e5
authored
May 24, 2002
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move IQueryParseTree to a separate file, to conform to style
guidelines. Added some conformance tests.
parent
58331c88
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
37 deletions
+83
-37
lib/python/Products/ZCTextIndex/IQueryParseTree.py
lib/python/Products/ZCTextIndex/IQueryParseTree.py
+52
-0
lib/python/Products/ZCTextIndex/IQueryParser.py
lib/python/Products/ZCTextIndex/IQueryParser.py
+0
-35
lib/python/Products/ZCTextIndex/ParseTree.py
lib/python/Products/ZCTextIndex/ParseTree.py
+3
-0
lib/python/Products/ZCTextIndex/QueryParser.py
lib/python/Products/ZCTextIndex/QueryParser.py
+4
-1
lib/python/Products/ZCTextIndex/tests/testQueryParser.py
lib/python/Products/ZCTextIndex/tests/testQueryParser.py
+24
-1
No files found.
lib/python/Products/ZCTextIndex/IQueryParseTree.py
0 → 100644
View file @
993856e5
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Query Parser Tree Interface."""
import
Interface
class
IQueryParseTree
(
Interface
.
Base
):
"""Interface for parse trees returned by parseQuery()."""
def
nodeType
():
"""Return the node type.
This is one of 'AND', 'OR', 'NOT', 'ATOM', 'PHRASE' or 'GLOB'.
"""
def
getValue
():
"""Return a node-type specific value.
For node type: Return:
'AND' a list of parse trees
'OR' a list of parse trees
'NOT' a parse tree
'ATOM' a string (representing a single search term)
'PHRASE' a string (representing a search phrase)
'GLOB' a string (representing a pattern, e.g. "foo*")
"""
def
terms
():
"""Return a list of all terms in this node, excluding NOT subtrees."""
def
executeQuery
(
index
):
"""Execute the query represented by this node against the index.
The index argument must implement the IIndex interface.
Return an IIBucket or IIBTree mapping document ids to scores
(higher scores mean better results).
May raise ParseTree.QueryError.
"""
lib/python/Products/ZCTextIndex/IQueryParser.py
View file @
993856e5
...
...
@@ -51,38 +51,3 @@ class IQueryParser(Interface.Base):
May raise ParseTree.ParseError.
"""
class
IQueryParseTree
(
Interface
.
Base
):
"""Interface for parse trees returned by parseQuery()."""
def
nodeType
():
"""Return the node type.
This is one of 'AND', 'OR', 'NOT', 'ATOM', 'PHRASE' or 'GLOB'.
"""
def
getValue
():
"""Return a node-type specific value.
For node type: Return:
'AND' a list of parse trees
'OR' a list of parse trees
'NOT' a parse tree
'ATOM' a string (representing a single search term)
'PHRASE' a string (representing a search phrase)
'GLOB' a string (representing a pattern, e.g. "foo*")
"""
def
terms
():
"""Return a list of all terms in this node, excluding NOT subtrees."""
def
executeQuery
(
index
):
"""Execute the query represented by this node against the index.
The index argument must implement the IIndex interface.
Return an IIBucket or IIBTree mapping document ids to scores
(higher scores mean better results).
May raise ParseTree.QueryError.
"""
lib/python/Products/ZCTextIndex/ParseTree.py
View file @
993856e5
...
...
@@ -16,6 +16,7 @@
from
BTrees.IIBTree
import
difference
from
Products.ZCTextIndex.IQueryParseTree
import
IQueryParseTree
from
Products.ZCTextIndex.SetOps
import
mass_weightedIntersection
,
\
mass_weightedUnion
...
...
@@ -27,6 +28,8 @@ class ParseError(Exception):
class
ParseTreeNode
:
__implements__
=
IQueryParseTree
_nodeType
=
None
def
__init__
(
self
,
value
):
...
...
lib/python/Products/ZCTextIndex/QueryParser.py
View file @
993856e5
...
...
@@ -57,7 +57,8 @@ Summarizing the default operator rules:
import
re
import
ParseTree
# relative import
from
Products.ZCTextIndex.IQueryParser
import
IQueryParser
from
Products.ZCTextIndex
import
ParseTree
# Create unique symbols for token types.
_AND
=
intern
(
"AND"
)
...
...
@@ -94,6 +95,8 @@ _tokenizer_regex = re.compile(r"""
class
QueryParser
:
__implements__
=
IQueryParser
# This class is not thread-safe;
# each thread should have its own instance
...
...
lib/python/Products/ZCTextIndex/tests/testQueryParser.py
View file @
993856e5
...
...
@@ -14,13 +14,31 @@
from
unittest
import
TestCase
,
TestSuite
,
main
,
makeSuite
from
Products.ZCTextIndex.QueryParser
import
QueryParser
from
Interface
import
verify_class_implementation
from
Products.ZCTextIndex.IQueryParser
import
IQueryParser
from
Products.ZCTextIndex.IQueryParseTree
import
IQueryParseTree
from
Products.ZCTextIndex.QueryParser
import
QueryParser
from
Products.ZCTextIndex.ParseTree
import
ParseError
,
ParseTreeNode
from
Products.ZCTextIndex.ParseTree
import
OrNode
,
AndNode
,
NotNode
from
Products.ZCTextIndex.ParseTree
import
AtomNode
,
PhraseNode
,
GlobNode
from
Products.ZCTextIndex.Lexicon
import
Lexicon
,
Splitter
class
TestInterfaces
(
TestCase
):
def
testInterfaces
(
self
):
verify_class_implementation
(
IQueryParser
,
QueryParser
)
verify_class_implementation
(
IQueryParseTree
,
ParseTreeNode
)
verify_class_implementation
(
IQueryParseTree
,
OrNode
)
verify_class_implementation
(
IQueryParseTree
,
AndNode
)
verify_class_implementation
(
IQueryParseTree
,
NotNode
)
verify_class_implementation
(
IQueryParseTree
,
AtomNode
)
verify_class_implementation
(
IQueryParseTree
,
PhraseNode
)
verify_class_implementation
(
IQueryParseTree
,
GlobNode
)
class
TestQueryParserBase
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -67,6 +85,7 @@ class TestQueryParserBase(TestCase):
for
i
in
range
(
len
(
list1
)):
self
.
compareParseTrees
(
list1
[
i
],
list2
[
i
],
msg
)
class
TestQueryParser
(
TestQueryParserBase
):
def
test001
(
self
):
...
...
@@ -216,6 +235,7 @@ class TestQueryParser(TestQueryParserBase):
def
test122
(
self
):
self
.
failure
(
"foo AND -bar"
)
class
StopWordTestQueryParser
(
TestQueryParserBase
):
def
setUp
(
self
):
...
...
@@ -259,6 +279,7 @@ class StopWordTestQueryParser(TestQueryParserBase):
def
test306
(
self
):
self
.
failure
(
'stop AND NOT foo'
)
class
FakeStopWordRemover
:
def
process
(
self
,
list
):
...
...
@@ -268,7 +289,9 @@ class FakeStopWordRemover:
def
test_suite
():
return
TestSuite
((
makeSuite
(
TestQueryParser
),
makeSuite
(
StopWordTestQueryParser
),
makeSuite
(
TestInterfaces
),
))
if
__name__
==
"__main__"
:
main
(
defaultTest
=
'test_suite'
)
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