whoosh-community / whoosh

Whoosh is a fast, featureful full-text indexing and searching library implemented in pure Python.
Other
252 stars 37 forks source link

Strange filter behavior #462

Open fortable1999 opened 7 years ago

fortable1999 commented 7 years ago

Original report by Moritz E. Beber (Bitbucket: midnighter, GitHub: midnighter).


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:

#!python

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:

#!python

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.

#!python

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
dorel14 commented 4 years ago

Hello , same for me , i'have in my schema a product column , and when i try to set up a filter on this all results disapears.