Plugin Directory

Changeset 1078386


Ignore:
Timestamp:
01/29/2015 05:31:54 PM (11 years ago)
Author:
naveenann
Message:

Improved Query Template

Location:
opensearchserver-search/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • opensearchserver-search/trunk/index.php

    r1078202 r1078386  
    169169  delete_option('oss_facets_option_hierarchical');
    170170  delete_option('oss_facets_option_hierarchical_taxonomy');
     171  delete_option('oss_query_behaviour');
     172  delete_option('oss_query_template');
    171173 
    172174  $taxonomies=get_taxonomies('','names');
  • opensearchserver-search/trunk/lib/oss_abstract.class.php

    r927584 r1078386  
    131131   * Will fail if more than 16 HTTP redirection
    132132   */
    133   protected function queryServer($url, $data = NULL, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT, $method = 'GET') {
     133  protected function queryServer($url, $data = NULL, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT, $method = 'GET',$api_version = 1) {
    134134
    135135    $this->lastQueryString = $url;
     
    139139    if($method === 'GET') {
    140140      curl_setopt($rcurl, CURLOPT_HTTP_VERSION, '1.0');
     141      if($api_version == 2) {
     142        curl_setopt($rcurl, CURLOPT_HTTPHEADER, array("Content-type: application/json; charset=utf-8"));
     143      }
    141144    }
    142145    curl_setopt($rcurl, CURLOPT_BINARYTRANSFER, TRUE);
     
    207210  }
    208211 
    209   protected function queryServerREST($path, $params = null, $data = null, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT, $method = 'GET') {
    210         return $this->queryServer($this->getQueryURL($path, $params), $data, $connexionTimeout, $timeout, $method);
     212  protected function queryServerREST($path, $params = null, $data = null, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT, $method = 'GET', $api_version = 1 ) {
     213        return $this->queryServer($this->getQueryURL($path, $params), $data, $connexionTimeout, $timeout, $method, $api_version);
    211214  }
    212215
  • opensearchserver-search/trunk/lib/oss_api.class.php

    r854646 r1078386  
    6969  const REST_API_AUTOCOMPLETION = 'services/rest/index/{index_name}/autocompletion/{autocompletion_name}?field={field_name}&rows={rows}';
    7070  const REST_API_AUTOCOMPLETION_BUILD = 'services/rest/index/{index_name}/autocompletion/{autocompletion_name}';
     71  const REST_API_SEARCH_TEMPLATE_LIST = 'services/rest/index/{index_name}/search/template';
    7172 
    7273
  • opensearchserver-search/trunk/lib/oss_searchtemplate.class.php

    r854646 r1078386  
    195195    return $return === FALSE ? FALSE : TRUE;
    196196  }
    197 
     197 
     198
     199  public function get_search_template_list() {
     200    $path_parameters = array(
     201        "{index_name}" => $this->index
     202    );
     203    $path = strtr(OssApi::REST_API_SEARCH_TEMPLATE_LIST, $path_parameters);
     204    $return = $this->queryServerREST($path,NULL,NULL, OssApi::DEFAULT_CONNEXION_TIMEOUT, OssApi::DEFAULT_QUERY_TIMEOUT,'GET',2);
     205    return json_decode($return)->templates;
     206  }
    198207}
    199208?>
  • opensearchserver-search/trunk/opensearchserver_admin.php

    r1078202 r1078386  
    4444  $autocompletion->createAutocompletion($autocompletion_name, 'autocomplete');
    4545  return TRUE;
     46}
     47
     48
     49function get_list_of_search_templates() {
     50  $search_template_instance = opensearchserver_getsearchtemplate_instance();
     51  return $search_template_instance->get_search_template_list();
    4652}
    4753
     
    718724    update_option('oss_facet', $facets);
    719725   
     726    $oss_write_query = isset($_POST['oss_write_query']) ? $_POST['oss_write_query'] : 1;
     727    update_option('oss_query_behaviour', $oss_write_query);
     728    $oss_query_template = isset($_POST['oss_query_template']) ? $_POST['oss_query_template'] : NULL;
     729    update_option('oss_query_template', $oss_query_template);
    720730    $oss_multi_filter = isset($_POST['oss_multi_filter']) ? $_POST['oss_multi_filter'] : NULL;
    721731    update_option('oss_multi_filter', $oss_multi_filter);
     
    738748    $oss_advanced_facets = isset($_POST['oss_advanced_facets']) ? $_POST['oss_advanced_facets'] : NULL;
    739749    update_option('oss_advanced_facets', $oss_advanced_facets);
    740     $oss_facet_max_display = isset($_POST['oss_facet_max_display']) ? $_POST['oss_facet_max_display'] : NULL;
     750      $oss_facet_max_display = isset($_POST['oss_facet_max_display']) ? $_POST['oss_facet_max_display'] : NULL;
    741751    update_option('oss_facet_max_display', $oss_facet_max_display);
    742752    $oss_sort_timestamp = isset($_POST['oss_sort_timestamp']) ? $_POST['oss_sort_timestamp'] : NULL;
     
    957967                        <form id="query_settings" name="query_settings" method="post"
    958968                            action="">
     969                        <strong>Query Behaviour</strong>
     970                            <p>
     971                                  <input type="radio" id="oss_write_query"
     972                                        value="1" name="oss_write_query"
     973                                        <?php
     974                                        $oss_write_query = isset($_POST['oss_write_query']) ? $_POST['oss_write_query'] : 1;
     975                                        checked( 1 == $oss_write_query); ?>  />
     976                                    <label for="oss_write_query_enable">Write Query</label>
     977                                    <input type="radio" id="oss_existing_query_template"
     978                                        value="2" name="oss_write_query"
     979                                        <?php checked( 2 == get_option('oss_query_behaviour')); ?>  />
     980                                    <label for="oss_existing_query_template_enabled">Use an existing query template</label>
     981                              </p>
     982
    959983                            <fieldset><legend>Query template</legend>
    960                            
     984                                         <div id="oss-query-write-template">
    961985                            <p>Enter the template query, or leave empty to use the default one</p>
    962986                            <p> <label for="oss_query">OpenSearchServer query template</label>:<br />
     
    9761000                                <p>For allowing search into a new field simply add it to the query, for example <code>OR custom_field_favorite_fruits:($$)^5</code>. <code>^5</code> gives a weight of 5 to this field.
    9771001                            </div>
     1002                      </div>
     1003                      <div id="oss-query-select-template">
     1004                          <p>
     1005                            <strong>Select query template</strong>
     1006                            <select name="oss_query_template" id="oss_query_template">
     1007                            <option value="none">Select </option>
     1008                            <?php
     1009                            $templates = get_list_of_search_templates();
     1010                            foreach($templates as $template) {
     1011                              ?>
     1012                              <option value="<?php print $template->name;?>"><?php print $template->name.' (Type '.$template->type.')';?></option>
     1013                              <?php
     1014                            }
     1015                            ?>
     1016                           
     1017                            </select>
     1018                          </p>
     1019                          </div>
    9781020                            </fieldset>
    9791021                            <fieldset><legend>Facets</legend>
     
    15161558    jQuery('#oss_log_enable').click(function(e) { jQuery('#oss_logs_custom').toggle();});
    15171559    jQuery('#oss_filter_language_wpml').click(function(e) { jQuery('#oss_filter_language_field').toggle();});
     1560    jQuery('#oss_write_query').click(function(e) {jQuery('#oss-query-select-template').hide();jQuery('#oss-query-write-template').show();});
     1561    jQuery('#oss_existing_query_template').click(function(e) {jQuery('#oss-query-write-template').hide();jQuery('#oss-query-select-template').show();});
     1562    if(jQuery('#oss_existing_query_template').is(":checked")) {jQuery('#oss-query-write-template').hide();jQuery('#oss-query-select-template').show();}
     1563    else {jQuery('#oss-query-select-template').hide();jQuery('#oss-query-write-template').show();}
    15181564</script>
    15191565<?php
  • opensearchserver-search/trunk/opensearchserver_search_functions.php

    r1078202 r1078386  
    172172          opensearchserver_add_filter($search, $fieldToFilterOn, ICL_LANGUAGE_CODE);
    173173      }
    174      
    175       $oss_query = $search->query($query)->template('search');
     174      if(get_option('oss_query_behaviour') == 2) {
     175        $oss_query = $search->query($query)->template(get_option('oss_query_template'));
     176      }else {
     177        $oss_query = $search->query($query)->template('search');
     178      }
    176179      if(get_query_var('sort')) {
    177180        if(get_query_var('sort') == '+date') {
Note: See TracChangeset for help on using the changeset viewer.