Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr return all results when q=<empty>

I am using PHP Codeigniter framework with solr-php-client to build a search application.

I have two pages -

  1. a search page with just a single input box
  2. a results page which will display results when user enters a search term in search page

The issue is, unless I enter a search term solr-php-client is not returning any results and for which the url would just be "http://localhost:8080/search/?q=" and it wont do anything. But when I enter a search term such as "apple" as an eg., it redirect to results page with matching results without any issue and the url becomes "http://localhost:8080/rdsearch/?q=apple"

What I would like to achieve is - When user does not enter a search term in the search page or when q is empty as in "http://localhost:8080/search/?q=", it should simply direct to results page and show all the results (similar to a solr query *:*)

like image 666
sunskin Avatar asked Feb 23 '26 20:02

sunskin


1 Answers

There might be some other solutions available, I can propose you the following 2 solutions.

  1. You can check your input box. If it's empty, by default pass *:* as input with the Solr URL.
  2. Or you can modify your solrconfig.xml for the select request handler. Put

<str name="q.alt">*:*</str>

While querying

http://'localhost':8080/solr/collection1/select?q=&wt=xml&indent=true&defType=dismax

You can see though I've provided q= , but it'll return all the result. Because it'll take the q.alt query as the query parser is Dismax now. For further info please read here

like image 134
buddy86 Avatar answered Feb 25 '26 10:02

buddy86



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!