solariumphp / solarium

PHP Solr client library
Other
933 stars 302 forks source link

Option to configure "/solr" in base-path #938

Closed jschultze closed 3 years ago

jschultze commented 3 years ago

When using Solarium in a recent project, I needed to connect to a Solr instance that is using /index instead of /solr in the url. As far as I can see, there's no way to configure or change this base-path when setting up a Solarium-client. In fact, it seems that /solr has been hardcoded with version 2 of the API.

An option to change this setting, while keeping the default as /solr, would improve the usability of Solarium.

thomascorthals commented 3 years ago

This was discussed in #853. It will get implemented someday. In the meantime, you can work around it by extending the cURL adapter. Override createHandle with a method that calls the parent and then replaces the path of the URI for the handle before returning it.

jschultze commented 3 years ago

Thanks for the info and sorry for the double post! I extended the Endpoint for now but will have a look if the suggested extension of the cURL adapter works better.

thomascorthals commented 2 years ago

Since Solarium 6.2.1, this can be done without workarounds by adding a context to the endpoint configuration. It will default to solr if omitted.

$config = [
    'endpoint' => [
        'localhost' => [
            'scheme' => 'http', # or https
            'host' => '127.0.0.1',
            'port' => 8983,
            'path' => '/',
            'context' => 'index',
            'core' => 'techproducts', # or collection
        ]
    ]
];
jschultze commented 2 years ago

Thanks a lot for the addition of this configuration setting!