Strange filter behavior

Issue #462 new
moritz.beber@gmail.com
created an issue

I see some strange behavior when using a search filter. Hopefully these two snippets show what I mean. I'm using Whoosh 2.7.4.

(1.) Snippet:

with search_iJP815._index.searcher() as search:
    res = search.search(_11, limit=None)
    print(len(res))
    print(res.scored_length())
    print(list(res))

(1.) Output:

16
16
[<Hit {'id': 'C0248_c', 'kind': 'metabolites'}>, <Hit {'id': 'C2190_c', 'kind': 'metabolites'}>, <Hit {'id': 'IR03964', 'kind': 'reactions'}>, <Hit {'id': 'C0048_c', 'kind': 'metabolites'}>, <Hit {'id': 'EC0048_c', 'kind': 'metabolites'}>, <Hit {'id': 'C0262_c', 'kind': 'metabolites'}>, <Hit {'id': 'EC0262_c', 'kind': 'metabolites'}>, <Hit {'id': 'C0186_c', 'kind': 'metabolites'}>, <Hit {'id': 'C1647_c', 'kind': 'metabolites'}>, <Hit {'id': 'C0044_c', 'kind': 'metabolites'}>, <Hit {'id': 'RR04161', 'kind': 'reactions'}>, <Hit {'id': 'IR00283', 'kind': 'reactions'}>, <Hit {'id': 'IR02232', 'kind': 'reactions'}>, <Hit {'id': 'IR08833', 'kind': 'reactions'}>, <Hit {'id': 'IR00265', 'kind': 'reactions'}>, <Hit {'id': 'IR04302', 'kind': 'reactions'}>]

So the first snippet works as I expect. However, when I introduce a filter, all results suddenly disappear.

(2.) Snippet:

allow = Term("kind", "metabolites")

with search_iJP815._index.searcher() as search:
    res = search.search(_11, filter=allow, limit=None)
    print(len(res))
    print(res.scored_length())
    print(res.filtered_count)
    print(list(res))

(2.) Output:

0
0
16
[]

Please note that in the first output there were plenty of hits with kind == "metabolites". So what am I doing wrong? The schema is the following, by the way.

import whoosh.fields as wfields

class SearchSchema(wfields.SchemaClass):
    """Describe the schema for indexing cobra objects."""

    id = wfields.ID(stored=True, unique=True, field_boost=2.0)
    name = wfields.NGRAM(maxsize=5)
    kind = wfields.STORED