Change request method to POST for queries

  • HaikoG
    Participant
    # 2 years, 5 months ago

    Hi,

    We have some large queries due to category exclusions for the default product searches. This means we dynamically add a lot of categories to the query before the query is executed. This causes the query to exceed the URI length limit and throws an error.
    My guess is that this query uses a GET method as these are limited by length. Can you tell me if there is a way to change this to a POST request? and if so, how?

    Uncaught Exception: Solr HTTP error: OK (414)
    <h1>Bad Message 414</h1>

    reason: URI Too Long

    in /mnt/datadrive/public_html/testshop.switch.nl/wp-content/plugins/wpsolr-pro/wpsolr/core/vendor/solarium/solarium/library/Solarium/Core/Query/Result/Result.php on line 106

    wpsolr
    Keymaster
    # 2 years, 5 months ago
    wpsolr
    Keymaster
    HaikoG
    Participant
    # 2 years, 5 months ago

    Thanks for the quick reply
    I think the postbigrequest-plugin is what we’re after, but I haven’t figured out how to activate it yet.

    getPlugin(‘postbigrequest’);
    According to the documentation that should be called on the solarium client, but the obj from get_solr_client does not recognize the function

    $solr_client = WPSOLR_Service_Container::get_solr_client( false );

    any ideas?

    wpsolr
    Keymaster
    # 2 years, 5 months ago

    Try this one:

    add_action( 'init', function () {
    
    	if ( defined( 'WPSOLR_PLUGIN_SHORT_NAME' ) ) {
    		/**
    		 *
    		 * Set post method on Solarium client.
    		 *
    		 * @param array $parameters
    		 *
    		 */
    		function wpsolr_solarium_query_set_post_method( $parameters ) {
    
    		/* @var WPSOLR_AbstractSearchClient $search_engine_client */
    		$client = $parameters[ WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY__PARAM_SOLARIUM_CLIENT ];
    		$client->get_search_engine_client()->getPlugin('postbigrequest');
    		}
    
    		// Catch Solarium query before calling Solr
    		add_action( WpSolrFilters::WPSOLR_ACTION_SOLARIUM_QUERY, 'wpsolr_solarium_query_set_post_method', 10, 1 );
    	}
    } );
    HaikoG
    Participant
    # 2 years, 5 months ago

    Awesome! that works like a charm!

    Thanks

    wpsolr
    Keymaster
    # 2 years, 5 months ago

    Great.

    I moved this topic in the “Request a feature” forum. I will add a checkbox on Solr indexes to force POST queries instead of default “GET” queries.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.