Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commitWithin for Solr.add is ignored when JSON update API is used (when no boost or fieldUpdates) #422

Closed
eukaryote opened this issue Sep 1, 2023 · 1 comment

Comments

@eukaryote
Copy link
Contributor

Expected behaviour

Calling Solr.add without boost with a commitWithin value should still result in commitWithin being used for the Solr update.

Actual behaviour

As of version 3.9.0, the commitWithin is sent to Solr if the XML API is used but not if the JSON API is used, which happens if the boost arg to add is not provided.

Steps to reproduce the behaviour

Run the following against master, which uses a mock to verify that commitWithin is included in the XML API request but not for the JSON API request:

from unittest.mock import patch, MagicMock

import pysolr


solr = pysolr.Solr("http://pysolr.test/")


# `commitWithin` is not included for the JSON API:
with patch.object(solr, "get_session") as mock:
    mock().post.return_value = MagicMock(status_code=200)
    solr.add([{"id": "doc1", "foo": "bar"}], commitWithin="1000")
mock().post.assert_called_once_with(
    'http://pysolr.test/update/',
    data=b'[{"id": "doc1", "foo": "bar"}]',
    headers={'Content-type': 'application/json; charset=utf-8'},
    files=None,
    timeout=60,
    auth=None,
)

# `commitWithin` is included in the XML doc for the XML API:
with patch.object(solr, "get_session") as mock:
    mock().post.return_value = MagicMock(status_code=200)
    solr.add([{"id": "doc1", "foo": "bar"}], commitWithin="1000", boost={"foo": 2.0})
mock().post.assert_called_once_with(
    'http://pysolr.test/update/',
    data=b'<add commitWithin="1000"><doc><field name="id">doc1</field><field name="foo" boost="2.0">bar</field></doc></add>',
    headers={'Content-type': 'text/xml; charset=utf-8'},
    files=None,
    timeout=60,
    auth=None,
)

I made a start on an update that switches to including the commitWithin in the URL for both JSON and XML. This simplifies things compared to including it in the message body, because to do that for the JSON API, you'd have to switch from the structure that you're currently using (a list of docs) to a different structure (such as a dict), because the list of docs format doesn't seem to provide any way to specify commitWithin.

See pull request: #421

Configuration

  • Operating system version: Ubuntu 20.04.6 LTS
  • Search engine version: 4.10.4 (Test version)
  • Python version: 3.10.11
  • pysolr version: master as of 30a2c01
@eukaryote
Copy link
Contributor Author

PR #421 was merged, so closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant