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

Unable to retrieve results using pysolr.search() with grouping #401

Open
2 of 3 tasks
prasadbattularaghavendra opened this issue May 22, 2023 · 2 comments
Open
2 of 3 tasks

Comments

@prasadbattularaghavendra
Copy link

prasadbattularaghavendra commented May 22, 2023

I have

  • Tested with the latest release
  • Tested with the current master branch
  • Searched for similar existing issues

Expected behavior

I expect to retrieve search results grouped by the specified field (sno) based on the provided query. The results should be similar to what I see in the Solr UI.

Actual behavior

No search results are returned. The results variable is empty.

Steps to reproduce the behavior

  1. Use pysolr library to connect to Solr instance.
  2. Execute the following search query with grouping in Python:
results = solr.search(query, **{"group": "true", "group_field": "sno", "group_offset": 0,
    "group_limit": 1, "group_sort": "date desc", "group_ngroups": "true", "rows": 1000})

Alternatively, I tried the query below which gives me:

_(HTTP 400): [Reason: invalid boolean value: True]_- 
results = solr.search(query, **{_"group":True_, "group_field": "sno", "group_offset": 0,
    "group_limit": 1, "group_sort": "date desc", _"group_ngroups": True,_ "rows": 1000})

Configuration

  • Operating system version: Windows 10
  • Search engine version:
  • Python version: 3.8
  • pysolr version: 3.9.0
@ch2ohch2oh
Copy link
Contributor

I've looked into this. There are two problems here: First pysolr converted python boolean true to True with a capital 'T', which solr won't take. Second issue is the grouping field parameter is called group.field not group_field. You can do a search here https://archive.apache.org/dist/lucene/solr/ref-guide/apache-solr-ref-guide-4.9.pdf

Unfortunately the code seems a bit tangled for me but it is not too hard to fix.

@acdha
Copy link
Collaborator

acdha commented Oct 16, 2023

Can someone contribute a working example for a perceived problem? pysolr doesn't do type-conversion at all: the search method passes the values through to safe_urlencode which on Python 3 calls the stdlib urlencode function.

That means that your values like "true" are not going to be modified but you do need to convert things which are not strings or numbers:

>>> pysolr.safe_urlencode({"group": "true", "group2": True, "group.field": "test_id"})
'group=true&group2=True&group.field=test_id'
>>> solr.search("title_full:*", **{"group": "true", "group2": True, "group.field": "test_id"})
<pysolr.Results object at 0x1076fcd90>
# Solr log: path=/select params={q=title_full:*&wt=json&group2=True&group.field=test_id&group=true}

pysolr tends to stay out of the type conversion business because it would require knowledge of your Solr instance and its configuration to know which fields should be converted and which should be left alone, and that knowledge lives at the application level.

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

3 participants