Question

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 *:*)

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top