forked from jaeksoft/opensearchserver-php-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoss_autocompletion.class.php
More file actions
121 lines (111 loc) · 3.86 KB
/
oss_autocompletion.class.php
File metadata and controls
121 lines (111 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
* This file is part of OpenSearchServer PHP Client.
*
* Copyright (C) 2008-2013 Emmanuel Keller / Jaeksoft
*
* http://www.open-search-server.com
*
* OpenSearchServer PHP Client is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSearchServer PHP Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenSearchServer PHP Client. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* Class to access OpenSearchServer API
*/
require_once(dirname(__FILE__).'/oss_abstract.class.php');
class OssAutocompletion extends OssAbstract {
public function __construct($enginePath, $index = NULL, $login = NULL, $apiKey = NULL) {
$this->init($enginePath, $index, $login, $apiKey);
}
/**
*
* @param string $query the characters to pass to the autocompletion query
* @param int $rows The number of row to return
*/
public function autocompletionQuery($query, $rows = 10) {
$params = array('query' => $query, 'rows' => $rows);
$return = $this->queryServerTXT(OssApi::API_AUTOCOMPLETION, $params);
if ($return === FALSE) {
return FALSE;
}
return $return;
}
/*
* @deprecated Use autocompleteQuery
*/
public function autocomplete($query, $rows = 10) {
return $this->autocompletionQuery($query, $rows);
}
/**
* Build the autocompletion index
* @param int $bufferSize the size of the buffer
*/
public function autocompletionBuild($bufferSize = 1000) {
$params = array('cmd' => 'build', 'bufferSize' => $bufferSize);
$return = $this->queryServerXML(OssApi::API_AUTOCOMPLETION, $params);
if ($return === FALSE) {
return FALSE;
}
return TRUE;
}
/**
* Set the field used by the autocompletion index
* @param string $field the field name
*/
public function autocompletionSet($field) {
$params = array('cmd' => 'set', 'field' => $field);
$return = $this->queryServerXML(OssApi::API_AUTOCOMPLETION, $params);
if ($return === FALSE) {
return FALSE;
}
return TRUE;
}
/**
* Create new autocompletion instance
* @param string $autocompletion_name the name of the autocompletion instance
* @param string $field_name the name of the autocompletion instance
* @param int $rows the name of the autocompletion instance
*/
public function createAutocompletion($autocompletion_name, $field_name = 'autocomplete', $rows = 10) {
$path_parameters = array(
"{index_name}" => $this->index,
"{autocompletion_name}" => $autocompletion_name,
"{rows}" => $rows,
"{field_name}" => $field_name
);
$path = strtr(OssApi::REST_API_AUTOCOMPLETION, $path_parameters);
$return = $this->queryServerREST($path,NULL,NULL, OssApi::DEFAULT_CONNEXION_TIMEOUT, OssApi::DEFAULT_QUERY_TIMEOUT,'PUT');
if ($return === FALSE) {
return FALSE;
}
return TRUE;
}
/**
* Build the autocompletion index with REST API
* @param string $autocompletion_name the name of the autocompletion instance
*/
public function autocompletionBuildREST($autocompletion_name) {
$path_parameters = array(
"{index_name}" => $this->index,
"{autocompletion_name}" => $autocompletion_name
);
$path = strtr(OssApi::REST_API_AUTOCOMPLETION_BUILD, $path_parameters);
$return = $this->queryServerREST($path,NULL,NULL, OssApi::DEFAULT_CONNEXION_TIMEOUT, OssApi::DEFAULT_QUERY_TIMEOUT,'PUT');
if ($return === FALSE) {
return FALSE;
}
return TRUE;
}
}
?>