backdrop-contrib / search_api_solr

This module provides an implementation of the Search API which uses an Apache Solr search server for indexing and searching.
GNU General Public License v2.0
0 stars 4 forks source link

Search results show all index nodes #14

Open kswan opened 3 months ago

kswan commented 3 months ago

My search results are showing all indexed nodes regardless of the search text.

Also, this error is logged: User error: "0" is an invalid render array key in element_children() (line 7457 of /srv/www/core/includes/common.inc).

In this line https://github.com/backdrop-contrib/search_api_solr/blob/5c8a5fa0eafe8a8c2f6c17ecaeca10fa7bef424d/includes/service.inc#L1734 element_children() is called with an array containing a key->value where the value is the search string. element_children() throws an error when the value is not an array.

If I bypass the is_array() in https://github.com/backdrop/backdrop/blob/96a0e03870c9fd09ab4134827a05148173e8e516/core/includes/common.inc#L7448 , the error isn't thrown and the search results are correct.

kswan commented 3 months ago

PR submitted.

Since sort functionality in element_child() isn't used, the only effect of using that function is to omit array elements that begin with "#". I implemented that functionality without using element_child().

argiepiano commented 3 months ago

I have no way to test this as I don't have access to a SOLR server, but I was wondering if the patch should follow the pattern of the similar method in Search API flattenKeysArray() here: https://github.com/backdrop-contrib/search_api/blob/864e102a14417d550141df9c9f04d04a980871e5/includes/processor_highlight.inc#L290

At first sight the process the $keys variable in similar way.

kswan commented 3 months ago

Thank you for the comment. I reviewed the flattenKeysArray() method and I believe the context and objective are different.

The PR above addresses SearchApiSolrService -> flattenKeys() (extends SearchApiAbstractService), your comment references SearchApiHighlight -> flattenKeysArray() (extends SearchApiAbstractProcessor).

Both methods receive the argument as an array produced by SearchApiQueryInterface::getKeys().

The context is different in that SearchApiSolrService -> flattenKeys() is preparing the search keys to generate a search query. SearchApiHighlight -> flattenKeysArray() is used in post-processing the search results.

The objectives are different because SearchApiSolrService -> flattenKeys() is generating a query string that is passed to the Solr server. This query string includes conjunctions (AND, OR), grouping, and negation. SearchApiHighlight -> flattenKeysArray() is generating a simple flat array of terms.

Considering the different context and objectives, I think the differences between these two methods are logical.

argiepiano commented 3 months ago

Thanks @kswan. As I mentioned I have no way to test this, but perhaps the maintainer @earlyburg can do that? I'm not sure if @earlyburg is still active - the last release was done by someone in the @backdrop-contrib/bug-squad.

@earlyburg please indicate if you are still interested in maintaining. And perhaps @kswan you are interested in becoming a co-maintainer?