@@ -94,6 +94,11 @@ class CollectionHandler extends
94
94
*/
95
95
const OPTION_SKIP = 'skip ' ;
96
96
97
+ /**
98
+ * index parameter
99
+ */
100
+ const OPTION_INDEX = 'index ' ;
101
+
97
102
/**
98
103
* limit parameter
99
104
*/
@@ -169,6 +174,11 @@ class CollectionHandler extends
169
174
*/
170
175
const OPTION_COUNT = 'count ' ;
171
176
177
+ /**
178
+ * query option
179
+ */
180
+ const OPTION_QUERY = 'query ' ;
181
+
172
182
/**
173
183
* checksum option
174
184
*/
@@ -938,6 +948,76 @@ public function byExample($collectionId, $document, $options = array())
938
948
}
939
949
940
950
951
+ /**
952
+ * Get document(s) by a fulltext query
953
+ *
954
+ * This will find all documents from the collection that match the fulltext query specified in query.
955
+ * In order to use the fulltext operator, a fulltext index must be defined for the collection and the specified attribute.
956
+ *
957
+ *
958
+ * @throws Exception
959
+ *
960
+ * @param mixed $collectionId - collection id as string or number
961
+ * @param mixed $attribute - The attribute that contains the texts.
962
+ * @param mixed $query - The fulltext query.
963
+ * @param bool|array $options - optional, prior to v1.0.0 this was a boolean value for sanitize, since v1.0.0 it's an array of options.
964
+ * <p>Options are :<br>
965
+ * <li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
966
+ * <li>'sanitize' - Deprecated, please use '_sanitize'.</li>
967
+ * <li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
968
+ * <li>'hiddenAttributes' - Deprecated, please use '_hiddenAttributes'.</li>
969
+ * <p>
970
+ * This is actually the same as setting hidden attributes using setHiddenAttributes() on a document. <br>
971
+ * The difference is, that if you're returning a resultset of documents, the getAll() is already called <br>
972
+ * and the hidden attributes would not be applied to the attributes.<br>
973
+ * </p>
974
+ * </li>
975
+ * <li>'batchSize' - can optionally be used to tell the server to limit the number of results to be transferred in one batch</li>
976
+ * <li>'skip' - Optional, The number of documents to skip in the query.</li>
977
+ * <li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
978
+ * <li>'index' - If given, the identifier of the fulltext-index to use.</li>
979
+ * </p>
980
+ *
981
+ * @return cursor - Returns a cursor containing the result
982
+ */
983
+ public function fulltext ($ collectionId , $ attribute , $ query , $ options = array ())
984
+ {
985
+ // This preserves compatibility for the old sanitize parameter.
986
+ if (!is_array ($ options )) {
987
+ $ sanitize = $ options ;
988
+ $ options = array ();
989
+ $ options = array_merge ($ options , $ this ->getCursorOptions ($ sanitize ));
990
+ } else {
991
+ $ options = array_merge ($ options , $ this ->getCursorOptions ($ options ));
992
+ }
993
+
994
+ $ body = array (
995
+ self ::OPTION_COLLECTION => $ collectionId ,
996
+ self ::OPTION_ATTRIBUTE => $ attribute ,
997
+ self ::OPTION_QUERY => $ query ,
998
+ );
999
+
1000
+ $ body = $ this ->includeOptionsInBody (
1001
+ $ options ,
1002
+ $ body ,
1003
+ array (
1004
+ ConnectionOptions::OPTION_BATCHSIZE => $ this ->getConnectionOption (
1005
+ ConnectionOptions::OPTION_BATCHSIZE
1006
+ ),
1007
+ self ::OPTION_LIMIT => null ,
1008
+ self ::OPTION_SKIP => null ,
1009
+ self ::OPTION_INDEX => null ,
1010
+ )
1011
+ );
1012
+
1013
+ $ response = $ this ->getConnection ()->put (Urls::URL_FULLTEXT , $ this ->json_encode_wrapper ($ body ));
1014
+
1015
+ $ options ['isNew ' ] = false ;
1016
+
1017
+ return new Cursor ($ this ->getConnection (), $ response ->getJson (), $ options );
1018
+ }
1019
+
1020
+
941
1021
/**
942
1022
* Get the first document matching a given example.
943
1023
*
@@ -991,7 +1071,7 @@ public function firstExample($collectionId, $document, $options = array())
991
1071
$ response = $ this ->getConnection ()->put (Urls::URL_FIRST_EXAMPLE , $ this ->json_encode_wrapper ($ data ));
992
1072
$ data = $ response ->getJson ();
993
1073
994
- $ options ['isNew ' ] = false ;
1074
+ $ options ['_isNew ' ] = false ;
995
1075
996
1076
return Document::createFromArray ($ data ['document ' ], $ options );
997
1077
}
@@ -1026,6 +1106,96 @@ public function any($collectionId)
1026
1106
}
1027
1107
}
1028
1108
1109
+ /**
1110
+ * This will return the first documents from the collection, in the order of insertion/update time.
1111
+ * When the count argument is supplied, the result will be a list of documents, with the "oldest" document being
1112
+ * first in the result list.
1113
+ * If the count argument is not supplied, the result is the "oldest" document of the collection,
1114
+ * or null if the collection is empty.
1115
+ *
1116
+ *
1117
+ * @throws Exception
1118
+ *
1119
+ * @param mixed $collectionId - collection id as string or number
1120
+ * @param int $count - the number of documents to return at most. Specifiying count is optional.
1121
+ *
1122
+ * @return array - array of documents in the collection
1123
+ * @since 1.2
1124
+ */
1125
+ public function first ($ collectionId , $ count = null )
1126
+ {
1127
+
1128
+ $ data = array (
1129
+ self ::OPTION_COLLECTION => $ collectionId ,
1130
+ );
1131
+ if ($ count != null ) {
1132
+ $ data [self ::OPTION_COUNT ] = $ count ;
1133
+ }
1134
+
1135
+ $ response = $ this ->getConnection ()->put (Urls::URL_FIRST , $ this ->json_encode_wrapper ($ data ));
1136
+ $ data = $ response ->getJson ();
1137
+
1138
+ $ result = array ();
1139
+ if ($ data ["result " ] == null ) {
1140
+ return array ();
1141
+ }
1142
+ $ options = array ();
1143
+ $ options ['_isNew ' ] = false ;
1144
+ if ($ count != null && $ count > 1 ) {
1145
+ foreach ($ data ["result " ] as $ doc ) {
1146
+ $ result [] = Document::createFromArray ($ doc , $ options );
1147
+ }
1148
+ } else {
1149
+ return Document::createFromArray ($ data ["result " ], $ options );
1150
+ }
1151
+ return $ result ;
1152
+ }
1153
+
1154
+ /**
1155
+ * This will return the last documents from the collection, in the order of insertion/update time.
1156
+ * When the count argument is supplied, the result will be a list of documents, with the "latest" document being
1157
+ * first in the result list.
1158
+ * If the count argument is not supplied, the result is the "latest" document of the collection,
1159
+ * or null if the collection is empty.
1160
+ *
1161
+ *
1162
+ * @throws Exception
1163
+ *
1164
+ * @param mixed $collectionId - collection id as string or number
1165
+ * @param int $count - the number of documents to return at most. Specifiying count is optional.
1166
+ *
1167
+ * @return array - array of documents in the collection
1168
+ * @since 1.2
1169
+ */
1170
+ public function last ($ collectionId , $ count = null )
1171
+ {
1172
+
1173
+ $ data = array (
1174
+ self ::OPTION_COLLECTION => $ collectionId ,
1175
+ );
1176
+ if ($ count != null ) {
1177
+ $ data [self ::OPTION_COUNT ] = $ count ;
1178
+ }
1179
+
1180
+ $ response = $ this ->getConnection ()->put (Urls::URL_LAST , $ this ->json_encode_wrapper ($ data ));
1181
+ $ data = $ response ->getJson ();
1182
+
1183
+ $ result = array ();
1184
+ if ($ data ["result " ] == null ) {
1185
+ return array ();
1186
+ }
1187
+ $ options = array ();
1188
+ $ options ['_isNew ' ] = false ;
1189
+ if ($ count != null && $ count > 1 ) {
1190
+ foreach ($ data ["result " ] as $ doc ) {
1191
+ $ result [] = Document::createFromArray ($ doc , $ options );
1192
+ }
1193
+ } else {
1194
+ return Document::createFromArray ($ data ["result " ], $ options );
1195
+ }
1196
+ return $ result ;
1197
+ }
1198
+
1029
1199
1030
1200
/**
1031
1201
* Update document(s) matching a given example
0 commit comments