Plugin Directory

Changeset 602348


Ignore:
Timestamp:
09/22/2012 02:44:19 PM (13 years ago)
Author:
ekeller
Message:

Version 1.0.9

Location:
opensearchserver-search/trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • opensearchserver-search/trunk/css/oss-style.css

    r601998 r602348  
    11/* OpenSearchServer result page */
    2 
    32#oss-quick-open {
    4     font-size: 12px;
    5 }
    6 #oss-content {
    7     font-size: 12px;
    8     color:#222222;
    9 }
    10 #oss-title {
    11     font-size: 12px;
    12     color:#1122CC;
    13 }
    14 #oss-url {
    15     font-size: 12px;
    16     color:#009933;
    17 }
    18 #oss-no-of-doc {
    19     padding-left:200px;
    20     padding-bottom:15px;
    21 }
    22 #oss-results {
    23     padding-left:200px;
    24 }
    25 #oss-result {
    26     padding-bottom:15px;
     3    font-size: 100%;
    274}
    285
    29 #oss-filter{
    30     margin:0;
    31     padding:0;
    32     clear:both;
    33     float:left;
    34     margin-right:10px;
     6.oss-content {
     7    font-size: 100%;
     8    color: #222222;
     9}
     10
     11.oss-title {
     12    font-size: 110%;
     13    color: #1122CC;
     14}
     15
     16.oss-url {
     17    font-size: 90%;
     18    color: #009933;
     19}
     20
     21#oss-no-of-doc {
     22    padding-left: 200px;
     23    padding-bottom: 15px;
     24}
     25
     26#oss-results {
     27    padding-left: 200px;
     28}
     29
     30.oss-result {
     31    padding-bottom: 10px;
     32}
     33
     34#oss-filter {
     35    margin: 0;
     36    padding: 0;
     37    clear: both;
     38    float: left;
     39    margin-left: 5px;
     40    margin-right: 5px;
    3541    width: 180px;
    3642}
    37 #oss-filter-not-selected a{
    38 font-size:11px;
     43
     44.oss-filter-title {
     45    font-size: 110%;
    3946}
    40 #oss-filter-selected a{
    41     color: #DD4B39;
    42     cursor: pointer;
    43     font-size:11px;
     47
     48.oss-bold {
     49    font-weight: bold;
    4450}
     51
    4552#oss-paging {
    4653    margin: 0;
    47         padding: 0;
    48     text-align: center; 
     54    padding: 0;
     55    text-align: center;
    4956}
    5057
     58#oss-search-form #keyword {
     59    border: 1px solid #ccc;
     60    width: 570px;
     61    height: 25px;
     62}
    5163
    52 #oss-search-form #keyword{
    53     border:1px solid #ccc;
    54     width:570px;
    55     height:25px;
    56     -webkit-box-shadow: 0px 0px 4px #4195fc;
    57     -moz-box-shadow: 0px 0px 4px #d8d9d9;
    58     box-shadow: 0px 0px 4px #d8d9d9;
     64#oss-submit {
     65    background-color: #4D90FE;
     66    border: 1px solid #3079ED;
     67    color: #FFFFFF;
     68    border-bottom-left-radius: 3px;
     69    border-bottom-right-radius: 3px;
     70    border-top-left-radius: 3px;
     71    border-top-right-radius: 3px;
     72    cursor: default;
     73    display: inline-block;
     74    font-weight: bold;
     75    height: 31px;
     76    min-width: 54px;
     77    padding: 0 8px;
     78    margin-left: 10px;
     79    text-align: center;
     80    text-decoration: none;
    5981}
    60 #oss-submit {
    61     background-color:#4D90FE;
    62     background-image:-webkit-linear-gradient(top, #4D90FE, #4787ED);
    63     border:1px solid #3079ED;
    64     color:#FFFFFF;
    65      -webkit-user-select:none;
    66     border-bottom-left-radius:3px;
    67     border-bottom-right-radius:3px;
    68     border-top-left-radius:3px; 
    69     border-top-right-radius:3px;
    70     cursor:default;
    71     display:inline-block;
    72     font-weight:bold;
    73     height:31px;
    74     min-width:54px;
    75     padding:0 8px; 
    76     margin-left:10px;
    77      text-align:center;
    78     text-decoration:none;
     82
     83#oss-search-form form {
     84    padding-left: 200px;
    7985}
    80 #oss-search-form form{
    81     padding-left:200px;
     86
     87#oss-search {
     88    width: 100%;
     89    font-size: 100%;
     90    font-style: normal;
     91    font-size-adjust: none;
    8292}
    83 #oss-search {
    84     width:960px;
    85     font-family:arial,sans-serif;
    86     font-size:13px;
    87     font-weight:400;
    88     font-style:normal;
    89     font-size-adjust:none;
    90     margin-left:20px;
    91   }
    9293
    93 .autocomplete_link {
    94     font-size: 12px;
     94.oss-autocomplete_link {
     95    font-size: 100%;
    9596    background-color: #FFFFFF;
    9697    padding: 2px 6px 2px 6px;
    9798}
    9899
    99 .autocomplete_link_over {
    100     font-size: 12px;
     100.oss-autocomplete_link_over {
     101    font-size: 100%;
    101102    background-color: #99BBFF;
    102103    padding: 2px 6px 2px 6px;
    103104}
    104105
    105 #autocomplete {
     106#oss-autocomplete {
    106107    margin: 0;
    107108    width: 380px;
     
    110111}
    111112
    112 #autocompletelist {
     113#oss-autocompletelist {
    113114    background-color: #FFFFFF;
    114115    text-align: left;
    115116    z-index: 1000;
    116     position:absolute;width: 380px;
     117    position: absolute;
     118    width: 380px;
    117119    border: 1px solid #99BBFF;
    118120}
     121
    119122#oss-page {
    120     padding-left:10px;
    121 }
    122 .autocomplete_link {
    123     font-size: 12px;
    124     background-color: #FFFFFF;
    125     padding: 2px 6px 2px 6px;
     123    padding-left: 10px;
    126124}
    127125
    128 .autocomplete_link_over {
    129     font-size: 12px;
    130     background-color: #99BBFF;
    131     padding: 2px 6px 2px 6px;
    132 }
    133  
    134  
    135 #oss-image img{
    136     -webkit-transform:scale(0.8);
    137     -moz-transform:scale(0.8);
    138     -o-transform:scale(0.8);
    139     -webkit-transition-duration: 0.5s;
    140     -moz-transition-duration: 0.5s;
    141     -o-transition-duration: 0.5s;
    142     margin: 0 10px 5px 0;
    143     max-width: 170px;
    144     max-height: 130px;
    145     width: expression(this.width > 170 ? "170px" : true);
    146     height: expression(this.height > 130 ? "130px" : true);
    147 }
    148  
    149 #oss-image img:hover{
    150     -webkit-transform:scale(1.1);
    151     -moz-transform:scale(1.1);
    152     -o-transform:scale(1.1);
    153     box-shadow:0px 0px 30px gray;
    154     -webkit-box-shadow:0px 0px 30px gray;
    155     -moz-box-shadow:0px 0px 30px gray;
    156 }
    157126#oss-facets-menu {
    158127    vertical-align: middle;
    159     margin:0;
    160     list-style:none;
     128    margin: 0;
     129    list-style: none;
    161130}
     131
    162132#oss-facets {
    163     padding-top:10px;
     133    padding-top: 10px;
    164134}
    165 .oss-facets-li a{
     135
     136.oss-facets-li a {
    166137    color: #222222;
    167138}
     139
    168140.oss-facets-li {
    169     padding-left:10px;
    170     margin-top:0;
     141    padding-left: 10px;
     142    margin-top: 0;
    171143}
     144
    172145#oss-facets-menu li:hover {
    173     background:#EEEEEE;
     146    background: #EEEEEE;
    174147}
     148
    175149#oss-facets-menu li a {
    176     text-decoration:none;
     150    text-decoration: none;
    177151}
    178  
    179 .oss-submenu{
     152
     153.oss-submenu {
    180154    display: none;
    181155    list-style: none;
    182     padding-left:15px;
    183     margin:0;
     156    padding-left: 15px;
     157    margin: 0;
    184158}
     159
    185160.oss-top-nav  a {
    186     color:#000000;
     161    color: #000000;
    187162}
     163
    188164#oss-menu-selected  a {
    189165    color: #DD4B39;
    190166    cursor: pointer;
    191167}
     168
    192169#oss-head a {
    193     font-size:16px;
     170    font-size: 120%;
    194171    color: #1122CC;
    195     margin-top:0;
    196     clear:both;
     172    margin-top: 0;
     173    clear: both;
    197174}
     175
    198176#oss-nav {
    199177    list-style: none;
    200     margin:0;
    201     padding-right:7px;
    202     padding-top:10px;
    203     padding-bottom:10px;
    204     border-bottom:1px solid #ccc;
    205  }
    206 #oss-nav li {
    207     padding-left:10px;
    208 }
    209 #oss-nav li a {
    210     text-decoration:none;
    211 }
    212 #oss-nav li:hover {
    213     background:#EEEEEE;
    214    
    215 }
    216 #oss-image-result {
    217     padding-top:40px;
     178    margin: 0;
     179    padding-right: 7px;
     180    padding-top: 10px;
     181    padding-bottom: 10px;
     182    border-bottom: 1px solid #ccc;
    218183}
    219184
    220 
    221 #ibox{
    222     position:absolute;
    223     overflow-y:none;
    224     background:#fff;
    225     z-index:1001;
    226     display:none;
    227     padding:4px;
    228     -webkit-box-shadow: 0px 0px 6px 0px #bbb;
    229     -moz-box-shadow: 0px 0px 6px 0px #bbb;
    230     box-shadow: 0px 0px 6px 0px #bbb;
    231 }
    232 #ibox img{
    233    max-width: 250px;
    234   max-height: 210px;
    235   width: expression(this.width > 250 ? "250px" : true);
    236   height: expression(this.height > 210 ? "210px" : true);
    237   margin:5px;
    238   padding:0px;
    239 }
    240 #ibox br{
    241     clear:both;
    242 }​
    243 
    244 /*
    245     ColorBox Core Style:
    246     The following CSS is consistent between example themes and should not be altered.
    247 */
    248 #colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;}
    249 #cboxOverlay{position:fixed; width:100%; height:100%;}
    250 #cboxMiddleLeft, #cboxBottomLeft{clear:left;}
    251 #cboxContent{position:relative;}
    252 #cboxLoadedContent{overflow:auto;}
    253 #cboxTitle{margin:0;}
    254 #cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
    255 #cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
    256 .cboxPhoto{float:left; margin:auto; border:0; display:block; max-width: none;}
    257 .cboxIframe{width:100%; height:100%; display:block; border:0;}
    258 #colorbox, #cboxContent, #cboxLoadedContent{box-sizing:content-box;}
    259 
    260 /*
    261     User Style:
    262     Change the following styles to modify the appearance of ColorBox.  They are
    263     ordered & tabbed in a way that represents the nesting of the generated HTML.
    264 */
    265 #cboxOverlay{background:#000;}
    266 #colorbox{}
    267     #cboxContent{margin-top:20px;}
    268         .cboxIframe{background:#fff;}
    269         #cboxError{padding:50px; border:1px solid #ccc;}
    270         #cboxLoadedContent{border:5px solid #000; background:#fff;}
    271         #cboxTitle{position:absolute; top:-20px; left:0; color:#ccc;}
    272         #cboxCurrent{position:absolute; top:-20px; right:0px; color:#ccc;}
    273         #cboxSlideshow{position:absolute; top:-20px; right:90px; color:#fff;}
    274         #cboxPrevious{position:absolute; top:50%; left:5px; margin-top:-32px; background:url(../images/controls.png) no-repeat top left; width:28px; height:65px; text-indent:-9999px;}
    275         #cboxPrevious:hover{background-position:bottom left;}
    276         #cboxNext{position:absolute; top:50%; right:5px; margin-top:-32px; background:url(../images/controls.png) no-repeat top right; width:28px; height:65px; text-indent:-9999px;}
    277         #cboxNext:hover{background-position:bottom right;}
    278         #cboxLoadingOverlay{background:#000;}
    279         #cboxLoadingGraphic{background:url(../images/loading.gif) no-repeat center center;}
    280         #cboxClose{position:absolute; top:5px; right:5px; display:block; background:url(../images/controls.png) no-repeat top center; width:38px; height:19px; text-indent:-9999px;}
    281         #cboxClose:hover{background-position:bottom center;}
    282 
    283  
    284 div.popphoto {
    285     padding: 0;
    286     position: relative;
    287     display: inline-block;
    288     #display: inline;
    289 }
    290 div.popphoto img {
    291       max-width: 170px;
    292       max-height: 130px;
    293       width: expression(this.width > 170 ? "170px" : true);
    294       height: expression(this.height > 130 ? "130px" : true);
    295       margin:10px;
     185#oss-nav li {
     186    padding-left: 10px;
    296187}
    297188
    298 div.popphoto img:hover {
    299     -moz-box-shadow: 2px 2px 4px #222222;
    300     -webkit-box-shadow: 2px 2px 4px #222222;
    301     box-shadow: 2px 2px 4px #222222;
    302     /* For IE 8 */
    303     -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color='#222222')";
    304     /* For IE 5.5 - 7 */
    305     filter: progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color='#222222');
     189#oss-nav li a {
     190    text-decoration: none;
    306191}
    307192
    308 div.POPPER_popper {
    309     position: absolute;
    310     #position: fixed;
    311     display: block;
    312     background-color: #ffffff;
    313     top: 0px;
    314     left: 0px;
    315    
    316     -moz-box-shadow: 2px 2px 4px #222222;
    317     -webkit-box-shadow: 2px 2px 4px #222222;
    318     box-shadow: 2px 2px 4px #222222;
    319     /* For IE 8 */
    320     -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color='#222222')";
    321     /* For IE 5.5 - 7 */
    322     filter: progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color='#222222');
     193#oss-nav li:hover {
     194    background: #EEEEEE;
    323195}
    324 div.POPPER_popper  img {
    325       max-width: 250px;
    326       max-height: 210px;
    327       width: expression(this.width > 250 ? "250px" : true);
    328       height: expression(this.height > 210 ? "210px" : true);
    329 }
    330 
    331 div.POPPER_slider {
    332     position: absolute;
    333     #position: fixed;
    334     display: none;
    335     background-color: #000000;
    336     color: #ffffff;
    337     text-align: left;
    338     padding-right: 11px;
    339     font-size: 10px;
    340     font-family: Verdana;
    341     margin-top: 0;
    342     margin-right:0;
    343 }
    344 
    345 a.POPPER_a,a.POPPER_a img {
    346 
    347     border: none;
    348     border-width: 0px;
    349 }
    350 
    351 .popinfo {
    352     display: none;
    353 }
    354 
    355 .POPPER_pinf {
    356     overflow: hidden;
    357     display: none;
    358     background-color: #ffffff;
    359     font-family: Verdana;
    360     font-size: 12px;
    361 }
  • opensearchserver-search/trunk/index.php

    r601998 r602348  
    2525*/
    2626function opensearchserver_admin_actions() {
    27     add_submenu_page('plugins.php', 'OpenSearchServer Settings', 'OpenSearchServer', 'edit_plugins', __FILE__, 'opensearchserver_admin_page');
     27  add_submenu_page('plugins.php', 'OpenSearchServer Settings', 'OpenSearchServer', 'edit_plugins', __FILE__, 'opensearchserver_admin_page');
    2828}
    29 function load_scripts_styles() {
    30     wp_register_script( 'opensearchserver', plugins_url('opensearchserver-search') .'/js/opensearchserver.js' );
    31     wp_enqueue_script( 'opensearchserver' );
    32     wp_register_style( 'opensearchserver-style', plugins_url('opensearchserver-search')  . '/css/oss-style.css');
    33     wp_enqueue_style('opensearchserver-style');
    34     wp_enqueue_script( 'jQuery' );
     29function opensearchserver_load_scripts_styles() {
     30  wp_register_script( 'opensearchserver', plugins_url('opensearchserver-search') .'/js/opensearchserver.js' );
     31  wp_enqueue_script( 'opensearchserver' );
     32  wp_register_style( 'opensearchserver-style', plugins_url('opensearchserver-search')  . '/css/oss-style.css');
     33  wp_enqueue_style('opensearchserver-style');
     34  wp_enqueue_script( 'jQuery' );
    3535}
    3636function  opensearchserver_search() {
    3737
    38     if ( stripos($_SERVER['REQUEST_URI'], '/?s=') === FALSE && stripos($_SERVER['REQUEST_URI'], '/search/') === FALSE)  {
    39         return;
    40     }
    41     if (stripos($_SERVER['REQUEST_URI'], '/?s=') === FALSE && stripos($_SERVER['REQUEST_URI'], '/search/') === FALSE)   {
    42         return;
    43     }
    44     $query=get_search_query();
    45     if($query == 'ossautointernal') {
    46         include_once('autocomplete.php');
    47         exit;
    48     }else {
    49         if (file_exists(TEMPLATEPATH . '/oss_search.php')) {
    50             include_once(TEMPLATEPATH . '/oss_search.php');
    51         } else if (file_exists(dirname(__FILE__) . '/template/opensearchserver_search.php')) {
    52             include_once('template/opensearchserver_search.php');
    53         } else {
    54             return;
    55         }
    56     }
     38  if ( stripos($_SERVER['REQUEST_URI'], '/?s=') === FALSE && stripos($_SERVER['REQUEST_URI'], '/search/') === FALSE)    {
     39    return;
     40  }
     41  if (stripos($_SERVER['REQUEST_URI'], '/?s=') === FALSE && stripos($_SERVER['REQUEST_URI'], '/search/') === FALSE) {
     42    return;
     43  }
     44  $query=get_search_query();
     45  if($query == 'ossautointernal') {
     46    include_once('autocomplete.php');
     47    exit;
     48  }else {
     49    if (file_exists(TEMPLATEPATH . '/oss_search.php')) {
     50      include_once(TEMPLATEPATH . '/oss_search.php');
     51    } else if (file_exists(dirname(__FILE__) . '/template/opensearchserver_search.php')) {
     52      include_once('template/opensearchserver_search.php');
     53    } else {
     54      return;
     55    }
     56  }
    5757}
    5858function opensearchserver_install() {
    59     $oss_query  = 'title:($$)^10 OR title:("$$")^10 OR allContent:($$) OR allContent:("$$")
    60     OR
    61     content:($$)^5 OR content:("$$")^5 OR categories:($$) OR categories:("$$")';
    62     update_option('oss_query', $oss_query);
     59  $oss_query  = 'title:($$)^10 OR title:("$$")^10 OR allContent:($$) OR allContent:("$$")
     60  OR
     61  content:($$)^5 OR content:("$$")^5 OR categories:($$) OR categories:("$$")';
     62  update_option('oss_query', $oss_query);
    6363}
    6464
    6565function opensearchserver_uninstall() {
    66     delete_option('oss_query');
    67     delete_option('oss_serverurl');
    68     delete_option('oss_indexname');
    69     delete_option('oss_login');
    70     delete_option('oss_key');
    71     delete_option('oss_facet');
    72     delete_option('oss_spell');
     66  delete_option('oss_query');
     67  delete_option('oss_serverurl');
     68  delete_option('oss_indexname');
     69  delete_option('oss_login');
     70  delete_option('oss_key');
     71  delete_option('oss_facet');
     72  delete_option('oss_spell');
    7373}
    74 function do_while_posting($post_id,$post) {
    75     if ($post->post_type == 'post' || $post->post_type == 'page'
    76             && $post->post_status == 'publish') {
    77         opensearchserver_reindex_site($post->ID,$post->post_type);
    78     }
    79     else {
    80         $delete='id:'.$post->post_type.'_'.$post->ID;
    81         delete_document($delete);
    82     }
     74function opensearchserver_do_while_posting($post_id,$post) {
     75  if ($post->post_type == 'post' || $post->post_type == 'page'
     76    && $post->post_status == 'publish') {
     77    opensearchserver_reindex_site($post->ID,$post->post_type);
     78  }
     79  else {
     80    $delete='id:'.$post->post_type.'_'.$post->ID;
     81    opensearchserver_delete_document($delete);
     82  }
    8383}
    8484register_activation_hook(__FILE__,'opensearchserver_install');
    8585register_deactivation_hook( __FILE__, 'opensearchserver_uninstall');
    86 add_action('save_post','do_while_posting',10,2);
    87 add_action('wp_enqueue_scripts','load_scripts_styles' );
     86add_action('save_post','opensearchserver_do_while_posting',10,2);
     87add_action('wp_enqueue_scripts','opensearchserver_load_scripts_styles' );
    8888add_action('admin_menu', 'opensearchserver_admin_actions');
    8989add_action('template_redirect', 'opensearchserver_search');
  • opensearchserver-search/trunk/js/opensearchserver.js

    r601998 r602348  
    1 function getXmlHttpRequestObject() {
     1if (typeof (OpenSearchServer) == "undefined")
     2    OpenSearchServer = {};
     3
     4OpenSearchServer.getXmlHttpRequestObject = function() {
    25    if (window.XMLHttpRequest) {
    36        return new XMLHttpRequest();
     
    710        return null;
    811    }
    9 }
     12};
    1013
    11 var xmlHttp = getXmlHttpRequestObject();
     14OpenSearchServer.xmlHttp = OpenSearchServer.getXmlHttpRequestObject();
    1215
    13 function setAutocomplete(value) {
    14     var ac = document.getElementById('autocomplete');
     16OpenSearchServer.setAutocomplete = function(value) {
     17    var ac = document.getElementById('oss-autocomplete');
    1518    ac.innerHTML = value;
    1619    return ac;
    17 }
     20};
    1821
    19 var selectedAutocomplete = 0;
    20 var autocompleteSize = 0;
     22OpenSearchServer.selectedAutocomplete = 0;
     23OpenSearchServer.autocompleteSize = 0;
    2124
    22 function getselectedautocompletediv(n) {
    23     return document.getElementById('autocompleteitem' + n);
    24 }
     25OpenSearchServer.getselectedautocompletediv = function(n) {
     26    return document.getElementById('oss-autocompleteitem' + n);
     27};
    2528
    26 function autosuggest(event) {
    27     var keynum;
     29OpenSearchServer.autosuggest = function(event) {
     30    var keynum = 0;
    2831    if (window.event) { // IE
    2932        keynum = event.keyCode;
     
    3336    if (keynum == 38 || keynum == 40) {
    3437        if (selectedAutocomplete > 0) {
    35             autocompleteLinkOut(selectedAutocomplete);
     38            OpenSearchServer.autocompleteLinkOut(selectedAutocomplete);
    3639        }
    3740        if (keynum == 38) {
     
    4548        }
    4649        if (selectedAutocomplete > 0) {
    47             var dv = getselectedautocompletediv(selectedAutocomplete);
    48             autocompleteLinkOver(selectedAutocomplete);
    49             setKeywords(dv.innerHTML);
     50            var dv = OpenSearchServer.getselectedautocompletediv(selectedAutocomplete);
     51            OpenSearchServer.autocompleteLinkOver(selectedAutocomplete);
     52            OpenSearchServer.setKeywords(dv.innerHTML);
    5053        }
    5154        return false;
    5255    }
    5356
    54     if (xmlHttp.readyState != 4 && xmlHttp.readyState != 0)
     57    if (OpenSearchServer.xmlHttp.readyState != 4
     58            && OpenSearchServer.xmlHttp.readyState != 0)
    5559        return;
    56     var str = escape(document.getElementById('keyword').value);
     60    var str = escape(document.getElementById('oss-keyword').value);
    5761    if (str.length == 0) {
    58         setAutocomplete('');
     62        OpenSearchServer.setAutocomplete('');
    5963        return;
    6064    }
    6165
    62     xmlHttp.open("GET", '?s=ossautointernal&q=' + str, true);
    63     xmlHttp.onreadystatechange = handleAutocomplete;
    64     xmlHttp.send(null);
     66    OpenSearchServer.xmlHttp.open("GET", '?s=ossautointernal&q=' + str, true);
     67    OpenSearchServer.xmlHttp.onreadystatechange = OpenSearchServer.handleAutocomplete;
     68    OpenSearchServer.xmlHttp.send(null);
    6569    return true;
    66 }
     70};
    6771
    68 function handleAutocomplete() {
    69     if (xmlHttp.readyState != 4)
     72OpenSearchServer.handleAutocomplete = function() {
     73    if (OpenSearchServer.xmlHttp.readyState != 4)
    7074        return;
    71     var ac = setAutocomplete('');
    72     var resp = xmlHttp.responseText;
     75    var ac = OpenSearchServer.setAutocomplete('');
     76    var resp = OpenSearchServer.xmlHttp.responseText;
    7377    if (resp == null) {
    7478        return;
     
    7882    }
    7983    var str = resp.split("\n");
    80     var content = '<div id="autocompletelist">';
    81     for (i = 0; i < str.length - 1; i++) {
     84    var content = '<div id="oss-autocompletelist">';
     85    for ( var i = 0; i < str.length - 1; i++) {
    8286        var j = i + 1;
    83         content += '<div id="autocompleteitem' + j + '" ';
    84         content += 'onmouseover="javascript:autocompleteLinkOver(' + j + ');" ';
    85         content += 'onmouseout="javascript:autocompleteLinkOut(' + j + ');" ';
    86         content += 'onclick="javascript:setsetKeywords_onClick(this.innerHTML);" ';
    87         content += 'class="autocomplete_link">' + str[i] + '</div>';
     87        content += '<div id="oss-autocompleteitem' + j + '" ';
     88        content += 'onmouseover="javascript:OpenSearchServer.autocompleteLinkOver('
     89                + j + ');" ';
     90        content += 'onmouseout="javascript:OpenSearchServer.autocompleteLinkOut('
     91                + j + ');" ';
     92        content += 'onclick="javascript:OpenSearchServer.setKeywords_onClick(this.innerHTML);" ';
     93        content += 'class="oss-autocomplete_link">' + str[i] + '</div>';
    8894    }
    8995    content += '</div>';
     
    9197    selectedAutocomplete = 0;
    9298    autocompleteSize = str.length;
    93 }
     99};
    94100
    95 function autocompleteLinkOver(n) {
     101OpenSearchServer.autocompleteLinkOver = function(n) {
    96102    if (selectedAutocomplete > 0) {
    97         autocompleteLinkOut(selectedAutocomplete);
     103        OpenSearchServer.autocompleteLinkOut(selectedAutocomplete);
    98104    }
    99     var dv = getselectedautocompletediv(n);
    100     if(dv != null)
    101     {
    102         dv.className = 'autocomplete_link_over';
     105    var dv = OpenSearchServer.getselectedautocompletediv(n);
     106    if (dv != null) {
     107        dv.className = 'oss-autocomplete_link_over';
    103108        selectedAutocomplete = n;
    104109    }
    105 }
     110};
    106111
    107 function autocompleteLinkOut(n) {
    108     var dv = getselectedautocompletediv(n);
     112OpenSearchServer.autocompleteLinkOut = function(n) {
     113    var dv = OpenSearchServer.getselectedautocompletediv(n);
    109114    if (dv != null) {
    110         dv.className = 'autocomplete_link';
     115        dv.className = 'oss-autocomplete_link';
    111116    }
    112 }
    113 function setsetKeywords_onClick(value) {
    114     var dv = document.getElementById('keyword');
     117};
     118
     119OpenSearchServer.setKeywords_onClick = function(value) {
     120    var dv = document.getElementById('oss-keyword');
    115121    if (dv != null) {
    116122        dv.value = value;
    117123        dv.focus();
    118         setAutocomplete('');
    119         document.forms['searchformForm'].submit()
     124        OpenSearchServer.setAutocomplete('');
     125        document.forms['oss-searchform'].submit();
    120126        return true;
    121127    }
    122 }
    123 function setKeywords(value) {
    124     var dv = document.getElementById('keyword');
     128};
     129
     130OpenSearchServer.setKeywords = function(value) {
     131    var dv = document.getElementById('oss-keyword');
    125132    if (dv != null) {
    126133        dv.value = value;
    127134        dv.focus();
    128135    }
    129 }
     136};
  • opensearchserver-search/trunk/lib/oss_abstract.class.php

    r601998 r602348  
    7070   * param string[] $options Additional query parameters
    7171   * return string
    72    * Use OssApi::API_* constants for $apiCall.
    7372   * Optionals query parameters are provided as a named list:
    7473   * array(
     
    134133    // Use CURL to post the data
    135134
    136     $rcurl = curl_init($url);
     135    $rcurl = curl_init($url);
    137136    curl_setopt($rcurl, CURLOPT_HTTP_VERSION, '1.0');
    138137    curl_setopt($rcurl, CURLOPT_BINARYTRANSFER, TRUE);
     
    192191  }
    193192
     193  protected function queryServerTXT($path, $params = null, $data = null, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT) {
     194    return $this->queryServer($this->getQueryURL($path, $params), $data, $connexionTimeout, $timeout);
     195  }
     196
    194197  /**
    195198   * Post data to an URL and retrieve an XML
     
    199202   * @param int $timeout Optional. Number of seconds before the query fail
    200203   * @return SimpleXMLElement
    201    * Use OssApi::queryServerto retrieve an XML and check its validity
     204   * Use queryServer to retrieve an XML and check its validity
    202205   */
    203206  protected function queryServerXML($path, $params, $data = NULL, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT) {
    204     $result = $this->queryServer($this->getQueryURL($path, $params), $data, $connexionTimeout, $timeout);
     207    $result = $this->queryServerTXT($path, $params, $data, $connexionTimeout, $timeout);
    205208    if ($result === FALSE) {
    206209      return FALSE;
  • opensearchserver-search/trunk/lib/oss_api.class.php

    r601998 r602348  
    132132   */
    133133  public function optimize() {
    134     $return = $this->queryServer($this->getQueryURL(OssApi::API_OPTIMIZE));
     134    $return = $this->queryServerTXT(OssApi::API_OPTIMIZE);
    135135    return ($return !== FALSE);
    136136  }
     
    144144   */
    145145  public function reload() {
    146     $return = $this->queryServer($this->getQueryURL(OssApi::API_RELOAD));
     146    $return = $this->queryServerTXT(OssApi::API_RELOAD);
    147147    return ($return !== FALSE);
    148148  }
  • opensearchserver-search/trunk/lib/oss_autocompletion.class.php

    r601998 r602348  
    3434  }
    3535
    36   public function autocomplete($query, $rows = 10) {
     36  /**
     37   *
     38   * @param string $query the characters to pass to the autocompletion query
     39   * @param int $rows The number of row to return
     40   */
     41  public function autocompletionQuery($query, $rows = 10) {
    3742    $params = array('query' => $query, 'rows' => $rows);
    38     $return = OssApi::queryServer($this->getQueryURL(OssApi::API_AUTOCOMPLETION, $params));
     43    $return = $this->queryServerTXT(OssApi::API_AUTOCOMPLETION, $params);
    3944    if ($return === FALSE) {
    4045      return FALSE;
     
    4247    return $return;
    4348  }
     49
     50  /*
     51   * @deprecated  Use autocompleteQuery
     52  */
     53  public function autocomplete($query, $rows = 10) {
     54    return $this->autocompletionQuery($query, $rows);
     55  }
     56
     57  /**
     58   * Build the autocompletion index
     59   * @param int $bufferSize the size of the buffer
     60   */
     61  public function autocompletionBuild($bufferSize = 1000) {
     62    $params = array('cmd' => 'build', 'bufferSize' => $bufferSize);
     63    $return = $this->queryServerXML(OssApi::API_AUTOCOMPLETION, $params);
     64    if ($return === FALSE) {
     65      return FALSE;
     66    }
     67    return TRUE;
     68  }
     69
     70  /**
     71   * Set the field used by the autocompletion index
     72   * @param string $field the field name
     73   */
     74  public function autocompletionSet($field) {
     75    $params = array('cmd' => 'set', 'field' => $field);
     76    $return = $this->queryServerXML(OssApi::API_AUTOCOMPLETION, $params);
     77    if ($return === FALSE) {
     78      return FALSE;
     79    }
     80    return TRUE;
     81  }
    4482}
    4583?>
  • opensearchserver-search/trunk/lib/oss_exception.class.php

    r601998 r602348  
    11<?php
    22/*
    3 *  This file is part of OpenSearchServer.
     3 *  This file is part of OpenSearchServer.
    44*
    55*  Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft
     
    7070    $data = array();
    7171    foreach ($xmlDoc->entry as $entry)
    72     $data[(string)$entry['key']] = (string)$entry;
     72      $data[(string)$entry['key']] = (string)$entry;
    7373
    7474    $this->status  = $data['Status'];
  • opensearchserver-search/trunk/lib/oss_indexdocument.class.php

    r601998 r602348  
    11<?php
    22/*
    3 *  This file is part of OpenSearchServer.
     3 *  This file is part of OpenSearchServer.
    44*
    55*  Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft
  • opensearchserver-search/trunk/lib/oss_results.class.php

    r601998 r602348  
    11<?php
    22/*
    3 *  This file is part of OpenSearchServer.
     3 *  This file is part of OpenSearchServer.
    44*
    55*  Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft
     
    8585   *  GETTER
    8686   */
    87   public function getField($position, $fieldName, $modeSnippet = FALSE) {
     87  public function getField($position, $fieldName, $modeSnippet = FALSE, $highlightedOnly = FALSE) {
    8888    $field = NULL;
    8989    $doc = $this->result->xpath('result/doc[@pos="' . $position . '"]');
     
    9292      $value = NULL;
    9393      if ($modeSnippet) {
    94         $value = $doc[0]->xpath('snippet[@name="' . $fieldName . '"]');
     94        if ($highlightedOnly) {
     95          $value = $doc[0]->xpath('snippet[@name="' . $fieldName . '" and @highlighted="yes"]');
     96        } else {
     97          $value = $doc[0]->xpath('snippet[@name="' . $fieldName . '"]');
     98        }
    9599      }
    96100      if (!isset($value) || count($value) == 0) {
     
    156160
    157161  /**
    158   *
    159   * @return Return the spellsuggest array.
    160   */
     162   *
     163   * @return Return the spellsuggest array.
     164   */
    161165  public function getSpellSuggestions($fieldName) {
    162166    $currentSpellCheck = isset($fieldName)? $this->result->xpath('spellcheck/field[@name="' . $fieldName . '"]/word/suggest'):NULL;
  • opensearchserver-search/trunk/lib/oss_searchtemplate.class.php

    r601998 r602348  
    4444
    4545  public function createSearchTemplate($qtname, $qtquery = NULL, $qtoperator = NULL, $qtrows = NULL, $qtslop = NULL, $qtlang = NULL) {
    46     $params = array("qt.name" => $qtname);
     46    $params = array("qt.name" => $qtname);
    4747    if ($qtquery) {
    4848      $params['qt.query'] = $qtquery;
     
    6666  /*
    6767   * Function to create spell check Query Template
    68    * $qtsuggestions - No of suggestions to be returned
    69    * $qtfield - The field that is used for spell checking.
    70    * $qtscore - The minimum score of Spellcheck match.
    71    * $qtalgorithm -The alorithm used for spellcheck.OpenSearchServer has below alogrithms for spellcheck.
    72    *               1)LevensteinDistance
    73    *               2)NGramDistance
    74    *               3)JaroWinklerDistance
    75    */
     68  * $qtsuggestions - No of suggestions to be returned
     69  * $qtfield - The field that is used for spell checking.
     70  * $qtscore - The minimum score of Spellcheck match.
     71  * $qtalgorithm -The alorithm used for spellcheck.OpenSearchServer has below alogrithms for spellcheck.
     72  *               1)LevensteinDistance
     73  *               2)NGramDistance
     74  *               3)JaroWinklerDistance
     75  */
    7676  public function createSpellCheckTemplate($qtname, $qtquery = NULL, $qtsuggestions = NULL, $qtfield = NULL, $qtscore = NULL, $qtlang = NULL, $qtalgorithm = NULL) {
    77     $params = array("qt.name" => $qtname);
    78     $params['qt.type'] = 'SpellCheckRequest';
    79     if ($qtquery) {
    80         $params['qt.query'] = $qtquery;
    81     }
    82     if ($qtsuggestions) {
    83         $params['qt.suggestions'] = $qtsuggestions;
    84     }
    85     if ($qtfield) {
    86         $params['qt.field'] = $qtfield;
    87     }
    88     if ($qtscore) {
    89         $params['qt.score'] = $qtscore;
    90     }
     77    $params = array("qt.name" => $qtname);
     78    $params['qt.type'] = 'SpellCheckRequest';
     79    if ($qtquery) {
     80      $params['qt.query'] = $qtquery;
     81    }
     82    if ($qtsuggestions) {
     83      $params['qt.suggestions'] = $qtsuggestions;
     84    }
     85    if ($qtfield) {
     86      $params['qt.field'] = $qtfield;
     87    }
     88    if ($qtscore) {
     89      $params['qt.score'] = $qtscore;
     90    }
    9191
    92     if ($qtlang) {
    93         $params['qt.lang'] = $qtlang;
    94     }
    95     if ($qtalgorithm) {
    96         $params['qt.algorithm'] = $qtalgorithm;
     92    if ($qtlang) {
     93      $params['qt.lang'] = $qtlang;
     94    }
     95    if ($qtalgorithm) {
     96      $params['qt.algorithm'] = $qtalgorithm;
    9797    }
    9898    $params['cmd'] = OssSearchTemplate::API_SEARCH_TEMPLATE_CREATE;
     
    125125    $params['snippetfield'] = $snippetField;
    126126    $params['cmd'] = OssSearchTemplate::API_SEARCH_TEMPLATE_SETSNIPPETFIELD;
    127     $return = OssApi::queryServerXML(OssSearchTemplate::API_SEARCH_TEMPLATE, $params);
     127    $return = $this->queryServerXML(OssSearchTemplate::API_SEARCH_TEMPLATE, $params);
    128128    return $return === FALSE ? FALSE : TRUE;
    129129  }
  • opensearchserver-search/trunk/opensearchserver_admin.php

    r601998 r602348  
    44*/
    55function opensearchserver_getapi_instance() {
    6     return new OssApi(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
     6  return new OssApi(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
    77}
    88function opensearchserver_getschema_instance() {
    9     return new OssSchema(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
     9  return new OssSchema(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
    1010}
    1111function opensearchserver_getsearchtemplate_instance() {
    12     return new OssSearchTemplate(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
     12  return new OssSearchTemplate(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
    1313}
    1414function opensearchserver_getdelete_instance() {
    15     return new OssDelete(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
     15  return new OssDelete(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
    1616}
    1717function opensearchserver_getautocomplete_instance() {
    18     return new OssAutocompletion(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
    19 }
    20 /*
    21  * Check the index is available or create it.
    22 */
     18  return new OssAutocompletion(get_option('oss_serverurl'), get_option('oss_indexname'), get_option('oss_login'), get_option('oss_key'));
     19}
     20
     21
     22/**
     23 * Create or re-create the index if it already exists
     24 * @return boolean
     25 */
    2326function opensearchserver_create_index() {
    24     $oss_api = opensearchserver_getapi_instance();
    25     $index_list = $oss_api->indexList();
    26     $index = in_array(get_option('oss_indexname'), $index_list);
    27     if($index === FALSE) {
    28         $oss_api->createIndex(get_option('oss_indexname'));
    29         opensearchserver_create_schema();
    30         opensearchserver_query_template();
    31         opensearchserver_spellcheck_query_template();
    32         return TRUE;
    33     }
    34     return FALSE;
    35 }
    36 function setField($ossSchema, $xmlSchema, $fieldName, $analyzer, $stored, $indexed, $termVector, $default = 'no', $unique = 'no') {
    37     $xmlField = $xmlSchema->xpath('/response/schema/fields/field[@name="' . $fieldName . '"]');
    38     // Check if the field already exists.
    39     if (isset($xmlField[0]) && is_array($xmlField)) {
    40         $ossSchema->deleteField($fieldName);
    41     }
    42     $ossSchema->setField($fieldName, $analyzer, $stored, $indexed, $termVector, $default, $unique);
     27  $indexName = get_option('oss_indexname');
     28  $oss_api = opensearchserver_getapi_instance();
     29  $index_list = $oss_api->indexList();
     30  $index = in_array($indexName, $index_list);
     31  if ($index !== FALSE) {
     32    $oss_api->deleteIndex($indexName);
     33  }
     34
     35  $oss_api->createIndex($indexName);
     36  opensearchserver_create_schema();
     37  opensearchserver_query_template();
     38  opensearchserver_spellcheck_query_template();
     39  return TRUE;
     40}
     41
     42function opensearchserver_setField($ossSchema, $xmlSchema, $fieldName, $analyzer, $stored, $indexed, $termVector, $default = 'no', $unique = 'no') {
     43  $xmlField = $xmlSchema->xpath('/response/schema/fields/field[@name="' . $fieldName . '"]');
     44  // Check if the field already exists.
     45  if (isset($xmlField[0]) && is_array($xmlField)) {
     46    $ossSchema->deleteField($fieldName);
     47  }
     48  $ossSchema->setField($fieldName, $analyzer, $stored, $indexed, $termVector, $default, $unique);
    4349}
    4450
     
    4955
    5056function opensearchserver_create_schema() {
    51     $schema = opensearchserver_getschema_instance();
    52     $schema_xml = $schema->getSchema();
    53     setField($schema,$schema_xml,'id', NULL, 'yes', 'yes', 'no', 'no', 'yes');
    54     setField($schema,$schema_xml,'type', NULL, 'yes', 'yes', 'no', 'no', 'no');
    55     setField($schema,$schema_xml,'url',NULL,'no','yes','yes','no','no');
    56     setField($schema,$schema_xml,'urlExact','StandardAnalyzer','no','yes','yes','no','no');
    57     setField($schema,$schema_xml,'title','TextAnalyzer','yes','yes','positions_offsets','no','no');
    58     setField($schema,$schema_xml,'titleExact','StandardAnalyzer','yes','yes','no','no','no');
    59     setField($schema,$schema_xml,'content','TextAnalyzer','compress','yes','positions_offsets','yes','no');
    60     setField($schema,$schema_xml,'contentExact','StandardAnalyzer','compress','yes','no','no','no');
    61     setField($schema,$schema_xml,'timestamp',NULL,'no','yes','yes','no','no');
    62     setField($schema,$schema_xml,'user_name',NULL,'yes','yes','yes','no','no');
    63     setField($schema,$schema_xml,'user_email',NULL,'yes','yes','yes','no','no');
    64     setField($schema,$schema_xml,'user_url',NULL,'no','yes','yes','no','no');
    65     setField($schema,$schema_xml,'allContent','TextAnalyzer','compress','yes','no','yes','no');
    66     setField($schema,$schema_xml,'categories','TextAnalyzer','YES','yes','no','yes','no');
    67     setField($schema,$schema_xml,'categoriesExact',NULL,'YES','yes','no','yes','no');
    68 }
     57  $schema = opensearchserver_getschema_instance();
     58  $schema_xml = $schema->getSchema();
     59  opensearchserver_setField($schema,$schema_xml,'id', NULL, 'yes', 'yes', 'no', 'no', 'yes');
     60  opensearchserver_setField($schema,$schema_xml,'type', NULL, 'yes', 'yes', 'no', 'no', 'no');
     61  opensearchserver_setField($schema,$schema_xml,'url',NULL,'no','yes','yes','no','no');
     62  opensearchserver_setField($schema,$schema_xml,'urlExact','StandardAnalyzer','no','yes','yes','no','no');
     63  opensearchserver_setField($schema,$schema_xml,'title','TextAnalyzer','yes','yes','positions_offsets','no','no');
     64  opensearchserver_setField($schema,$schema_xml,'titleExact','StandardAnalyzer','no','yes','no','no','no');
     65  if (get_option('oss_phonetic')) {
     66    opensearchserver_setField($schema,$schema_xml,'titlePhonetic','PhoneticAnalyzer','yes','yes','positions_offsets','no','no');
     67    opensearchserver_setField($schema,$schema_xml,'contentPhonetic','PhoneticAnalyzer','yes','yes','positions_offsets','no','no');
     68  }
     69  opensearchserver_setField($schema,$schema_xml,'content','TextAnalyzer','compress','yes','positions_offsets','yes','no');
     70  opensearchserver_setField($schema,$schema_xml,'contentExact','StandardAnalyzer','no','yes','no','no','no');
     71  opensearchserver_setField($schema,$schema_xml,'timestamp',NULL,'no','yes','yes','no','no');
     72  opensearchserver_setField($schema,$schema_xml,'user_name',NULL,'yes','yes','yes','no','no');
     73  opensearchserver_setField($schema,$schema_xml,'user_email',NULL,'yes','yes','yes','no','no');
     74  opensearchserver_setField($schema,$schema_xml,'user_url',NULL,'no','yes','yes','no','no');
     75  opensearchserver_setField($schema,$schema_xml,'allContent','TextAnalyzer','no','yes','no','yes','no');
     76  opensearchserver_setField($schema,$schema_xml,'categories','TextAnalyzer','yes','yes','no','yes','no');
     77  opensearchserver_setField($schema,$schema_xml,'categoriesExact',NULL,'yes','yes','no','yes','no');
     78}
     79
    6980/*
    7081 * Function to display messages in admin
    7182*/
    72 function opensearchserver_diaplay_messages($message, $errormsg = FALSE) {
    73     if ($errormsg) {
    74         echo '<div id="message" class="error">';
    75     }
    76     else {
    77         echo '<div id="message" class="updated fade">';
    78     }
    79     echo "<p><strong>$message</strong></p></div>";
    80 }
     83function opensearchserver_display_messages($message, $errormsg = FALSE) {
     84  if ($errormsg) {
     85    echo '<div id="message" class="error">';
     86  }
     87  else {
     88    echo '<div id="message" class="updated fade">';
     89  }
     90  echo "<p><strong>$message</strong></p></div>";
     91}
     92
    8193/*
    8294 * Function to update the query template
    8395*/
    8496function opensearchserver_query_template() {
    85     $query_template = opensearchserver_getsearchtemplate_instance();
    86     $oss_query = stripcslashes(get_option('oss_query'));
    87     $query_template->createSearchTemplate("search",$oss_query,"AND","10","2","ENGLISH");
    88     $query_template->setSnippetField("search","title");
    89     $query_template->setSnippetField("search","content");
    90     $query_template->setReturnField("search","url");
    91     $query_template->setReturnField("search","user_url");
    92     $query_template->setReturnField("search","type");
    93     $query_template->setReturnField("search","user_name");
    94     $query_template->setReturnField("search","user_email");
    95     $query_template->setReturnField("search","categories");
    96 
    97 }
     97  $query_template = opensearchserver_getsearchtemplate_instance();
     98  $oss_query = stripcslashes(get_option('oss_query'));
     99  $query_template->createSearchTemplate('search', $oss_query, 'AND', '10', '2', 'ENGLISH');
     100  $query_template->setSnippetField('search','title', 70, 'b');
     101  $query_template->setSnippetField('search','content', 300, 'b', NULL, 'SentenceFragmenter');
     102  if (get_option('oss_phonetic')) {
     103    $query_template->setSnippetField('search','titlePhonetic', 70, 'b');
     104    $query_template->setSnippetField('search','contentPhonetic', 300, 'b', NULL, 'SentenceFragmenter');
     105  }
     106  $query_template->setReturnField('search',"url");
     107  $query_template->setReturnField('search',"user_url");
     108  $query_template->setReturnField('search',"type");
     109  $query_template->setReturnField('search',"user_name");
     110  $query_template->setReturnField('search',"user_email");
     111  $query_template->setReturnField('search',"categories");
     112}
     113
    98114/*
    99115 * Function to create the spellcheck query
    100116*/
    101117function opensearchserver_spellcheck_query_template() {
    102     $spell_field = get_option('oss_spell').'Exact';
    103     if($spell_field && $spell_field !='none')
    104         $spellcheck_query_template = opensearchserver_getsearchtemplate_instance();
    105     $spellcheck_query_template->createSpellCheckTemplate("spellcheck","*:*","1",$spell_field,"0.5",NULL,"LevensteinDistance");
    106 }
     118  $spell_field = get_option('oss_spell').'Exact';
     119  $spell_algo = get_option('oss_spell_algo');
     120  if($spell_field && $spell_field !='none') {
     121    $spellcheck_query_template = opensearchserver_getsearchtemplate_instance();
     122    $spellcheck_query_template->createSpellCheckTemplate('spellcheck', '*:*', '1', $spell_field, '0.5', NULL, $spell_algo);
     123  }
     124}
     125
    107126/*
    108127 * Function to reindex the website.
    109128*/
    110129function opensearchserver_reindex_site($id,$type) {
    111     global $wpdb;
    112     $oss_server_url = get_option('oss_serverurl');
    113     $oss_indexname = get_option('oss_indexname');
    114     $oss_login =  get_option('oss_login');
    115     $oss_key = get_option('oss_key');
    116     $custom_fields = get_option('oss_custom_field');
    117     $table_name_posts =$wpdb->prefix ."posts";
    118     $table_name_users =$wpdb->prefix ."users";
    119     $index_status=0;
    120     $ossEnginePath  = config_request_value('ossEnginePath', $oss_server_url, 'engineURL');
    121     $ossEngineConnectTimeOut = config_request_value('ossEngineConnectTimeOut', 5, 'engineConnectTimeOut');
    122     $ossEngineIndex = config_request_value('ossEngineIndex', $oss_indexname, 'engineIndex');
    123     if($id) {
    124         $delete='id:'.$type.'_'.$id;
    125         delete_document($delete);
    126         $sql_suffix = 'FROM '.$table_name_posts.' p LEFT JOIN  '.$table_name_users.' u ON p.post_author = u.ID WHERE `post_status` = \'publish\' AND p.ID ='.$id;
    127         $sql_query = 'SELECT p.ID,post_type,post_title,post_content,guid,post_date_gmt,post_author,user_nicename,user_url,user_email '.$sql_suffix;
    128         $sql_posts = $wpdb->get_results($sql_query);
    129         $index=add_documents_to_index($sql_posts, $custom_fields);
    130         opensearchserver_start_indexing($index);
    131     }else {
    132         delete_document('*:*');
    133         wp_cache_flush();
    134         $batch = 200;
    135         $sql_suffix = 'FROM '.$table_name_posts.' p LEFT JOIN  '.$table_name_users.' u ON p.post_author = u.ID WHERE `post_status` = \'publish\'';
    136         $total_count = $wpdb->get_var($wpdb->prepare( 'SELECT COUNT(*) '.$sql_suffix));
    137         $wpdb->flush();
    138         $sql_query = 'SELECT p.ID,post_type,post_title,post_content,guid,post_date_gmt,post_author,user_nicename,user_url,user_email '.$sql_suffix;
    139 
    140         $current_pos = 0;
    141         while ($current_pos < $total_count) {
    142             $row_fetch = $total_count - $current_pos;
    143             if ($row_fetch > $batch) {
    144                 $row_fetch = $batch;
    145             }
    146 
    147             $sql_posts = $wpdb->get_results($sql_query.' LIMIT '.$current_pos.','.$batch);
    148             $index = add_documents_to_index($sql_posts,$custom_fields);
    149             opensearchserver_start_indexing($index);
    150             $wpdb->flush();
    151             wp_cache_flush();
    152             unset($sql_posts);
    153             unset($index);
    154             $current_pos += $row_fetch;
    155         }
    156     }
    157     opensearchserver_optimize();
    158     $index_status=1;
    159     return $index_status;
    160 }
    161 function delete_document($query) {
    162     return opensearchserver_getdelete_instance()->delete($query);
     130  global $wpdb;
     131  $oss_server_url = get_option('oss_serverurl');
     132  $oss_indexname = get_option('oss_indexname');
     133  $oss_login =  get_option('oss_login');
     134  $oss_key = get_option('oss_key');
     135  $custom_fields = get_option('oss_custom_field');
     136  $table_name_posts =$wpdb->prefix ."posts";
     137  $table_name_users =$wpdb->prefix ."users";
     138  $index_status=0;
     139  $ossEnginePath  = config_request_value('ossEnginePath', $oss_server_url, 'engineURL');
     140  $ossEngineConnectTimeOut = config_request_value('ossEngineConnectTimeOut', 5, 'engineConnectTimeOut');
     141  $ossEngineIndex = config_request_value('ossEngineIndex', $oss_indexname, 'engineIndex');
     142  if($id)   {
     143    $delete='id:'.$type.'_'.$id;
     144    opensearchserver_delete_document($delete);
     145    $sql_suffix = 'FROM '.$table_name_posts.' p LEFT JOIN  '.$table_name_users.' u ON p.post_author = u.ID WHERE `post_status` = \'publish\' AND p.ID ='.$id;
     146    $sql_query = 'SELECT p.ID,post_type,post_title,post_content,guid,post_date_gmt,post_author,user_nicename,user_url,user_email '.$sql_suffix;
     147    $sql_posts = $wpdb->get_results($sql_query);
     148    $index = opensearchserver_add_documents_to_index($sql_posts, $custom_fields);
     149    opensearchserver_start_indexing($index);
     150  }else {
     151    opensearchserver_delete_document('*:*');
     152    wp_cache_flush();
     153    $batch = 200;
     154    $sql_suffix = 'FROM '.$table_name_posts.' p LEFT JOIN  '.$table_name_users.' u ON p.post_author = u.ID WHERE `post_status` = \'publish\'';
     155    $total_count = $wpdb->get_var($wpdb->prepare( 'SELECT COUNT(*) '.$sql_suffix));
     156    $wpdb->flush();
     157    $sql_query = 'SELECT p.ID,post_type,post_title,post_content,guid,post_date_gmt,post_author,user_nicename,user_url,user_email '.$sql_suffix;
     158
     159    $current_pos = 0;
     160    while ($current_pos < $total_count) {
     161      $row_fetch = $total_count - $current_pos;
     162      if ($row_fetch > $batch) {
     163        $row_fetch = $batch;
     164      }
     165
     166      $sql_posts = $wpdb->get_results($sql_query.' LIMIT '.$current_pos.','.$batch);
     167      $index = opensearchserver_add_documents_to_index($sql_posts,$custom_fields);
     168      opensearchserver_start_indexing($index);
     169      $wpdb->flush();
     170      wp_cache_flush();
     171      unset($sql_posts);
     172      unset($index);
     173      $current_pos += $row_fetch;
     174    }
     175  }
     176  opensearchserver_optimize();
     177  opensearchserver_autocompletionBuild();
     178  $index_status=1;
     179  return $index_status;
     180}
     181
     182function opensearchserver_delete_document($query) {
     183  return opensearchserver_getdelete_instance()->delete($query);
    163184}
    164185
    165186function opensearchserver_start_indexing($index) {
    166     $server = opensearchserver_getapi_instance();
    167     if ($server->update($index, get_option('oss_indexname')) === FALSE) {
    168         $errors[] = 'failedToUpdate';
    169     }
    170 }
    171 function clean_field($field) {
    172     $field = str_replace(' ', '_', $field);
    173     $escapechars = array('\\', '^', '~', ':', '(', ')', '{', '}', '[', ']' , '&', '||', '!', '*', '?','039;','\'','#');
    174     foreach ($escapechars as $escchar)  {
    175         $field = str_replace($escchar, '_', $field);
    176     }
    177     $field = trim($field);
    178     return strtolower($field);
    179 }
    180 function stripInvalidXml($value) {
    181     $ret = "";
    182     $current;
    183     if (empty($value)) {
    184         return $ret;
    185     }
    186     $length = strlen($value);
    187     for ($i=0; $i < $length; $i++) {
    188         $current = ord($value{$i});
    189         if (($current == 0x9) ||
    190                 ($current == 0xA) ||
    191                 ($current == 0xD) ||
    192                 (($current >= 0x20) && ($current <= 0xD7FF)) ||
    193                 (($current >= 0xE000) && ($current <= 0xFFFD)) ||
    194                 (($current >= 0x10000) && ($current <= 0x10FFFF))){
    195             $ret .= chr($current);
    196         }
    197         else {
    198             $ret .= " ";
    199         }
    200     }
    201     return $ret;
     187  $server = opensearchserver_getapi_instance();
     188  if ($server->update($index, get_option('oss_indexname')) === FALSE) {
     189    $errors[] = 'failedToUpdate';
     190  }
     191}
     192
     193function opensearchserver_clean_field($field) {
     194  $field = str_replace(' ', '_', $field);
     195  $escapechars = array('\\', '^', '~', ':', '(', ')', '{', '}', '[', ']' , '&', '||', '!', '*', '?','039;','\'','#');
     196  foreach ($escapechars as $escchar)  {
     197    $field = str_replace($escchar, '_', $field);
     198  }
     199  $field = trim($field);
     200  return strtolower($field);
     201}
     202
     203function opensearchserver_stripInvalidXml($value) {
     204  $ret = "";
     205  $current;
     206  if (empty($value)) {
     207    return $ret;
     208  }
     209  $length = strlen($value);
     210  for ($i=0; $i < $length; $i++) {
     211    $current = ord($value{$i});
     212    if (($current == 0x9) ||
     213      ($current == 0xA) ||
     214      ($current == 0xD) ||
     215      (($current >= 0x20) && ($current <= 0xD7FF)) ||
     216      (($current >= 0xE000) && ($current <= 0xFFFD)) ||
     217      (($current >= 0x10000) && ($current <= 0x10FFFF))){
     218      $ret .= chr($current);
     219    }
     220    else {
     221      $ret .= " ";
     222    }
     223  }
     224  return $ret;
    202225}
    203226
    204227function opensearchserver_encode($str) {
    205     $str2 = iconv('UTF-8', 'UTF-8//IGNORE', $str);
    206     if ($str2 == null) {
    207         $str2= mb_convert_encoding($str, 'UTF-8', 'UTF-8');
    208     }
    209     return stripInvalidXml($str2);
     228  $str2 = iconv('UTF-8', 'UTF-8//IGNORE', $str);
     229  if ($str2 == null) {
     230    $str2= mb_convert_encoding($str, 'UTF-8', 'UTF-8');
     231  }
     232  return opensearchserver_stripInvalidXml($str2);
    210233}
    211234
    212235function opensearchserver_optimize() {
    213     $server = opensearchserver_getapi_instance();
    214     $server->optimize();
    215 }
    216 
    217 function add_documents_to_index($sql_posts,$customFields) {
    218     $index = new OSSIndexDocument();
    219     $lang= substr(get_locale(), 0, 2);
    220     foreach($sql_posts as $post){
    221         $content=$post->post_content;
    222         $content = apply_filters('the_content', $content);
    223         $content = str_replace(']]>', ']]&gt;', $content);
    224         $content = opensearchserver_encode(strip_tags($content));
    225         $document = $index->newDocument($lang);
    226         $document->newField('id', $post->post_type.'_'.$post->ID);
    227         $document->newField('type', strip_tags($post->post_type));
    228         $document->newField('title', stripInvalidXml(strip_tags($post->post_title)));
    229         $document->newField('titleExact', stripInvalidXml(strip_tags($post->post_title)));
    230         $document->newField('content',stripInvalidXml($content));
    231         $document->newField('contentExact',stripInvalidXml($content));
    232         $document->newField('url', get_permalink($post->ID));
    233         $document->newField('urlExact', get_permalink($post->ID));
    234         $document->newField('timestamp', $post->post_date_gmt);
    235         $document->newField('user_name', $post->user_nicename);
    236         $document->newField('user_email', $post->user_email);
    237         $document->newField('user_email', $post->user_url);
    238         $custom_clean_all='';
    239         $categories_data= '';
    240         if($customFields) {
    241             $custom_fields_array=explode(",",$customFields);
    242             foreach($custom_fields_array as $field) {
    243                 $custom_content = '';
    244                 $custom_values=get_post_custom_values($field,$post->ID);
    245                 if(is_array($custom_values)) {
    246                     foreach ($custom_values as $values) {
    247                         $custom_content .= $values." ";
    248                     }
    249                 }else {
    250                     $custom_content = $custom_values;
    251                 }
    252                 $categories = get_the_category($post->ID);
    253                 if ( ! $categories == NULL ) {
    254                     foreach( $categories as $category ) {
    255                         $categories_data .= $category->cat_name.' ';
    256                     }
    257                 }
    258                 if($categories_data != '') {
    259                     $document->newField('categories', $categories_data);
    260                 }
    261                 $content_br = nl2br($custom_content);
    262                 $content_clean=str_replace("<br />", ' ', $content_br);
    263                 $document->newField("custom_".clean_field($field), stripInvalidXml(strip_tags($content_clean)));
    264                 $custom_clean_all .=' '.$content_clean;
    265             }
    266         }
    267         $all_content = stripInvalidXml(strip_tags($post->post_title)). ' '.$content;
    268         if($custom_clean_all) {
    269             $all_content .= ' ' .$custom_clean_all;
    270         }
    271         if($categories_data) {
    272             $document->newField("allContent", strip_tags($all_content.' '.$categories_data));
    273         }
    274     }
    275     return $index;
    276 }
     236  $server = opensearchserver_getapi_instance();
     237  $server->optimize();
     238}
     239
     240function opensearchserver_autocompletionBuild() {
     241  $autocompletion = opensearchserver_getautocomplete_instance();
     242  $autocompletion->autocompletionSet('contentExact');
     243  $autocompletion->autocompletionBuild();
     244}
     245
     246function opensearchserver_add_documents_to_index($sql_posts,$customFields) {
     247  $index = new OSSIndexDocument();
     248  $lang= substr(get_locale(), 0, 2);
     249  foreach($sql_posts as $post){
     250    $content=$post->post_content;
     251    $content = apply_filters('the_content', $content);
     252    $content = str_replace(']]>', ']]&gt;', $content);
     253    $content = opensearchserver_encode(strip_tags($content));
     254    $document = $index->newDocument($lang);
     255    $document->newField('id', $post->post_type.'_'.$post->ID);
     256    $document->newField('type', strip_tags($post->post_type));
     257    $title = opensearchserver_stripInvalidXml(strip_tags($post->post_title));
     258    $document->newField('title', $title);
     259    $document->newField('titleExact', $title);
     260    $document->newField('titlePhonetic', $title);
     261    $content = opensearchserver_stripInvalidXml($content);
     262    $document->newField('content', $content);
     263    $document->newField('contentExact', $content);
     264    $document->newField('contentPhonetic', $content);
     265    $document->newField('url', get_permalink($post->ID));
     266    $document->newField('urlExact', get_permalink($post->ID));
     267    $document->newField('timestamp', $post->post_date_gmt);
     268    $document->newField('user_name', $post->user_nicename);
     269    $document->newField('user_email', $post->user_email);
     270    $document->newField('user_email', $post->user_url);
     271    $categories_data= '';
     272
     273    // Handling categories
     274    $categories_data = null;
     275    $categories = get_the_category($post->ID);
     276    if ( ! $categories == NULL ) {
     277      foreach( $categories as $category ) {
     278        $categories_data .= $category->cat_name.' ';
     279        $document->newField('categories', $category->cat_name);
     280        $document->newField('categoriesExact', $category->cat_name);
     281      }
     282    }
     283
     284    // Handling custom fields
     285    $custom_clean_all='';
     286    if($customFields) {
     287      $custom_fields_array=explode(",",$customFields);
     288      foreach ($custom_fields_array as $field) {
     289        $custom_content = '';
     290        $custom_values=get_post_custom_values($field,$post->ID);
     291        if(is_array($custom_values)) {
     292          foreach ($custom_values as $values) {
     293            $custom_content .= $values." ";
     294          }
     295        }else {
     296          $custom_content = $custom_values;
     297        }
     298        $content_br = nl2br($custom_content);
     299        $content_clean=str_replace("<br />", ' ', $content_br);
     300        $document->newField("custom_".clean_field($field), stripInvalidXml(strip_tags($content_clean)));
     301        $custom_clean_all .=' '.$content_clean;
     302      }
     303    }
     304    // Build all content field
     305    $all_content = opensearchserver_stripInvalidXml(strip_tags($post->post_title)). ' '.$content;
     306    if ($categories_data) {
     307      $all_content = strip_tags($all_content.' '.$categories_data);
     308    }
     309    if ($custom_clean_all) {
     310      $all_content .= ' ' .$custom_clean_all;
     311    }
     312    $document->newField("allContent", strip_tags($all_content.' '.$categories_data));
     313  }
     314  return $index;
     315}
     316
     317function opensearchserver_default_query() {
     318  $q = 'title:($$)^10 OR title:("$$")^10'."\n";
     319  $q = $q.'OR titleExact:($$)^10 OR titleExact:("$$")^10'."\n";
     320  if (get_option('oss_phonetic')) {
     321    $q = $q.'OR titlePhonetic:($$)^10 OR titlePhonetic:("$$")^10'."\n";
     322    $q = $q.'OR contentPhonetic:($$) OR contentPhonetic:("$$")'."\n";
     323  }
     324  $q = $q.'OR content:($$) OR content:("$$")'."\n";
     325  $q = $q.'OR contentExact:($$) OR contentExact:("$$")'."\n";
     326  $q = $q.'OR allContent:($$)^0.1 OR allContent:("$$")^0.1';
     327  return $q;
     328}
     329
    277330function opensearchserver_get_fields() {
    278     return array("none"=>"Select","title" => "Title","content" =>"Content","url" => "Url","user_name" => "User Name","user_email" => "User Email","user_url" => "User URL","id" => "ID","type" => "Type","timestamp" => "TimeStamp");
    279 }
     331  return array('none'=>'Select',
     332    'title' => 'Title',
     333    'content' =>'Content',
     334    'url' => 'Url',
     335    'user_name' => 'User Name',
     336    'user_email' => 'User Email',
     337    'user_url' => 'User URL',
     338    'id' => 'ID',
     339    'type' => 'Type',
     340    'timestamp' => 'TimeStamp',
     341    'categoriesExact' => 'Categories');
     342}
     343
    280344/*
    281345 * The admin page settings actions
    282346*/
    283347function opensearchserver_admin_page() {
    284     $fields = opensearchserver_get_fields();
    285     $spellcheck_fields = array("none"=>"Select","title" => "Title","content" =>"Content");
    286     $action = isset($_POST['oss_submit']) ? $_POST['oss_submit'] :NULL;
    287     if($action == 'settings') {
    288         $oss_url = isset($_POST['oss_serverurl']) ? $_POST['oss_serverurl'] :NULL;
    289         $oss_indexname = isset($_POST['oss_indexname']) ? $_POST['oss_indexname'] :NULL;
    290         $oss_login = isset($_POST['oss_login']) ? $_POST['oss_login'] :NULL;
    291         $oss_key = isset($_POST['oss_key']) ? $_POST['oss_key'] :NULL;
    292         update_option('oss_serverurl', $oss_url);
    293         update_option('oss_indexname', $oss_indexname);
    294         update_option('oss_login', $oss_login);
    295         update_option('oss_key', $oss_key);
    296         opensearchserver_diaplay_messages('OpenSearchServer Settings has been updated');
    297 
    298     }if($action == 'query_settings') {
    299         $delete = isset($_POST['oss_delete']) ? $_POST['oss_delete'] :NULL;
    300         $delete_action = isset($_POST['opensearchserver_delete']) ? $_POST['opensearchserver_delete'] :NULL;
    301         if($delete !=NULL && $delete_action === 'Delete') {
    302             $facets = get_option('oss_facet');
    303             foreach ($facets as $key => $facet) {
    304                 if(trim($facet) == trim($delete)) {
    305                     unset($facets[$key]);
    306                 }
    307             }
    308             update_option('oss_facet', $facets);
    309         }else {
    310             $oss_query = isset($_POST['oss_query']) ? $_POST['oss_query'] :NULL;
    311             $oss_facet = isset($_POST['oss_facet']) ? $_POST['oss_facet'] :NULL;
    312             $oss_spell = isset($_POST['oss_spell']) ? $_POST['oss_spell'] :NULL;
    313             update_option('oss_query', $oss_query);
    314             if($oss_facet != 'none') {
    315                 if(get_option('oss_facet')) {
    316                     $facet = get_option('oss_facet');
    317                 }else {
    318                     $facet = array();
    319                 }
    320                 if (!in_array($oss_facet, $facet)) {
    321                     array_push($facet,$oss_facet);
    322                 }
    323                 update_option('oss_facet', $facet);
    324             }
    325             update_option('oss_spell', $oss_spell);
    326             opensearchserver_diaplay_messages('OpenSearchServer Settings has been updated.');
    327         }
    328 
    329     }if($action == 'index_settings') {
    330         $is_index_created = opensearchserver_create_index();
    331         if($is_index_created === TRUE) {
    332             opensearchserver_diaplay_messages('Index '.get_option('oss_indexname').' Created successfully');
    333         }else {
    334             opensearchserver_diaplay_messages('Error:10001 Index '.get_option('oss_indexname').' already exist');
    335         }
    336     }if($action == 'custom_field_settings') {
    337         $oss_custom_field = isset($_POST['oss_custom_field']) ? $_POST['oss_custom_field'] :NULL;
    338         update_option('oss_custom_field', $oss_custom_field);
    339         opensearchserver_diaplay_messages('OpenSearchServer Settings has been updated.');
    340     }
    341     if($action == 'opensearchserver_reindex') {
    342         $is_index_created = opensearchserver_create_index();
    343         $index_success = opensearchserver_reindex_site(NULL,NULL);
    344         opensearchserver_diaplay_messages('Re indexing has been finished successfully.');
    345     }
    346     ?>
     348  $fields = opensearchserver_get_fields();
     349  $spellcheck_fields = array(
     350    'none'=>'Select',
     351    'title' => 'Title',
     352    'content' =>'Content');
     353  $spellcheck_algo = array(
     354    'JaroWinklerDistance' => 'JaroWinklerDistance',
     355    'LevensteinDistance' => 'LevensteinDistance',
     356    'NGramDistance' => 'NGramDistance');
     357
     358  $action = isset($_POST['oss_submit']) ? $_POST['oss_submit'] :NULL;
     359  if($action == 'settings') {
     360    $oss_url = isset($_POST['oss_serverurl']) ? $_POST['oss_serverurl'] :NULL;
     361    $oss_indexname = isset($_POST['oss_indexname']) ? $_POST['oss_indexname'] :NULL;
     362    $oss_login = isset($_POST['oss_login']) ? $_POST['oss_login'] :NULL;
     363    $oss_key = isset($_POST['oss_key']) ? $_POST['oss_key'] :NULL;
     364    update_option('oss_serverurl', $oss_url);
     365    update_option('oss_indexname', $oss_indexname);
     366    update_option('oss_login', $oss_login);
     367    update_option('oss_key', $oss_key);
     368    opensearchserver_display_messages('OpenSearchServer Settings has been updated');
     369
     370  }if($action == 'query_settings') {
     371    $delete = isset($_POST['oss_delete']) ? $_POST['oss_delete'] :NULL;
     372    $delete_action = isset($_POST['opensearchserver_delete']) ? $_POST['opensearchserver_delete'] :NULL;
     373    if($delete !=NULL && $delete_action === 'Delete') {
     374      $facets = get_option('oss_facet');
     375      foreach ($facets as $key => $facet) {
     376        if(trim($facet) == trim($delete)) {
     377          unset($facets[$key]);
     378        }
     379      }
     380      update_option('oss_facet', $facets);
     381    }else {
     382      $oss_query = isset($_POST['oss_query']) ? $_POST['oss_query'] : NULL;
     383      if (isset($oss_query)) {
     384        $oss_query = trim($oss_query);
     385        if (strlen($oss_query) == 0) {
     386          $oss_query = opensearchserver_default_query();
     387        }
     388      }
     389      $oss_facet = isset($_POST['oss_facet']) ? $_POST['oss_facet'] : NULL;
     390      $oss_spell = isset($_POST['oss_spell']) ? $_POST['oss_spell'] : NULL;
     391      $oss_spell_algo = isset($_POST['oss_spell_algo']) ? $_POST['oss_spell_algo'] : NULL;
     392      update_option('oss_query', $oss_query);
     393      if($oss_facet != 'none') {
     394        if(get_option('oss_facet')) {
     395          $facet = get_option('oss_facet');
     396        }else {
     397          $facet = array();
     398        }
     399        if (!in_array($oss_facet, $facet)) {
     400          array_push($facet,$oss_facet);
     401        }
     402        update_option('oss_facet', $facet);
     403      }
     404      update_option('oss_spell', $oss_spell);
     405      update_option('oss_spell_algo', $oss_spell_algo);
     406      $oss_phonetic = isset($_POST['oss_phonetic']) ? $_POST['oss_phonetic'] : NULL;
     407      update_option('oss_phonetic', $oss_phonetic);
     408      opensearchserver_display_messages('OpenSearchServer Settings has been updated.');
     409    }
     410
     411  } if($action == 'index_settings') {
     412    $is_index_created = opensearchserver_create_index();
     413    opensearchserver_display_messages('Index '.get_option('oss_indexname').' Created successfully');
     414     
     415  }if($action == 'custom_field_settings') {
     416    $oss_custom_field = isset($_POST['oss_custom_field']) ? $_POST['oss_custom_field'] :NULL;
     417    update_option('oss_custom_field', $oss_custom_field);
     418    opensearchserver_display_messages('OpenSearchServer Settings has been updated.');
     419  }
     420  if($action == 'opensearchserver_reindex') {
     421    $is_index_created = opensearchserver_create_index();
     422    $index_success = opensearchserver_reindex_site(NULL,NULL);
     423    opensearchserver_display_messages('Re indexing has been finished successfully.');
     424  }
     425  ?>
    347426<div class="wrap">
    348427    <?php screen_icon( 'options-general' ); ?>
     
    413492                            <p>
    414493                                <label for="oss_query">OpenSearchServer Query</label>:<br />
    415                                 <textarea rows="10" cols="100" name="oss_query" wrap="off"><?php
    416                                     if(trim(get_option('oss_query'))) {
    417                                         print stripslashes(get_option('oss_query'));
    418                                     }
    419                                     ?></textarea>
     494                                <textarea rows="10" cols="100" name="oss_query" wrap="off">
     495<?php
     496if (trim(get_option('oss_query'))) {
     497  print stripslashes(get_option('oss_query'));
     498}
     499?>
     500                                </textarea>
    420501                            </p>
    421502                            <p>
     
    423504                                    name="oss_facet">
    424505                                    <?php
    425 
    426506                                    foreach ($fields as $key => $field) {
    427                                         ?>
     507                                      ?>
    428508                                    <option value="<?php print $key;?>">
    429509                                        <?php print $field;?>
     
    446526                                    <?php
    447527                                    foreach($facets as $facet) {
    448                                         ?>
     528                                      ?>
    449529                                    <tr>
    450530                                        <td><?php print $fields[$facet]; ?></td>
     
    464544                                    $facet = get_option('oss_spell');
    465545                                    foreach ($spellcheck_fields as $key => $field) {
    466                                         $selected = '';
    467                                         if($spellcheck_fields[$facet] == $field) {
    468                                             $selected = 'selected="selected"';
    469                                         }
    470                                         ?>
     546                                      $selected = '';
     547                                      if($spellcheck_fields[$facet] == $field) {
     548                                        $selected = 'selected="selected"';
     549                                      }
     550                                      ?>
     551                                    <option value="<?php print $key;?>" <?php print $selected;?>>
     552                                        <?php print $field;?>
     553                                    </option>
     554                                    <?php }?>
     555                                </select> <br /> <label for="oss_query">SpellCheck algorithm</label>:<br />
     556                                <select name="oss_spell_algo"><?php
     557                                $facet = get_option('oss_spell_algo');
     558                                foreach ($spellcheck_algo as $key => $field) {
     559                                  $selected = '';
     560                                  if($spellcheck_algo[$facet] == $field) {
     561                                    $selected = 'selected="selected"';
     562                                  }
     563                                  ?>
    471564                                    <option value="<?php print $key;?>" <?php print $selected;?>>
    472565                                        <?php print $field;?>
     
    475568                                </select>
    476569                            </p>
    477 
     570                            <p>
     571                                <label for="oss_phonetic">Enable phonetic</label>: <input
     572                                    type="checkbox" name="oss_phonetic" value="1"
     573                                    <?php checked( 1 == get_option('oss_phonetic')); ?> />
     574                            </p>
    478575                            <p>
    479576                                <input type="hidden" name="oss_submit" id="oss_submit"
     
    503600                                    id="oss_submit" value="index_settings" /><input type="submit"
    504601                                    name="opensearchserver_submit" value="Create Index"
    505                                     class="button-secondary" /><br />
     602                                    class="button-secondary" />
    506603                            </p>
    507604                        </form>
     
    523620                                    http://wordpress.org/extend/plugins/custom-field-template/</label>:
    524621                                <textarea rows="10" cols="100" name="oss_custom_field"
    525                                     wrap="off"><?php
     622                                    wrap="off">
     623                                    <?php
    526624                                    print stripslashes(get_option('oss_custom_field'));
    527                                     ?></textarea>
     625                                    ?>
     626                                </textarea>
    528627                            </p>
    529628                            <p>
     
    555654*/
    556655function opensearchserver_add_toogle() {
    557     ?>
     656  ?>
    558657<script type="text/javascript">
    559658    // <![CDATA[
  • opensearchserver-search/trunk/opensearchserver_search_functions.php

    r601998 r602348  
    5959    }
    6060}
    61 function opensearchserver_getsearchresult($query,$spellcheck,$facet) {
     61function opensearchserver_getsearchresult($query, $spellcheck, $facet) {
    6262    if($query) {
    6363        $start = isset($_REQUEST['pa']) ? $_REQUEST['pa'] : null;
    6464        $start = isset($start) ? max(0, $start - 1) * 10 : 0;
    65         $query = clean_query($query);
    66         $search = opensearchserver_getsearch_instance(10,$start);
     65        $query = opensearchserver_clean_query($query);
     66        $search = opensearchserver_getsearch_instance(10, $start);
    6767        if(!$spellcheck) {
    6868            opensearchserver_add_facets_search($search);
     
    8585
    8686
    87 function clean_query($query) {
     87function opensearchserver_clean_query($query) {
    8888    $escapechars = array('\\', '^', '~', ':', '(', ')', '{', '}', '[', ']' , '&', '||', '!', '*', '?','039;','\'','#');
    8989    foreach ($escapechars as $escchar)  {
     
    103103    return ($oss_results->getResultStart() + $oss_results->getResultRows() > $oss_results->getResultFound()) ? $oss_results->getResultFound() : $oss_results->getResultStart() + $oss_results->getResultRows();
    104104}
    105 function get_custom_fields() {
     105function opensearchserver_get_custom_fields() {
    106106    return explode(",",get_option('oss_custom_field'));
    107107}
  • opensearchserver-search/trunk/readme.txt

    r601998 r602348  
    44Requires at least: 3.0.1
    55Tested up to: 3.4.2
    6 Stable tag: 1.0.8
     6Stable tag: 1.0.9
    77License: GPLv2 or later
    88
     
    1010
    1111== Description ==
    12 WordPress OpenSearchServer Search Plugin allows to use OpenSearchServer to enable full text search on WordPress-based websites. This plugin replaces WordPress's built-in search functionality.
     12WordPress OpenSearchServer Search Plugin allows to use OpenSearchServer to enable full text search on WordPress-based websites. Including spellcheck, facet, filter, phonetic search, autocompletion. This plugin replaces WordPress's built-in search functionality.
    1313
    1414Key Features
    1515
     16 * Full-text search with phonetic support,
    1617 * Filter search results by Facet Field,
     18 * Automatic suggestion with autocompletion,
     19 * Spellcheking with automatic substitution,
    1720 * Automatically index an post when you publish an post,
    1821 * Search through posts and pages,
     
    2326= Requirements =
    2427
    25     * WordPress 3.0.0 or higher
     28    * WordPress 3.0.1 or higher
    2629
    2730= Installing the plugin =
     
    56592. Search provided by OpenSearchServer with facet and filter.
    5760
     61= 1.0.9 =
     62* Phonetic search
     63* Custom fields support
     64* Facets and filters on categories
     65* CSS and javascript improvements
     66
    5867= 1.0.8 =
    5968* Improved OpenSearchServer settings page.
  • opensearchserver-search/trunk/template/opensearchserver_search.php

    r601998 r602348  
    77<div id="oss-search">
    88    <div id="oss-search-form">
    9         <form method="get" id="searchform" action=<?php print home_url('/');?>>
     9        <form method="get" id="oss-searchform"
     10            action=<?php print home_url('/');?>>
    1011            <input type="text" value="<?php print get_search_query();?>" name="s"
    11                 id="keyword" size="45" onkeyup="return autosuggest(event)"
     12                id="oss-keyword" size="45"
     13                onkeyup="return OpenSearchServer.autosuggest(event)"
    1214                autocomplete="off" /> <input type="submit" id="oss-submit"
    1315                value="Search" />
    1416            <div style="position: absolute">
    15                 <div id="autocomplete"></div>
     17                <div id="oss-autocomplete"></div>
    1618            </div>
    1719        </form>
    1820    </div>
    1921    <?php
     22    $query_fq_parm = isset($_REQUEST['fq']) ? $_REQUEST['fq'] : NULL;
    2023    $query = get_search_query();
    21     $oss_result = opensearchserver_getsearchresult($query, FALSE,TRUE);
     24    $oss_result = opensearchserver_getsearchresult($query, FALSE, TRUE);
    2225    $oss_result_facet = opensearchserver_getsearchresult($query, FALSE, FALSE);
    2326    $oss_sp= isset($_REQUEST['sp']) ? $_REQUEST['sp'] :NULL;
    2427    if (isset($oss_result) && $oss_result instanceof SimpleXMLElement && isset($oss_result_facet) && $oss_result_facet instanceof SimpleXMLElement) {
    25         $oss_results = opensearchserver_getresult_instance($oss_result);
    26         $oss_result_facets = opensearchserver_getresult_instance($oss_result_facet);
    27         if($oss_results->getResultFound() <= 0 && $oss_sp != 1) {
    28             $oss_spell_result = opensearchserver_getsearchresult($query, TRUE,NULL);
    29             $spellcheck_query = opensearchserver_getspellcheck($oss_spell_result);
    30             $oss_result =  opensearchserver_getsearchresult($spellcheck_query, FALSE, TRUE);
    31             if (isset($oss_result) && $oss_result instanceof SimpleXMLElement && isset($oss_result_facet) && $oss_result_facet instanceof SimpleXMLElement) {
    32                 $oss_results = opensearchserver_getresult_instance($oss_result);
    33                 $oss_result_facet = opensearchserver_getsearchresult($spellcheck_query, FALSE, FALSE);
    34                 $oss_result_facets = opensearchserver_getresult_instance($oss_result_facet);
    35             }
    36         }
    37         $oss_resultTime = isset($oss_result) ? (float)$oss_result->result['time'] / 1000 : NULL;
    38         $max = opensearchserver_get_max($oss_results);
    39         if($oss_sp == 1 || $oss_results->getResultFound() <= 0) {
    40             ?>
     28      $oss_results = opensearchserver_getresult_instance($oss_result);
     29      $oss_result_facets = opensearchserver_getresult_instance($oss_result_facet);
     30      if($oss_results->getResultFound() <= 0 && $oss_sp != 1) {
     31        $oss_spell_result = opensearchserver_getsearchresult($query, TRUE,NULL);
     32        $spellcheck_query = opensearchserver_getspellcheck($oss_spell_result);
     33        $oss_result =  opensearchserver_getsearchresult($spellcheck_query, FALSE, TRUE);
     34        if (isset($oss_result) && $oss_result instanceof SimpleXMLElement && isset($oss_result_facet) && $oss_result_facet instanceof SimpleXMLElement) {
     35          $oss_results = opensearchserver_getresult_instance($oss_result);
     36          $oss_result_facet = opensearchserver_getsearchresult($spellcheck_query, FALSE, FALSE);
     37          $oss_result_facets = opensearchserver_getresult_instance($oss_result_facet);
     38        }
     39      }
     40      $oss_resultTime = isset($oss_result) ? (float)$oss_result->result['time'] / 1000 : NULL;
     41      $max = opensearchserver_get_max($oss_results);
     42      if($oss_sp == 1 || $oss_results->getResultFound() <= 0) {
     43        ?>
    4144    <div align="left" id="oss_error">
    4245        No documents containing all your search terms were found.<br /> Your
     
    4750    </div>
    4851    <?php
    49         }
    50         else {
    51             ?>
     52      }
     53      else {
     54        ?>
    5255    <div id="oss-filter">
    5356        <?php $facets = get_option('oss_facet');
    5457        foreach ($facets as $facet) {
    55             $facet_results = $oss_result_facets->getFacet($facet);
    56             ?>
    57         <div id="oss-filter-title"></div>
    58         <b><?php
    59         $fields = opensearchserver_get_fields();
    60         print ucfirst($fields[$facet]);?> </b>
    61         <ul id="oss-nav">
     58          $facet_results = $oss_result_facets->getFacet($facet);
     59          ?>
     60        <div class="oss-filter-title">
     61            <?php
     62            $fields = opensearchserver_get_fields();
     63            print ucfirst($fields[$facet]);?>
     64        </div>
     65        <ul class="oss-nav">
    6266            <li class="oss-top-nav"><a
    63                 href="<?php print '?s='.urlencode($query).'&fq=All';?>">All</a>
     67                href="<?php print '?s='.urlencode($query);?>">All</a>
    6468            </li>
    6569            <?php
    6670            if(count($facet_results) > 0 ) {
    67                 foreach ($facet_results as $values) {
    68                     $value = $values['name'];
    69                     ?>
    70             <li><a id="oss-link"
    71                 href="?s=<?php print $query.'&fq='.$facet. ':' .$value ?>"><?php print $value.'('.$values.')';?>
     71              foreach ($facet_results as $values) {
     72                $value = $values['name'];
     73                $fqParm = $facet. ':' .$value;
     74                ?>
     75            <li><a
     76                class="oss-link<?php if ($query_fq_parm == $fqParm) {?> oss-bold<?php } ?>"
     77                href="?s=<?php print $query.'&fq='.urlencode($fqParm); ?>"><?php print $value.'('.$values.')';?>
    7278            </a>
    7379            </li>
     
    8490        <?php print $oss_results->getResultFound().' documents found ('.$oss_resultTime.' seconds)';
    8591        if($oss_sp != 1 && $oss_results->getResultFound() > 0) {
    86             ?>
     92          ?>
    8793        <div id="oss-did-you-mean">
    8894            <?php if(isset($spellcheck_query)) { ?>
     
    98104        <?php
    99105        for ($i = $oss_results->getResultStart(); $i < $max; $i++) {
    100             $category    = stripslashes($oss_results->getField($i, 'type', true));
    101             $title   = stripslashes($oss_results->getField($i, 'title', true));
    102             $content = stripslashes($oss_results->getField($i, 'content', true));
    103             $user = stripslashes($oss_results->getField($i, 'user_name', true));
    104             $user_url = stripslashes($oss_results->getField($i, 'user_url', true));
    105             $type = stripslashes($oss_results->getField($i, 'type', true));
    106             $url = stripslashes($oss_results->getField($i, 'url', false));
    107             $categories = stripslashes($oss_results->getField($i, 'categories', false));
    108             ?>
     106          $category  = stripslashes($oss_results->getField($i, 'type', true));
     107          $title     = stripslashes($oss_results->getField($i, 'title', true));
     108          $content = stripslashes($oss_results->getField($i, 'content', true, true));
     109          if ($content == null) {
     110            $content = stripslashes($oss_results->getField($i, 'contentPhonetic', true, true));
     111            if ($content == null) {
     112              $content = stripslashes($oss_results->getField($i, 'content', true, false));
     113            }
     114          }
     115          $user = stripslashes($oss_results->getField($i, 'user_name', true));
     116          $user_url = stripslashes($oss_results->getField($i, 'user_url', true));
     117          $type = stripslashes($oss_results->getField($i, 'type', true));
     118          $url = stripslashes($oss_results->getField($i, 'url', false));
     119          $categories = stripslashes($oss_results->getField($i, 'categories', false));
     120          ?>
    109121
    110         <div id="oss-result">
     122        <div class="oss-result">
    111123            <?php
    112                 if($title) {?>
    113             <div id="oss-title">
     124                if ($title) {?>
     125            <div class="oss-title">
    114126                <a href="<?php print $url;?>"><?php print $title;?> </a><br />
    115127            </div>
     
    118130            <?php }
    119131            ?>
    120             <div id="oss-content">
     132            <div class="oss-content">
    121133                <?php if ($content) {
    122                     print $content.'<br/>';
     134                  print $content.'<br/>';
    123135                }
    124                 $custom_fields_array = get_custom_fields();
     136                $custom_fields_array = opensearchserver_get_custom_fields();
    125137                foreach($custom_fields_array as $field) {
    126                     $value = stripslashes($oss_results->getField($i, "custom_".clean_field($field), false));
    127                     if($value) {
    128                         print '<b>'. $field.'</b> : '.$value.'<br/>';
    129                     }
     138                  $value = stripslashes($oss_results->getField($i, "custom_".opensearchserver_clean_field($field), false));
     139                  if($value) {
     140                    print '<b>'. $field.'</b> : '.$value.'<br/>';
     141                  }
    130142                }
    131143                ?>
    132144            </div>
    133             <div id="oss-url">
     145            <div class="oss-url">
    134146                <?php
    135147     if($url) {?>
     
    138150                if($type && $user ) {
    139151
    140                     print $type."   By  ".$user;
    141                     if($categories != NULL || $categories != '') {
    142                         print ' in '. $categories. '<br/>';
    143                     }else {
    144                         print '<br/>';
    145                     }
     152                  print $type." By  ".$user;
     153                  if($categories != NULL || $categories != '') {
     154                    print ' in '. $categories. '<br/>';
     155                  }else {
     156                    print '<br/>';
     157                  }
    146158                }?>
    147159            </div>
    148160        </div>
    149         <br />
    150161        <?php
    151162        }
     
    162173        <?php }
    163174        else {
    164             print '<span id="oss-page">'.$page['label'].'</span>';
     175          print '<span id="oss-page">'.$page['label'].'</span>';
    165176        }
    166177            } ?>
     
    174185</div>
    175186<?php
    176         }
     187      }
    177188    }
    178189
Note: See TracChangeset for help on using the changeset viewer.