collective / collective.solr

Solr search engine integration for Plone
https://pypi.org/project/collective.solr/
22 stars 46 forks source link

Compatibility to managed-schema #260

Open NicolasGoeddel opened 4 years ago

NicolasGoeddel commented 4 years ago

Hi,

I want to suggest a small change for this line: https://github.com/collective/collective.solr/blob/52cb3eadcd9320f17d89e578740d8e85c69e2551/src/collective/solr/solr.py#L332

If you replace it with the following line collective.solr will automatically work with a managed-schema which seems to be the default since Solr 8.5.

schema_url = "%s/schema?wt=schema.xml"

See also https://lucene.apache.org/solr/guide/8_5/schema-api.html#retrieve-schema-examples and scroll down a bit.

tisto commented 4 years ago

@NicolasGoeddel I thought about this as well. Though, this means that we would have to drop support for older versions of Solr, right?

NicolasGoeddel commented 4 years ago

I don't think so. That API was already available in Solr 6.6.: https://lucene.apache.org/solr/guide/6_6/schema-api.html#SchemaAPI-RetrievetheEntireSchema

At least that was the oldest documentation I could find on that page. There are also PDF version available for Solr prior to version 6.6 but I did not take at look at these: http://archive.apache.org/dist/lucene/solr/ref-guide/

NicolasGoeddel commented 4 years ago

It seems there are some new issues now. Some attributes can not be found: https://github.com/collective/collective.solr/blob/52cb3eadcd9320f17d89e578740d8e85c69e2551/src/collective/solr/search.py#L156 AttributeError: indexed https://github.com/collective/collective.solr/blob/52cb3eadcd9320f17d89e578740d8e85c69e2551/src/collective/solr/parser.py#L228 AttributeError: stored

This happens because the retrieved schema does not add the indexed and stored attribute to the <field> nodes. At the moment I don't know how to make it work. Maybe I should use the normal schema instead. When I remember right there was something with kitconcept.recipe.solr or so. I have to take a look at this. Never used it.

NicolasGoeddel commented 4 years ago

Or for the moment this solution seems to work but is more like an hack: https://github.com/collective/collective.solr/blob/52cb3eadcd9320f17d89e578740d8e85c69e2551/src/collective/solr/parser.py#L158 Change it to:

class SolrField(AttrDict):
    """ a schema field representation """

    def __init__(self, *args, **kw):
        self["required"] = False
        self["multiValued"] = False
        self["indexed"] = True # added
        self["stored"] = True  # added
        super(SolrField, self).__init__(*args, **kw)
tisto commented 4 years ago

@NicolasGoeddel you do not have to use kitconcept.recipe.solr (we don't use it in production at all). You could use that as a starting point or copy over the schema configuration though.