Skip to content

Instantly share code, notes, and snippets.

@stalsma
Forked from jpmckinney/proxy.php
Last active August 29, 2015 14:21

Revisions

  1. James McKinney revised this gist Mar 19, 2012. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions proxy.php
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    * http://code.google.com/p/solr-php-client/
    */

    require_once(dirname(__FILE__) .'/SolrPhpClient/Apache/Solr/Service.php');
    require_once(dirname(__FILE__) . '/SolrPhpClient/Apache/Solr/Service.php');

    solr_proxy_main();

    @@ -21,6 +21,8 @@
    function solr_proxy_main() {
    if (isset($_POST['query'])) {
    $params = array();
    $keys = '';
    $core = '';

    // The names of Solr parameters that may be specified multiple times.
    $multivalue_keys = array('bf', 'bq', 'facet.date', 'facet.date.other', 'facet.field', 'facet.query', 'fq', 'pf', 'qf');
    @@ -35,13 +37,16 @@ function solr_proxy_main() {
    elseif ($key == 'q') {
    $keys = $value;
    }
    elseif ($key == 'core') {
    $core = "$value/";
    }
    else {
    $params[$key] = $value;
    }
    }

    // Replace these arguments as needed.
    $solr = new Apache_Solr_Service('example.solrstuff.org', 80, '/solrjs/');
    $solr = new Apache_Solr_Service('example.solrstuff.org', 80, '/solrjs/' . $core);

    try {
    $response = $solr->search($keys, $params['start'], $params['rows'], $params);
  2. evolvingweb revised this gist Feb 11, 2010. 1 changed file with 4 additions and 9 deletions.
    13 changes: 4 additions & 9 deletions proxy.php
    Original file line number Diff line number Diff line change
    @@ -22,11 +22,14 @@ function solr_proxy_main() {
    if (isset($_POST['query'])) {
    $params = array();

    // The names of Solr parameters that may be specified multiple times.
    $multivalue_keys = array('bf', 'bq', 'facet.date', 'facet.date.other', 'facet.field', 'facet.query', 'fq', 'pf', 'qf');

    $pairs = explode('&', $_POST['query']);
    foreach ($pairs as $pair) {
    list($key, $value) = explode('=', $pair, 2);
    $value = urldecode($value);
    if (in_array($key, apachesolr_ajax_multivalue_keys())) {
    if (in_array($key, $multivalue_keys)) {
    $params[$key][] = $value;
    }
    elseif ($key == 'q') {
    @@ -50,11 +53,3 @@ function solr_proxy_main() {
    print $response->getRawResponse();
    }
    }

    /**
    * @return array The names of Solr parameters that may be specified multiple
    * times.
    */
    function apachesolr_ajax_multivalue_keys() {
    return array('bf', 'bq', 'facet.date', 'facet.date.other', 'facet.field', 'facet.query', 'fq', 'pf', 'qf');
    }
  3. evolvingweb revised this gist Feb 11, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions proxy.php
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,7 @@ function solr_proxy_main() {
    }
    }

    // Replace these arguments as needed.
    $solr = new Apache_Solr_Service('example.solrstuff.org', 80, '/solrjs/');

    try {
  4. evolvingweb revised this gist Feb 11, 2010. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions proxy.php
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,13 @@
    * @file
    * Implements a Solr proxy.
    *
    * Currently requires json_decode which is bundled with PHP >= 5.2.0,
    * Currently requires json_decode which is bundled with PHP >= 5.2.0.
    *
    * You must download the SolrPhpClient and store it in the same directory as this file.
    *
    * http://code.google.com/p/solr-php-client/
    */

    // @see http://code.google.com/p/solr-php-client/
    require_once(dirname(__FILE__) .'/SolrPhpClient/Apache/Solr/Service.php');

    solr_proxy_main();
  5. evolvingweb revised this gist Feb 8, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion proxy.php
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    solr_proxy_main();

    /**
    * <p>Executes the Solr query and returns the JSON response.</p>
    * Executes the Solr query and returns the JSON response.
    */
    function solr_proxy_main() {
    if (isset($_POST['query'])) {
  6. evolvingweb revised this gist Feb 8, 2010. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions proxy.php
    Original file line number Diff line number Diff line change
    @@ -47,14 +47,6 @@ function solr_proxy_main() {
    }
    }

    /**
    * @param string $param The value of a Solr parameter.
    * @return bool Whether the value includes local parameters.
    */
    function apachesolr_ajax_has_local_params($param) {
    return preg_match('/^\{/', $param);
    }

    /**
    * @return array The names of Solr parameters that may be specified multiple
    * times.
  7. evolvingweb revised this gist Feb 8, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions proxy.php
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@
    * Currently requires json_decode which is bundled with PHP >= 5.2.0,
    */

    // @see http://code.google.com/p/solr-php-client/
    require_once(dirname(__FILE__) .'/SolrPhpClient/Apache/Solr/Service.php');

    solr_proxy_main();
  8. evolvingweb created this gist Feb 8, 2010.
    63 changes: 63 additions & 0 deletions proxy.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    <?php

    /**
    * @file
    * Implements a Solr proxy.
    *
    * Currently requires json_decode which is bundled with PHP >= 5.2.0,
    */

    require_once(dirname(__FILE__) .'/SolrPhpClient/Apache/Solr/Service.php');

    solr_proxy_main();

    /**
    * <p>Executes the Solr query and returns the JSON response.</p>
    */
    function solr_proxy_main() {
    if (isset($_POST['query'])) {
    $params = array();

    $pairs = explode('&', $_POST['query']);
    foreach ($pairs as $pair) {
    list($key, $value) = explode('=', $pair, 2);
    $value = urldecode($value);
    if (in_array($key, apachesolr_ajax_multivalue_keys())) {
    $params[$key][] = $value;
    }
    elseif ($key == 'q') {
    $keys = $value;
    }
    else {
    $params[$key] = $value;
    }
    }

    $solr = new Apache_Solr_Service('example.solrstuff.org', 80, '/solrjs/');

    try {
    $response = $solr->search($keys, $params['start'], $params['rows'], $params);
    }
    catch (Exception $e) {
    die($e->__toString());
    }

    print $response->getRawResponse();
    }
    }

    /**
    * @param string $param The value of a Solr parameter.
    * @return bool Whether the value includes local parameters.
    */
    function apachesolr_ajax_has_local_params($param) {
    return preg_match('/^\{/', $param);
    }

    /**
    * @return array The names of Solr parameters that may be specified multiple
    * times.
    */
    function apachesolr_ajax_multivalue_keys() {
    return array('bf', 'bq', 'facet.date', 'facet.date.other', 'facet.field', 'facet.query', 'fq', 'pf', 'qf');
    }