Changeset 602348
- Timestamp:
- 09/22/2012 02:44:19 PM (13 years ago)
- Location:
- opensearchserver-search/trunk
- Files:
-
- 16 edited
-
css/oss-style.css (modified) (2 diffs)
-
index.php (modified) (1 diff)
-
js/opensearchserver.js (modified) (6 diffs)
-
lib/oss_abstract.class.php (modified) (4 diffs)
-
lib/oss_api.class.php (modified) (2 diffs)
-
lib/oss_autocompletion.class.php (modified) (2 diffs)
-
lib/oss_exception.class.php (modified) (2 diffs)
-
lib/oss_indexdocument.class.php (modified) (1 diff)
-
lib/oss_results.class.php (modified) (4 diffs)
-
lib/oss_searchtemplate.class.php (modified) (3 diffs)
-
opensearchserver_admin.php (modified) (10 diffs)
-
opensearchserver_search_functions.php (modified) (3 diffs)
-
readme.txt (modified) (4 diffs)
-
screenshot-1.png (modified) (previous)
-
screenshot-2.png (modified) (previous)
-
template/opensearchserver_search.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
opensearchserver-search/trunk/css/oss-style.css
r601998 r602348 1 1 /* OpenSearchServer result page */ 2 3 2 #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%; 27 4 } 28 5 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; 35 41 width: 180px; 36 42 } 37 #oss-filter-not-selected a{ 38 font-size:11px; 43 44 .oss-filter-title { 45 font-size: 110%; 39 46 } 40 #oss-filter-selected a{ 41 color: #DD4B39; 42 cursor: pointer; 43 font-size:11px; 47 48 .oss-bold { 49 font-weight: bold; 44 50 } 51 45 52 #oss-paging { 46 53 margin: 0; 47 padding: 0;48 text-align: center; 54 padding: 0; 55 text-align: center; 49 56 } 50 57 58 #oss-search-form #keyword { 59 border: 1px solid #ccc; 60 width: 570px; 61 height: 25px; 62 } 51 63 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; 59 81 } 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; 79 85 } 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; 82 92 } 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 }92 93 93 . autocomplete_link {94 font-size: 1 2px;94 .oss-autocomplete_link { 95 font-size: 100%; 95 96 background-color: #FFFFFF; 96 97 padding: 2px 6px 2px 6px; 97 98 } 98 99 99 . autocomplete_link_over {100 font-size: 1 2px;100 .oss-autocomplete_link_over { 101 font-size: 100%; 101 102 background-color: #99BBFF; 102 103 padding: 2px 6px 2px 6px; 103 104 } 104 105 105 # autocomplete {106 #oss-autocomplete { 106 107 margin: 0; 107 108 width: 380px; … … 110 111 } 111 112 112 # autocompletelist {113 #oss-autocompletelist { 113 114 background-color: #FFFFFF; 114 115 text-align: left; 115 116 z-index: 1000; 116 position:absolute;width: 380px; 117 position: absolute; 118 width: 380px; 117 119 border: 1px solid #99BBFF; 118 120 } 121 119 122 #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; 126 124 } 127 125 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 }157 126 #oss-facets-menu { 158 127 vertical-align: middle; 159 margin: 0;160 list-style: none;128 margin: 0; 129 list-style: none; 161 130 } 131 162 132 #oss-facets { 163 padding-top: 10px;133 padding-top: 10px; 164 134 } 165 .oss-facets-li a{ 135 136 .oss-facets-li a { 166 137 color: #222222; 167 138 } 139 168 140 .oss-facets-li { 169 padding-left: 10px;170 margin-top: 0;141 padding-left: 10px; 142 margin-top: 0; 171 143 } 144 172 145 #oss-facets-menu li:hover { 173 background: #EEEEEE;146 background: #EEEEEE; 174 147 } 148 175 149 #oss-facets-menu li a { 176 text-decoration: none;150 text-decoration: none; 177 151 } 178 179 .oss-submenu {152 153 .oss-submenu { 180 154 display: none; 181 155 list-style: none; 182 padding-left: 15px;183 margin: 0;156 padding-left: 15px; 157 margin: 0; 184 158 } 159 185 160 .oss-top-nav a { 186 color: #000000;161 color: #000000; 187 162 } 163 188 164 #oss-menu-selected a { 189 165 color: #DD4B39; 190 166 cursor: pointer; 191 167 } 168 192 169 #oss-head a { 193 font-size: 16px;170 font-size: 120%; 194 171 color: #1122CC; 195 margin-top: 0;196 clear: both;172 margin-top: 0; 173 clear: both; 197 174 } 175 198 176 #oss-nav { 199 177 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; 218 183 } 219 184 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; 296 187 } 297 188 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; 306 191 } 307 192 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; 323 195 } 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 25 25 */ 26 26 function 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'); 28 28 } 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' );29 function 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' ); 35 35 } 36 36 function opensearchserver_search() { 37 37 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 } 57 57 } 58 58 function opensearchserver_install() { 59 $oss_query = 'title:($$)^10 OR title:("$$")^10 OR allContent:($$) OR allContent:("$$")60 OR61 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); 63 63 } 64 64 65 65 function 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'); 73 73 } 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 }74 function 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 } 83 83 } 84 84 register_activation_hook(__FILE__,'opensearchserver_install'); 85 85 register_deactivation_hook( __FILE__, 'opensearchserver_uninstall'); 86 add_action('save_post',' do_while_posting',10,2);87 add_action('wp_enqueue_scripts',' load_scripts_styles' );86 add_action('save_post','opensearchserver_do_while_posting',10,2); 87 add_action('wp_enqueue_scripts','opensearchserver_load_scripts_styles' ); 88 88 add_action('admin_menu', 'opensearchserver_admin_actions'); 89 89 add_action('template_redirect', 'opensearchserver_search'); -
opensearchserver-search/trunk/js/opensearchserver.js
r601998 r602348 1 function getXmlHttpRequestObject() { 1 if (typeof (OpenSearchServer) == "undefined") 2 OpenSearchServer = {}; 3 4 OpenSearchServer.getXmlHttpRequestObject = function() { 2 5 if (window.XMLHttpRequest) { 3 6 return new XMLHttpRequest(); … … 7 10 return null; 8 11 } 9 } 12 }; 10 13 11 var xmlHttp =getXmlHttpRequestObject();14 OpenSearchServer.xmlHttp = OpenSearchServer.getXmlHttpRequestObject(); 12 15 13 function setAutocomplete(value) {14 var ac = document.getElementById(' autocomplete');16 OpenSearchServer.setAutocomplete = function(value) { 17 var ac = document.getElementById('oss-autocomplete'); 15 18 ac.innerHTML = value; 16 19 return ac; 17 } 20 }; 18 21 19 varselectedAutocomplete = 0;20 varautocompleteSize = 0;22 OpenSearchServer.selectedAutocomplete = 0; 23 OpenSearchServer.autocompleteSize = 0; 21 24 22 function getselectedautocompletediv(n) {23 return document.getElementById(' autocompleteitem' + n);24 } 25 OpenSearchServer.getselectedautocompletediv = function(n) { 26 return document.getElementById('oss-autocompleteitem' + n); 27 }; 25 28 26 function autosuggest(event) {27 var keynum ;29 OpenSearchServer.autosuggest = function(event) { 30 var keynum = 0; 28 31 if (window.event) { // IE 29 32 keynum = event.keyCode; … … 33 36 if (keynum == 38 || keynum == 40) { 34 37 if (selectedAutocomplete > 0) { 35 autocompleteLinkOut(selectedAutocomplete);38 OpenSearchServer.autocompleteLinkOut(selectedAutocomplete); 36 39 } 37 40 if (keynum == 38) { … … 45 48 } 46 49 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); 50 53 } 51 54 return false; 52 55 } 53 56 54 if (xmlHttp.readyState != 4 && xmlHttp.readyState != 0) 57 if (OpenSearchServer.xmlHttp.readyState != 4 58 && OpenSearchServer.xmlHttp.readyState != 0) 55 59 return; 56 var str = escape(document.getElementById(' keyword').value);60 var str = escape(document.getElementById('oss-keyword').value); 57 61 if (str.length == 0) { 58 setAutocomplete('');62 OpenSearchServer.setAutocomplete(''); 59 63 return; 60 64 } 61 65 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); 65 69 return true; 66 } 70 }; 67 71 68 function handleAutocomplete() {69 if ( xmlHttp.readyState != 4)72 OpenSearchServer.handleAutocomplete = function() { 73 if (OpenSearchServer.xmlHttp.readyState != 4) 70 74 return; 71 var ac = setAutocomplete('');72 var resp = xmlHttp.responseText;75 var ac = OpenSearchServer.setAutocomplete(''); 76 var resp = OpenSearchServer.xmlHttp.responseText; 73 77 if (resp == null) { 74 78 return; … … 78 82 } 79 83 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++) { 82 86 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>'; 88 94 } 89 95 content += '</div>'; … … 91 97 selectedAutocomplete = 0; 92 98 autocompleteSize = str.length; 93 } 99 }; 94 100 95 function autocompleteLinkOver(n) {101 OpenSearchServer.autocompleteLinkOver = function(n) { 96 102 if (selectedAutocomplete > 0) { 97 autocompleteLinkOut(selectedAutocomplete);103 OpenSearchServer.autocompleteLinkOut(selectedAutocomplete); 98 104 } 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'; 103 108 selectedAutocomplete = n; 104 109 } 105 } 110 }; 106 111 107 function autocompleteLinkOut(n) {108 var dv = getselectedautocompletediv(n);112 OpenSearchServer.autocompleteLinkOut = function(n) { 113 var dv = OpenSearchServer.getselectedautocompletediv(n); 109 114 if (dv != null) { 110 dv.className = ' autocomplete_link';115 dv.className = 'oss-autocomplete_link'; 111 116 } 112 } 113 function setsetKeywords_onClick(value) { 114 var dv = document.getElementById('keyword'); 117 }; 118 119 OpenSearchServer.setKeywords_onClick = function(value) { 120 var dv = document.getElementById('oss-keyword'); 115 121 if (dv != null) { 116 122 dv.value = value; 117 123 dv.focus(); 118 setAutocomplete('');119 document.forms[' searchformForm'].submit()124 OpenSearchServer.setAutocomplete(''); 125 document.forms['oss-searchform'].submit(); 120 126 return true; 121 127 } 122 } 123 function setKeywords(value) { 124 var dv = document.getElementById('keyword'); 128 }; 129 130 OpenSearchServer.setKeywords = function(value) { 131 var dv = document.getElementById('oss-keyword'); 125 132 if (dv != null) { 126 133 dv.value = value; 127 134 dv.focus(); 128 135 } 129 } 136 }; -
opensearchserver-search/trunk/lib/oss_abstract.class.php
r601998 r602348 70 70 * param string[] $options Additional query parameters 71 71 * return string 72 * Use OssApi::API_* constants for $apiCall.73 72 * Optionals query parameters are provided as a named list: 74 73 * array( … … 134 133 // Use CURL to post the data 135 134 136 $rcurl = curl_init($url);135 $rcurl = curl_init($url); 137 136 curl_setopt($rcurl, CURLOPT_HTTP_VERSION, '1.0'); 138 137 curl_setopt($rcurl, CURLOPT_BINARYTRANSFER, TRUE); … … 192 191 } 193 192 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 194 197 /** 195 198 * Post data to an URL and retrieve an XML … … 199 202 * @param int $timeout Optional. Number of seconds before the query fail 200 203 * @return SimpleXMLElement 201 * Use OssApi::queryServerto retrieve an XML and check its validity204 * Use queryServer to retrieve an XML and check its validity 202 205 */ 203 206 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); 205 208 if ($result === FALSE) { 206 209 return FALSE; -
opensearchserver-search/trunk/lib/oss_api.class.php
r601998 r602348 132 132 */ 133 133 public function optimize() { 134 $return = $this->queryServer ($this->getQueryURL(OssApi::API_OPTIMIZE));134 $return = $this->queryServerTXT(OssApi::API_OPTIMIZE); 135 135 return ($return !== FALSE); 136 136 } … … 144 144 */ 145 145 public function reload() { 146 $return = $this->queryServer ($this->getQueryURL(OssApi::API_RELOAD));146 $return = $this->queryServerTXT(OssApi::API_RELOAD); 147 147 return ($return !== FALSE); 148 148 } -
opensearchserver-search/trunk/lib/oss_autocompletion.class.php
r601998 r602348 34 34 } 35 35 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) { 37 42 $params = array('query' => $query, 'rows' => $rows); 38 $return = OssApi::queryServer($this->getQueryURL(OssApi::API_AUTOCOMPLETION, $params));43 $return = $this->queryServerTXT(OssApi::API_AUTOCOMPLETION, $params); 39 44 if ($return === FALSE) { 40 45 return FALSE; … … 42 47 return $return; 43 48 } 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 } 44 82 } 45 83 ?> -
opensearchserver-search/trunk/lib/oss_exception.class.php
r601998 r602348 1 1 <?php 2 2 /* 3 * This file is part of OpenSearchServer.3 * This file is part of OpenSearchServer. 4 4 * 5 5 * Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft … … 70 70 $data = array(); 71 71 foreach ($xmlDoc->entry as $entry) 72 $data[(string)$entry['key']] = (string)$entry;72 $data[(string)$entry['key']] = (string)$entry; 73 73 74 74 $this->status = $data['Status']; -
opensearchserver-search/trunk/lib/oss_indexdocument.class.php
r601998 r602348 1 1 <?php 2 2 /* 3 * This file is part of OpenSearchServer.3 * This file is part of OpenSearchServer. 4 4 * 5 5 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft -
opensearchserver-search/trunk/lib/oss_results.class.php
r601998 r602348 1 1 <?php 2 2 /* 3 * This file is part of OpenSearchServer.3 * This file is part of OpenSearchServer. 4 4 * 5 5 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft … … 85 85 * GETTER 86 86 */ 87 public function getField($position, $fieldName, $modeSnippet = FALSE ) {87 public function getField($position, $fieldName, $modeSnippet = FALSE, $highlightedOnly = FALSE) { 88 88 $field = NULL; 89 89 $doc = $this->result->xpath('result/doc[@pos="' . $position . '"]'); … … 92 92 $value = NULL; 93 93 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 } 95 99 } 96 100 if (!isset($value) || count($value) == 0) { … … 156 160 157 161 /** 158 *159 * @return Return the spellsuggest array.160 */162 * 163 * @return Return the spellsuggest array. 164 */ 161 165 public function getSpellSuggestions($fieldName) { 162 166 $currentSpellCheck = isset($fieldName)? $this->result->xpath('spellcheck/field[@name="' . $fieldName . '"]/word/suggest'):NULL; -
opensearchserver-search/trunk/lib/oss_searchtemplate.class.php
r601998 r602348 44 44 45 45 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); 47 47 if ($qtquery) { 48 48 $params['qt.query'] = $qtquery; … … 66 66 /* 67 67 * Function to create spell check Query Template 68 * $qtsuggestions - No of suggestions to be returned69 * $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)LevensteinDistance73 * 2)NGramDistance74 * 3)JaroWinklerDistance75 */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 */ 76 76 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 } 91 91 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; 97 97 } 98 98 $params['cmd'] = OssSearchTemplate::API_SEARCH_TEMPLATE_CREATE; … … 125 125 $params['snippetfield'] = $snippetField; 126 126 $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); 128 128 return $return === FALSE ? FALSE : TRUE; 129 129 } -
opensearchserver-search/trunk/opensearchserver_admin.php
r601998 r602348 4 4 */ 5 5 function 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')); 7 7 } 8 8 function 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')); 10 10 } 11 11 function 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')); 13 13 } 14 14 function 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')); 16 16 } 17 17 function 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 */ 23 26 function 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 42 function 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); 43 49 } 44 50 … … 49 55 50 56 function 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 69 80 /* 70 81 * Function to display messages in admin 71 82 */ 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 } 83 function 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 81 93 /* 82 94 * Function to update the query template 83 95 */ 84 96 function 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 98 114 /* 99 115 * Function to create the spellcheck query 100 116 */ 101 117 function 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 107 126 /* 108 127 * Function to reindex the website. 109 128 */ 110 129 function 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 182 function opensearchserver_delete_document($query) { 183 return opensearchserver_getdelete_instance()->delete($query); 163 184 } 164 185 165 186 function 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 193 function 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 203 function 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; 202 225 } 203 226 204 227 function 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 returnstripInvalidXml($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); 210 233 } 211 234 212 235 function 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(']]>', ']]>', $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 240 function opensearchserver_autocompletionBuild() { 241 $autocompletion = opensearchserver_getautocomplete_instance(); 242 $autocompletion->autocompletionSet('contentExact'); 243 $autocompletion->autocompletionBuild(); 244 } 245 246 function 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(']]>', ']]>', $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 317 function 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 277 330 function 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 280 344 /* 281 345 * The admin page settings actions 282 346 */ 283 347 function 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 ?> 347 426 <div class="wrap"> 348 427 <?php screen_icon( 'options-general' ); ?> … … 413 492 <p> 414 493 <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 496 if (trim(get_option('oss_query'))) { 497 print stripslashes(get_option('oss_query')); 498 } 499 ?> 500 </textarea> 420 501 </p> 421 502 <p> … … 423 504 name="oss_facet"> 424 505 <?php 425 426 506 foreach ($fields as $key => $field) { 427 ?>507 ?> 428 508 <option value="<?php print $key;?>"> 429 509 <?php print $field;?> … … 446 526 <?php 447 527 foreach($facets as $facet) { 448 ?>528 ?> 449 529 <tr> 450 530 <td><?php print $fields[$facet]; ?></td> … … 464 544 $facet = get_option('oss_spell'); 465 545 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 ?> 471 564 <option value="<?php print $key;?>" <?php print $selected;?>> 472 565 <?php print $field;?> … … 475 568 </select> 476 569 </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> 478 575 <p> 479 576 <input type="hidden" name="oss_submit" id="oss_submit" … … 503 600 id="oss_submit" value="index_settings" /><input type="submit" 504 601 name="opensearchserver_submit" value="Create Index" 505 class="button-secondary" /> <br />602 class="button-secondary" /> 506 603 </p> 507 604 </form> … … 523 620 http://wordpress.org/extend/plugins/custom-field-template/</label>: 524 621 <textarea rows="10" cols="100" name="oss_custom_field" 525 wrap="off"><?php 622 wrap="off"> 623 <?php 526 624 print stripslashes(get_option('oss_custom_field')); 527 ?></textarea> 625 ?> 626 </textarea> 528 627 </p> 529 628 <p> … … 555 654 */ 556 655 function opensearchserver_add_toogle() { 557 ?>656 ?> 558 657 <script type="text/javascript"> 559 658 // <![CDATA[ -
opensearchserver-search/trunk/opensearchserver_search_functions.php
r601998 r602348 59 59 } 60 60 } 61 function opensearchserver_getsearchresult($query, $spellcheck,$facet) {61 function opensearchserver_getsearchresult($query, $spellcheck, $facet) { 62 62 if($query) { 63 63 $start = isset($_REQUEST['pa']) ? $_REQUEST['pa'] : null; 64 64 $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); 67 67 if(!$spellcheck) { 68 68 opensearchserver_add_facets_search($search); … … 85 85 86 86 87 function clean_query($query) {87 function opensearchserver_clean_query($query) { 88 88 $escapechars = array('\\', '^', '~', ':', '(', ')', '{', '}', '[', ']' , '&', '||', '!', '*', '?','039;','\'','#'); 89 89 foreach ($escapechars as $escchar) { … … 103 103 return ($oss_results->getResultStart() + $oss_results->getResultRows() > $oss_results->getResultFound()) ? $oss_results->getResultFound() : $oss_results->getResultStart() + $oss_results->getResultRows(); 104 104 } 105 function get_custom_fields() {105 function opensearchserver_get_custom_fields() { 106 106 return explode(",",get_option('oss_custom_field')); 107 107 } -
opensearchserver-search/trunk/readme.txt
r601998 r602348 4 4 Requires at least: 3.0.1 5 5 Tested up to: 3.4.2 6 Stable tag: 1.0. 86 Stable tag: 1.0.9 7 7 License: GPLv2 or later 8 8 … … 10 10 11 11 == 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.12 WordPress 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. 13 13 14 14 Key Features 15 15 16 * Full-text search with phonetic support, 16 17 * Filter search results by Facet Field, 18 * Automatic suggestion with autocompletion, 19 * Spellcheking with automatic substitution, 17 20 * Automatically index an post when you publish an post, 18 21 * Search through posts and pages, … … 23 26 = Requirements = 24 27 25 * WordPress 3.0. 0or higher28 * WordPress 3.0.1 or higher 26 29 27 30 = Installing the plugin = … … 56 59 2. Search provided by OpenSearchServer with facet and filter. 57 60 61 = 1.0.9 = 62 * Phonetic search 63 * Custom fields support 64 * Facets and filters on categories 65 * CSS and javascript improvements 66 58 67 = 1.0.8 = 59 68 * Improved OpenSearchServer settings page. -
opensearchserver-search/trunk/template/opensearchserver_search.php
r601998 r602348 7 7 <div id="oss-search"> 8 8 <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('/');?>> 10 11 <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)" 12 14 autocomplete="off" /> <input type="submit" id="oss-submit" 13 15 value="Search" /> 14 16 <div style="position: absolute"> 15 <div id=" autocomplete"></div>17 <div id="oss-autocomplete"></div> 16 18 </div> 17 19 </form> 18 20 </div> 19 21 <?php 22 $query_fq_parm = isset($_REQUEST['fq']) ? $_REQUEST['fq'] : NULL; 20 23 $query = get_search_query(); 21 $oss_result = opensearchserver_getsearchresult($query, FALSE, TRUE);24 $oss_result = opensearchserver_getsearchresult($query, FALSE, TRUE); 22 25 $oss_result_facet = opensearchserver_getsearchresult($query, FALSE, FALSE); 23 26 $oss_sp= isset($_REQUEST['sp']) ? $_REQUEST['sp'] :NULL; 24 27 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 ?> 41 44 <div align="left" id="oss_error"> 42 45 No documents containing all your search terms were found.<br /> Your … … 47 50 </div> 48 51 <?php 49 }50 else {51 ?>52 } 53 else { 54 ?> 52 55 <div id="oss-filter"> 53 56 <?php $facets = get_option('oss_facet'); 54 57 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"> 62 66 <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> 64 68 </li> 65 69 <?php 66 70 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.')';?> 72 78 </a> 73 79 </li> … … 84 90 <?php print $oss_results->getResultFound().' documents found ('.$oss_resultTime.' seconds)'; 85 91 if($oss_sp != 1 && $oss_results->getResultFound() > 0) { 86 ?>92 ?> 87 93 <div id="oss-did-you-mean"> 88 94 <?php if(isset($spellcheck_query)) { ?> … … 98 104 <?php 99 105 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 ?> 109 121 110 <div id="oss-result">122 <div class="oss-result"> 111 123 <?php 112 if ($title) {?>113 <div id="oss-title">124 if ($title) {?> 125 <div class="oss-title"> 114 126 <a href="<?php print $url;?>"><?php print $title;?> </a><br /> 115 127 </div> … … 118 130 <?php } 119 131 ?> 120 <div id="oss-content">132 <div class="oss-content"> 121 133 <?php if ($content) { 122 print $content.'<br/>';134 print $content.'<br/>'; 123 135 } 124 $custom_fields_array = get_custom_fields();136 $custom_fields_array = opensearchserver_get_custom_fields(); 125 137 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 } 130 142 } 131 143 ?> 132 144 </div> 133 <div id="oss-url">145 <div class="oss-url"> 134 146 <?php 135 147 if($url) {?> … … 138 150 if($type && $user ) { 139 151 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 } 146 158 }?> 147 159 </div> 148 160 </div> 149 <br />150 161 <?php 151 162 } … … 162 173 <?php } 163 174 else { 164 print '<span id="oss-page">'.$page['label'].'</span>';175 print '<span id="oss-page">'.$page['label'].'</span>'; 165 176 } 166 177 } ?> … … 174 185 </div> 175 186 <?php 176 }187 } 177 188 } 178 189
Note: See TracChangeset
for help on using the changeset viewer.