In the following code, I’m trying to add a plugin to the query_parser
(QueryParser
). The schema is already indexed and saved before the project started. However, I have an issue where the DerivationPlugin
does not apply to the query_parser
when using self._schema
.
self._schema
is loaded from the index during initialization.- When I create the parser using
self._schema
, theDerivationPlugin
is
not applied correctly during parsing. - If I create a new schema (
const_schema
) with the same fields asself._schema
, theDerivationPlugin
works as expected. - However, if I extract fields from
self._schema
and use them to create
a new schema, theDerivationPlugin
still does not work, even though
the fields are identical.
Here is the relevant code snippet:
class BasicSearchEngine:
def __init__(self, qdocindex, query_parser, main_field):
self._docindex = qdocindex
self._schema = self._docindex.get_schema()
fields = {name: field for name, field in self._docindex.get_schema().items()}
const_fields = {
'a_g': NUMERIC(stored=True, unique=False),
'a_l': NUMERIC(stored=True, unique=False),
'a_w': NUMERIC(stored=True, unique=False),
}
const_schema = Schema(**const_fields)
print(const_schema.items() == self._schema.items()) # True
const_schema_fields = {name: field for name, field in const_schema.items()}
print(const_schema_fields == fields) # True
self._parser = query_parser(main_field, self._schema, group=qparser.OrGroup)
self._parser.add_plugin(DerivationPlugin)
Why does the DerivationPlugin
not work with the parser when using self._schema
, but it works when a newly created schema is used, even though the fields are identical? How can I resolve this issue?