Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/moin/items/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from urllib.parse import unquote

from whoosh.query import Term, Prefix, And, Or, Not
from whoosh.query import Term, Prefix, And, Or, Not, NullQuery

from moin import current_app, flaskg, log
from moin.constants.chartypes import CHARS_UPPER, CHARS_LOWER
Expand Down Expand Up @@ -1425,8 +1425,15 @@ def build_index_query(self, startswith=None, selected_groups=None, isglobalindex
isglobalindex: ???

Output:
Returns a whoosh.query.Prefix object for the input parameters
Returns a whoosh.query.Prefix object for the input parameters,
or a NullQuery matching nothing when the item has no subitem
prefixes (e.g. an index rooted at an itemid that matches nothing).
"""
if not isglobalindex and not self.subitem_prefixes:
# an item addressed by something other than a name, such as a
# nonexistent itemid, has no names and thus no subitem prefixes;
# no stored item can be one of its subitems
return NullQuery()
prefix = "" if isglobalindex else self.subitem_prefixes[0]
if startswith:
query = Prefix(NAME_EXACT, prefix + startswith) | Prefix(NAME_EXACT, prefix + startswith.swapcase())
Expand Down
9 changes: 9 additions & 0 deletions src/moin/items/_tests/test_Item.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ def testIndex(self):
fix_files, fix_builds = fix_meta(files, builds)
assert fix_files == fix_builds

def testIndexMissingItemid(self):
# an index rooted at an itemid that matches nothing has no names,
# so there are no subitem prefixes; it must yield an empty index
# rather than crash on subitem_prefixes[0]
item = Item.create("@itemid/" + "0" * 32)
assert isinstance(item, NonExistent)
assert item.names == []
assert item.get_index() == ([], [])

def test_meta_filter(self):
name = "Test_item"
contenttype = "text/plain;charset=utf-8"
Expand Down
Loading