- Issue created by @gaspounet
- π«π·France gaspounet
By digging a little more it turns out that the problem comes in fact from the quotation marks used in the query
fq=itm_test_id:("10"+"13") <== NOT WORKING
fq=itm_test_id:(10+13) <== OK !
Is there a way to check that the value is numeric and in this case treat it as such ?
- π«π·France gaspounet
Well me, it's nice talking to myself
A credit to dementiaβMegadeth, Sweating Bullets
OK so the problem was coming from the modification I made in my solrconfig_extra.xml file:
<requestHandler name="/select" class="solr.SearchHandler"> <lst name="defaults"> <str name="defType">lucene</str> ... <str name="q.op">AND</str> </lst> ... </requestHandler>
If I remove the "q.op" parameter to let the operator by default for query expressions (operator "OR"), it is working as expected...
In the first place I set this parameter to "AND" to suit my needs for my fulltext filters: I want only results were we can find all the words in the search phrases typed by the user without the user having to separate them manually with the keywords "AND" or "&&" which is not working for my views where I use the direct parsing mode which ignores the operator "contains all words".
- π«π·France gaspounet
And so, in order to obtain the results I'm looking for using taxonomy IDs exposed filters alongside fulltext fields using the direct parse mode and the "contains all words" operator, I need to rewrite the query thanks to a hook function:
function MYMODULE_views_query_alter( $view, $query ) { switch( $view -> id() ) { case 'my_solr_index_view': //Get the fulltext search value when using direct parse mode $cleanKeys = " " . $query -> getKeys(); //remove all quotes if there is an odd number of quotes if ( substr_count( $cleanKeys, '"' ) % 2 !== 0 ) { $cleanKeys = str_replace( "\"", " ", $cleanKeys ); } //Remove all parentheses if the number of open parentheses does not match the number of closed parentheses if ( substr_count( $cleanKeys, '(' ) != substr_count( $cleanKeys, ')' ) ) { $cleanKeys = str_replace( "(", " ", $cleanKeys ); $cleanKeys = str_replace( ")", " ", $cleanKeys ); } //Clean operator keywords $cleanKeys = str_replace( "+", " AND ", $cleanKeys ); $cleanKeys = str_replace( "&&", " AND ", $cleanKeys ); $cleanKeys = str_replace( "||", " OR ", $cleanKeys ); $cleanKeys = str_replace( "\"", " \" ", $cleanKeys ); $cleanKeys = str_replace( " -", " NOT ", $cleanKeys ); $cleanKeys = trim( preg_replace( '/\s+/', ' ', $cleanKeys ) ); $cleanKeys = preg_replace( "/^(AND |OR |NOT )/", "* $1", $cleanKeys ); //Loop through the query in order to add the "AND" operator between words when the operator is not explicitly written and when we are not looking for exact match $solrBooleans = [ "AND", "OR", "NOT" ]; $newKeys = []; $previousKey = ""; $exactWord = false; foreach ( explode( " ", $cleanKeys ) as $key ) { if ( $key == "\"" ) { $exactWord = !$exactWord; $newKeys[] = $key; } else { if ( $exactWord || !$previousKey || in_array( $key, $solrBooleans ) || in_array( $previousKey, $solrBooleans ) ) { $newKeys[] = $key; } else { $newKeys[] = "AND"; $newKeys[] = $key; } } $previousKey = $key; } $query -> keys( implode( " ", $newKeys ) ); break; } }
Please let me know if there is a better way (sure there is!).
- π©πͺGermany mkalkbrenner π©πͺ
The problem is that you manipulated the default operator and set it to AND.
The internal query builder of the module doesn't know that and builds all queries and filter queries for a OR as default operator.
Setting it to AND is not supported by this module. But "contains all" should build the correct query. - Status changed to Fixed
over 1 year ago 2:28pm 10 August 2023 Automatically closed - issue fixed for 2 weeks with no activity.