Download the PHP package opensearchserver/opensearchserver without Composer
On this page you can find all versions of the php package opensearchserver/opensearchserver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opensearchserver/opensearchserver
More information about opensearchserver/opensearchserver
Files in opensearchserver/opensearchserver
Package opensearchserver
Short Description PHP library for OpenSearchServer: professionnal search engine, crawlers (web, file, database), REST APIs, .... This library uses OpenSearchServer's V2 API.
License Apache-2.0
Homepage http://www.opensearchserver.com/
Informations about the package opensearchserver
OpenSearchServer PHP Client
OpenSearchServer is an Open-Source professionnal search engine offering lots of advanced features:
- Fully integrated solution: build your index, crawl your websites, filesystem or databases, configure your search queries
- Complete user interface in browser
- Search features:
- Full-text, boolean and phonetic search
- Outer and inner join
- Clusters with faceting & collapsing
- Filtered search (date, distance)
- Geolocation using square or radius
- Several spell-checking algorithms
- Relevance customization
- Suggestion (auto-completion)
- Indexation features:
- 17 languages
- Crawlers: web, filesystem (local, remote), database, mailboxes
- Special analysis for each language
- Numerous filters: n-gram, lemmatization, shingle, elisions, stripping diacritic, Etc.
- Automatic language detection
- Named entity recognition
- Synonyms (word and multi-terms)
- Automatic classifications
Find out all the awesome features offered by OpenSearchServer on our website: http://www.opensearchserver.com/
======================================
This API connector is intended to be used with PHP 5 (any version >= 5.3) and Composer. It is based on the V2 API of OpenSearchServer.
Setup
-
Create a folder for your project
-
Create a file named
composer.json
with this content: -
Run these commands to install vendors:
-
Create a folder where example code can be written:
- Code can now be written in file
web/index.php
. Take examples fromvendor/opensearchserver/opensearchserver/examples/oss_examples.php
.
Quick start
A global handler must be created. It will be used to submit every request to your OpenSearchServer instance:
Each API request is wrapped in a particular class. Requests must be instanciated, configured and then passed to $oss_api->submit()
that will return an OpenSearchServer\Response
object.
Create an index
This code creates an index based on our "WEB_CRAWLER" template, which will automatically create a schema allowing to easily crawl a website.
Configure web crawler
Add some allowed patterns:
Note character
*
: it means crawler will be allowed to follow any URL starting by these patterns.
Add some start URLs for crawler:
Here
*
is not used since real URL are given to crawler: it will use these URLs as first entry points.
Start crawler:
Index documents
While crawler is running some documents can still be manually indexed:
Here objects of type
OpenSearchServer\Document\Document()
are being used to create documents, but some other options exist: passing array, passing JSON, ... See documentation below to know all about this.
Search:
It is quite easy then to search for documents:
Client Documentation
Table of contents
- How to make requests
- Create an handler
- Create a request
- Create request by using an array of JSON parameters
- Create request by using JSON text
- Handle response and search results
- OpenSearchServer\Response\Response
- OpenSearchServer\Response\ResponseIterable
- OpenSearchServer\Response\SearchResult
- OpenSearchServer\Response\MoreLikeThisResult
- OpenSearchServer\Response\SpellCheckResult
- Work with index
- Create an empty index
- Create an index with a template
- Get list of index on an instance
- Delete an index
- Check if an index exists
- Instance monitoring
- Configure schema
- Create a field
- Create full schema
- Get list of fields
- Get details of a specific field
- Delete a field
- Set default and unique field for an index
- Analyzers
- Create an analyzer
- Get list of analyzers
- Get details of a specific analyzer
- Web crawler
- Patterns
- Insert inclusion patterns
- List inclusion patterns
- Delete inclusion patterns
- Insert exclusion patterns
- List exclusion patterns
- Delete exclusion patterns
- Set status for inclusion and exclusion lists
- Inject URL in URL database
- Force crawling of URL
- Start web crawler
- Stop web crawler
- Get web crawler status
- File crawler
- Start file crawler
- Stop file crawler
- Get file crawler status
- File repositories
- List repositories
- Local file
- FTP
- SMB/CIFS
- Swift
- REST crawler
- List existing REST crawlers
- Execute a REST crawler
- Parse files
- List existing parsers
- Get details about a specific parser
- Parse a file by uploading it
- Parse a file located on the server
- Parse a file and let OpenSearchServer detect its type
- Autocompletion
- Create an autocompletion
- Build autocompletion
- Get list of existing autocompletion items
- Query autocompletion
- Delete an autocompletion item
- Documents
- Push documents
- Add document with array notation
- Add documents by creating OpenSearchServer\Document\Document objects
- Add documents by pushing text file
- Delete documents
- Delete documents by query
- Execute search queries
- Search options
- Search(field)
- Save a Search(field) query template
- Search(pattern)
- Save a Search(pattern) query template
- Search templates
- List search template
- Get details of a search template
- Delete a search template
- Search in batch
- Synonyms
- Create a list of synonyms
- Check if a list of synonyms exists
- Get existing lists of synonyms
- Get synonyms of a list
- Delete a list of synonyms
- Stop words
- Create a list of stop words
- Check if a list of stop words exists
- Get existing lists of stop words
- Get stop words of a list
- Delete a list of stop words
- More like this queries
- Create a more like this query template
- Delete a more like this query template
- Get list of more like this query templates
- Get details of a more like this query template
- Execute a more like this search
- Spellcheck queries
- Get list of spellcheck query templates
- Delete a spellcheck query template
- Execute a spellcheck search
- Scheduler
- Get status of a scheduler job
- Execute a scheduler job
- Replication
- Get list of replications
- Get details about one replication
- Create or update a replication
- Start a replication
- Delete a replication
How to make requests
In this PHP client requests to OpenSearchServer's API are objects. Each request object must be submitted to a global handler that is in charge of sending them to an OpenSearchServer instance and returning a response.
Create an handler
Create a request
Several types of objects are available, each being a mapping to one API. For instance objects of type OpenSearchServer\Index\Create
will be used to create index and objects of type OpenSearchServer\Search\Field\Search
will be used to search for documents.
Each request object is a child of the abstract parent class OpenSearchServer\Request
.
For example here is the code to create a request that wil create an index when sent to an OpenSearchServer instance:
After being created each type of request must be configured in a particular way, depending on its type, by calling some methods.
For example this code will tell OpenSearchServer to name the new index "first_index":
Important note:
- method
index()
is really important and is shared by almost every type of requests. In the case of index creation it serves to give a name to new index and in almost every other request it will be used to configure the index on which API call must be made.
This method will not be documented further but will be displayed in code examples when needed.
Once configured request must be sent to an OpenSearchServer instance thanks to the handler created before:
Create request by using an array of JSON parameters
JSON body of request can be given as an array of JSON parameters to the constructor. If values are given this way every data set by calling specific methods on this request will be ignored.
However some methods must still be called to set index on which work and every parameters used directly in request's URL.
Example: create a Search field template:
Create request by using JSON text
JSON body of request can be given as a JSON strings to the constructor. If values are given this way every data set by calling specific methods on this request or by giving JSON array values will be ignored.
However some methods must still be called to set index on which work and every parameters used directly in request's URL.
Example: create a Search field template:
Handle response and search results
Several types of responses can be returned by submit()
. Internally this method uses a Factory that builds a response depending on the type of Request given.
OpenSearchServer\Response\Response
Main Response class.
- Methods:
- isSuccess(): true if everything went well, false if there was a problem during execution of request.
- getInfo(): some requests can return some information. For example
Index deleted: 00__test_file
. - getRawContent(): return raw JSON content of response.
- getJsonValues(): return an array of values built from JSON response.
- Example:
OpenSearchServer\Response\ResponseIterable
Extends OpenSearchServer\Response\Response. Used when response contain iterable values. This class implements \Iterator
and can thus be used in a loop structure.
-
Example: loop through suggestions of an autocompletion query:
- Requests that use this type of response:
- OpenSearchServer\Autocompletion\Query
- OpenSearchServer\Autocompletion\GetList
- OpenSearchServer\Crawler\Rest\GetList
- OpenSearchServer\Index\GetList
- OpenSearchServer\Field\GetList
- OpenSearchServer\SearchTemplate\GetList
- OpenSearchServer\MoreLikeThis\GetList
- OpenSearchServer\Analyzer\GetList
- OpenSearchServer\Synonyms\GetList
- OpenSearchServer\Crawler\Rest\GetList
- OpenSearchServer\Crawler\Web\Patterns\Exclusion\GetList
- OpenSearchServer\Crawler\Web\Patterns\Inclusion\GetList
- OpenSearchServer\Parser\GetList
OpenSearchServer\Response\SearchResult
Extends OpenSearchServer\Response\ResponseIterable. Used for search results.
- Methods:
- getResults(): return array of objects of type OpenSearchServer\Response\Result
- getFacets(): return an array of facets for this query. Each facet is an array with key being name of field and values being array in the form
<text value> => <number of occurrences>
Example of array of facets:
- getQuery(): return query executed by OpenSearchServer
- getRows(): return number of rows asked
- getStart(): return starting offset
- getTotalNumberFound(): return total number of results found in index for this query
- getTime(): return query duration, in ms
- getCollapsedDocCount(): return number of total collapsed docs
- getMaxScore(): return max score in this results set
- getNumberOfResults(): return number of results in this results set
Example: this class being iterable it can also be used in a loop structure:
This class creates object of type OpenSearchServer\Response\Result:
- Methods:
- getPos():
- getScore():
- getCollapsedCount():
- getField($fieldName, $returnFirstValueOnly = true): return value of a field
$fieldName
is the name of the field to return.$returnFirstValueOnly
can be set to false to get every values of a multivalued field. Often fields will have only one value, thus default value for this parameter istrue
.- getSnippet($fieldName, $returnFirstValueOnly = true): return value of a snippet
$fieldName
is the name of the field from which the snippet has been created.$returnFirstValueOnly
can be set to false to get every snippets if several snippets where asked.- getAvailableFields($returnAllWithoutValues = false): return all available fields for this result.
$returnAllWithoutValues
can be set to true to return fields that have been configured asreturnedFields
in the query even if they have no value for this result.- getAvailableSnippets($returnAllWithoutValues = false): return all available snippets for this result.
$returnAllWithoutValues
can be set to true to return snippets that have been asked the query even if they have no value for this result.- getHighlightedSnippets(): return list of all fields for which an higlighted snippet has been made
- Example:
OpenSearchServer\Response\MoreLikeThisResult
This kind of response looks like OpenSearchServer\Response\SearchResult but with fewer features, since results returned by MoreLikeThis query are simpler.
- Methods:
- getResults(): return array of objects of type OpenSearchServer\Response\Result
- getQuery(): return query
OpenSearchServer\Response\SpellCheckResult
This response is returned by SpellCheck queries. It is used to access spell check suggestions for each asked field.
Example:
Available methods:
-
getSpellSuggestionsArray(string $fieldname): return the spell suggestions for one field as array, key is searched word and value is array of suggestions: key is suggestion and value frequency. Array will be sorted with more frequent suggestions at the beginning.
- Example of result
- getBestSpellSuggestion(string $fieldname): return best spell suggestion for this field.
- getSpellSuggest(string $fieldname): helper method, alias to
getBestSpellSuggestion()
.
Work with index
Create an empty index
Go to API documentation for this method
Create an index with a template
Two pre-configured templates are offered with OpenSearchServer: WEB_CRAWLER and FILE_CRAWLER. Each template comes with pre-configured schema, queries, renderers.
Template WEB_CRAWLER
:
Template FILE_CRAWLER
:
Get list of index on an instance
Go to API documentation for this method
This class does not need a call to
->index()
before submission.
Delete an index
Go to API documentation for this method
Check if an index exists
Go to API documentation for this method
Instance monitoring
Several instance-wide monitoring properties can be retrieved:
This would display for example:
- availableProcessors: 4
- freeMemory: 38656976
- memoryRate: 12.958230285108
- maxMemory: 1879048192
- totalMemory: 298319872
- indexCount: 59
- freeDiskSpace: 24181137408
- freeDiskRate: 23.061161199939
- java.runtime.name: Java(TM) SE Runtime Environment
- sun.boot.library.path: C:\Program Files\Java\jre7\bin
- java.vm.version: 24.51-b03
- java.vm.vendor: Oracle Corporation
- java.vendor.url: http://java.oracle.com/
- ...
- ...
Available methods:
- full(boolean $full): if set to true return every available properties. Otherwise return only some basic properties.
Configure schema
In OpenSearchServer each index must have a schema. A schema is a list of fields, each with some properties.
Create a field
Go to API documentation for this method
Available methods:
- name(string $name): name of field to create.
- indexed(boolean $indexed): tells whether or not this field must be indexed. Indexed field can then used in full-text searchs.
- analyzer(string $analyzerName): analyzer to use on this field. Analyzer allow to apply several transformations on indexed or searched data.
- stored(boolean $stored): tells whether or not this field must be stored. Stored field can return their original values in search queries, even if some Analyzers transformed it.
- copyOf(string/array $fields): field(s) from which copy value. Value is copied before transformation by analyzers. A string or an array of string can be given to this method.
Create full schema at once
Schema can be totally created at once using some JSON Text or JSON array of values with object of type OpenSearchServer\Field\CreateBulk
.
Get list of fields
Go to API documentation for this method
Get details of a specific field
Go to API documentation for this method
Available methods:
- name(string $name): name of field to get information for.
Delete a field
Go to API documentation for this method
Available methods:
- name(string $name): name of field to delete.
Set default and unique field for an index
Go to API documentation for this method
Available methods:
- defaultField(string $name): name of field that must be used as default field. Default field is used for search queries when no particular field is configured in the query. Empty value removes default field setting.
- uniqueField(string $name): name of field that must be used as unique field. Unique field is used as a primary key. Empty value removes unique field setting.
Analyzers
Create an analyzer
Go to API documentation for this method
Analyzer can be created or updated using some JSON Text or JSON array of values with object of type OpenSearchServer\Analyzer\Create
.
Available methods:
- name(string $name): name of the analyzer to create or update.
- lang(string $lang): lang of the analyzer to create or update.
Get list of analyzers
Go to API documentation for this method
Get details of a specific analyzer
Go to API documentation for this method
Available methods:
- name(string $name): name of the analyzer to get information for.
- lang(string $lang): lang of the analyzer to get information for.
Delete an analyzer
Available methods:
- name(string $name): name of the analyzer to delete.
- lang(string $lang): lang of the analyzer to delete.
Web Crawler
Patterns
Available methods for Insert and Delete classes:
- pattern(string $pattern): URL to insert or delete
- patterns(array $patterns): array of URL to insert or delete
Insert inclusion patterns
Go to API documentation for this method
List inclusion patterns
Go to API documentation for this method
Delete inclusion patterns
Go to API documentation for this method
Insert exclusion patterns
Go to API documentation for this method
List exclusion patterns
Go to API documentation for this method
Delete exclusion patterns
Go to API documentation for this method
Set status for inclusion and exclusion lists
Inject URL in URL database
In addition to inserting pattern it is also needed to tell crawler which URL it should use to start crawling. It will then discover automatically new URLs to crawl.
Force crawling of URL
Same as "Manual crawl" in OpenSearchServer's interface. Given URL must be in inclusion patterns.
If you want OSS to return the crawled data (content of the page and all extracted fields), use method returnData(true)
:
Start web crawler
Go to API documentation for this method
Stop web crawler
Go to API documentation for this method
Get web crawler status
Go to API documentation for this method
File crawler
Start file crawler
Available method:
- run($runType): run crawler
once
orforever
. Defaults toforever
.
Stop file crawler
Get file crawler status
File repositories
Every type of location share some common methods for insertion:
Available methods:
- path(string $path)
- ignoreHiddenFile(boolean $ignoreHiddenFile)
- includeSubDirectory(boolean $includeSubDirectory)
- enabled(string $path): enable/disable this location
- delay(int $delay): delay between each access to a file, in ms.
List repositories
Get list of existing repositories in one index.
Local file
Insert local file location
Delete local file location
One method must be called to target location to delete.
Available method:
- path(string $path): path of location to delete
FTP
Insert FTP location
Available methods:
- username(string $username)
- password(string $password)
- host(string $host)
- ssl(boolean $isSsl): if set to true uses FTP over SSL.
Delete FTP location
Several methods must be called to target location to delete.
Available methods:
- path(string $path): path of location to delete
- username(string $username)
- host(string $host)
- ssl(boolean $isSsl): set to true if location to delete uses FTP over SSL
SMB/CIFS
Insert SMB/CIFS location
Available methods:
- username(string $username)
- password(string $password)
- domain(string $domain)
- host(string $host)
Delete SMB/CIFS location
Several methods must be called to target location to delete.
Available methods:
- path(string $path): path of location to delete
- username(string $username)
- domain(string $domain)
- host(string $host)
Swift
Insert Swift location
Available methods:
- username(string $username)
- password(string $password)
- tenant(string $tenant)
- container(string $container)
- authUrl(string $authUrl)
- authType(string $authType): can be
KEYSTONE
orIAM
.
Delete Swift location
Several methods must be called to target location to delete.
Available methods:
- path(string $path): path of location to delete
- username(string $username)
- container(string $container)
REST crawler
List existing REST crawlers
Execute a REST crawler
Available methods:
- name(string $name): name of REST crawler to execute.
Parse files
OpenSearchServer is able to parse files from lots of different types. Parsers allow for extraction of information inside documents.
Methods for this API do not require an index
to work with, since parsing is "index-free". Those API do not index any data, they simply
parse files and send back parsed data.
List existing parsers
Go to API documentation for this method
Get details about a specific parser
Go to API documentation for this method
Parse a file by uploading it
Go to API documentation for this method
Use this API to send a file to OpenSearchServer and get back parsed data.
Another way to send the file is by using a particular method of the Handler. This method does not use the Buzz HTTP client but rather directly makes a CURL call, using CurlFile to send the file.
The file path must be given using method filePath()
instead of file()
, and request must be submitted using submitFile()
instead of submit()
.
This method is more direct and will use less memory than the previous one.
Parse a file located on the server
Go to API documentation for this method
Use this API to ask OpenSearchServer to parse a file located on its server, and get back parsed data.
Parse a file and let OpenSearchServer detect its type
Go to API documentation for this method
Use this API to send a file or to parse a file located on the server: OpenSearchServer will try to automatically detect its MIME type to apply the correct parser on it.
Available methods:
- name(string $name): name of the file. Optionnal.
- type(string $type): type of the file. Optionnal.
- path(string $path): path of the file located on the server. Optionnal.
- file(string $fullPath): path of the file to send to the parser. Optionnal.
- filePath(string $fullPath): path of the file to send to the parser if request is submitted using
submitFile()
. Optionnal. - variable(string $variable, string $value): one property of the parser. Optionnal.
Autocompletion
Create an autocompletion
Go to API documentation for this method
Autocompletion are "sub-index" for OpenSearchServer. They need to be created and configured with fields to use for suggestions.
Available methods:
- name(string $name): name of autocompletion item to create.
- field(string $name): name of field in main schema from which suggestion are returned.
- fields(array $fields):** helper method, calls
field()
for each item in array.
Build autocompletion
Go to API documentation for this method
Autocompletion sub-index need to be re-built frequently, when content on main index changes. This can be automatized with OpenSearchServer's Schedulers or done by calling this API.
Available methods:
- name(string $name): name of autocompletion item to build.
Get list of existing autocompletion items
Go to API documentation for this method
Several autocompletion items can be built, each with particular fields for some specific purpose.
Query autocompletion
Go to API documentation for this method
Available methods:
- name(string $name): name of autocompletion item to query.
- query(string $keywords): keywords to use for suggestions. Usually beginning of a word.
- rows(int $numberOfRows): number of suggestions to return.
Delete an autocompletion item
Go to API documentation for this method
Available methods:
- name(string $name): name of autocompletion item to delete.
Documents
Push documents
Go to API documentation for this method
Add document with array notation
Add documents by creating OpenSearchServer\Document\Document objects
Available methods:
- addDocument(array / OpenSearchServer\Document\Document $document): add a document in list of documents to add in the index.
- addDocuments(array $documents): helper method. Add several document, call
addDocument()
for each item in array.
Available methods for object of type OpenSearchServer\Document\Document:
- lang(string $lang): set lang of indexation. Used by some Analyzers to transform text.
- field(string $name, string $value, int $boost): give value to a field, with an optionnal boost. You would probably prefer to use boost at query time. This method can be called several times with same
$name
argument to index multiple values for one field.
Add documents by pushing text file
Go to API documentation for this method
Text files in CSV or TTL can be pushed to OpenSearchServer, with a regexp pattern to match fields.
Available methods:
- pattern(string $pattern): REGEXP pattern to use for mapping values to fields.
- data(string $data):
- langpos(int $pos): position of language in mapped fields (index start at 1)
- buffersize(int $bufferSize)
- charset(string $charset): charset of sent text
- field(string $fieldname): one field mapping. Can be called several times to map several fields.
- fields(array $fields): help method. Calls
field()
for each item in array.
Delete documents
Go to API documentation for this method
Available methods:
- field(string $name): name of field on which base deletion.
- value(string $value): value of the field to delete.
- values(array $values): helper method. Call
value()
for each item in array.
Delete documents using an existing query template or using a query pattern
Go to API documentation for this method
Available methods:
One or the other of these 2 methods must be used:
- template($queryTemplate): name of a query template to use for deletion.
- query($pattern): query pattern for selecting documents to delete.
Execute search queries
Search options
Two types of search queries exist in OpenSearchServer : Search field and Search pattern.
They both offer lots of common options and only differ in the way of specfiying searched fields:
Available methods:
- General options:
- query(string $query): search keywords
- emptyReturnsAll(boolean $value): if set to true and keywords are empty will return every documents of the index
- operator(string $operator): Set the default operator: OR or AND
- lang(string $lang):
- enableLogs(boolean value): Enale logging of this query
- returnedFields(array $fields): An array of fieldnames to return with results
- rows(int $rows):
- template(string $name): set name of query template to use. If set, query will use given registered query template but will override every parameters defined in the query object.
- snippet():
- Sorting options
- sort(string $field, string $direction): add a sorting on one field. Can be called multiple times to successively sort on different fields.
- sorts(array $sorts, string $direction): helper method. Calls
sort()
for each item in array.
- Scoring options
- scoring(string $field, int $weight, boolean $ascending, type $type): add one level of scoring.
- Boosting queries
- boostingQuery(string $queryPattern, int $boost): add one boosting query.
- Facetting options
- facet(string $field, int $min = 0, boolean $multi = false, boolean $postCollapsing = false): compute facet for one field: this will return count of every different values for this field. Facets can be used through
->getFacets()
when workingh with anOpenSearchServer\Response\SearchResult
object. You can find more details in the proper section.
- facet(string $field, int $min = 0, boolean $multi = false, boolean $postCollapsing = false): compute facet for one field: this will return count of every different values for this field. Facets can be used through
- Filtering options
- queryFilter(string $filter): add a filter with a pattern query. For example :
lang:en
. - negativeFilter(string $filter): add a negative query filter.
- geoFilter(string $shape, string $unit, int $distance): add a geo filter.
- negativeGeoFilter(string $shape, string $unit, int $distance): add a negative geo filter
- relativeDateFilter(string $field, string $fromUnit, int $fromInterval, string $toUnit, int $toInterval, string $dateFormat, boolean $isNegative):: add a RelativeDateFilter. This filter allows dynamic date filtering.
- This filter can be used to simplify date filtering, or when saving a Search template. If a template is saved with a relative date filter it will always force a date filter base on current date. For example if set with values
fromUnit
= days,fromInterval
= 30,toUnit
= days,toInterval
= 0 anddateFormat
=yyyyMMdd
this search template will always filter documents whose chosen filtered field contains a date in last 30 days. For instance if $field is "fileSystemDate" and if a search is run on february 1st of 2014 it will translates to this filter:fileSystemDate:[20140101 TO 20140201]
. - Parameters:
$field
: name of field on which apply filter.$fromUnit
: unit to use for first boundary. Values can beOpenSearchServer\Search\Field\Search::RELATIVE_DATE_FILTER_UNIT_DAYS
,OpenSearchServer\Search\Field\Search::RELATIVE_DATE_FILTER_UNIT_HOURS
andOpenSearchServer\Search\Field\Search::RELATIVE_DATE_FILTER_UNIT_MINUTES
.$fromInterval
: interval to use for first boundary.$toUnit
: unit to use for second boundary. Values can beOpenSearchServer\Search\Field\Search::RELATIVE_DATE_FILTER_UNIT_DAYS
,OpenSearchServer\Search\Field\Search::RELATIVE_DATE_FILTER_UNIT_HOURS
andOpenSearchServer\Search\Field\Search::RELATIVE_DATE_FILTER_UNIT_MINUTES
.$toInterval
: interval to use for first boundary.$dateFormat
: format to use to render dates. Full date format isyyyyMMddHHmmss
(OpenSearchServer\Search\Field\Search::RELATIVE_DATE_FILTER_DATEFORMAT
).$isNegative
: whether this filter must be negative or not.
- negativeRelativeDateFilter(string $field, string $fromUnit, int $fromInterval, string $toUnit, int $toInterval, string $dateFormat, boolean $isNegative):: add a negative RelativeDateFilter.
- filter(string $field): helper method, alias to
queryFilter()
. - filterField(string $field, string / array $filter, string $join, boolean $addQuotes): other way to add a query filter.
- Parameters:
$field
: name of field on which apply filter.$filter
: value(s) on which filter.$join
: if $filter is an array of values, type of join to use between values: OR or AND.$addQuotes
: whether to add quotes around filtered values or not.
- queryFilter(string $filter): add a filter with a pattern query. For example :
- Collapsing options
- collapsing(string $field, int $max, string $mode, string $type):
- Join options
- join(string $indexName, string $queryTemplate, string $queryString, string $localField, string $foreignField, string $type, boolean $returnFields, boolean $returnScores, boolean $returnFacets):
Search(field)
Go to API documentation for this method
Fields that must be searched are specified precisely in this kind of query:
Available methods:
- searchField(string $field, string $mode, int $boost, int $phraseBoost):
- searchFields(array $fields, string $mode, int $boost, int $phraseBoost): helper method. Calls
searchField()
for each item in array.
Save a Search(field) query template
Go to API documentation for this method
Query template can be registered to be used later without having to give every parameters. They can also be edited with the administration interface.
Search(pattern)
Go to API documentation for this method
With this kind of query searched fields are configured with a pattern language:
Save a Search(pattern) query template
Go to API documentation for this method
Query template can be registered to be used later without having to give every parameters. They can also be edited with the administration interface.
Search templates
As shown above it is possible to save several search templates for future use.
List search templates
Go to API documentation for this method
Get details of a search template
Go to API documentation for this method
Delete a search template
Go to API documentation for this method
Search in batch
Multiple queries can be sent at once. Results will be returned for each query, unless parameter mode
is set to
first
: then queries will stop as soon as one return results.
Queries must be created as usual: Search field, Search pattern, with or without template.
Available methods:
- mode(string $mode):
OpenSearchServer\SearchBatch\SearchBatch::MODE_FIRST
, orOpenSearchServer\SearchBatch\SearchBatch::MODE_ALL
(default value) orOpenSearchServer\SearchBatch\SearchBatch::MODE_MANUAL
. - addQuery(OpenSearchServer\Search $query, string $modeManualAction): add one query to the batch. Parameter
$modeManualAction
is the batch action to use for the query, if mode is "manual" - addQueries(array $queries): add several queries to the batch. Parameter
$queries
is an array of array: each sub array contains one required item, the query, and a second optionnal item, the batchAction to use for this query if mode is "manual".
Response for this request will be of type SearchBatchResult
.
Available methods for SearchBatchResult
:
- getNumberOfQueriesWithResult(): return number of results set (even empty ones).
- getResults(): return all results for all queries.
- getResultsByPosition(int $position): return results for one query. Position starts at 0. This method return object of type
SearchResult
.
Synonyms
Create a list of synonyms
Go to API documentation for this method
Available methods:
- name(string $name): name of list to create
- addSynonyms(array/string $list): synonyms to add. One array entry for each group of synonyms. The synonyms within a group are separated by commas. Example: couch,sofa,divan
Check if a list of synonyms exists
Go to API documentation for this method
Available methods:
- name(string $name): name of list to check
Get existing lists of synonyms
Go to API documentation for this method
Get synonyms of a list
Go to API documentation for this method
Available methods:
- name(string $name): name of list to get
Delete a list of synonyms
Go to API documentation for this method
Available methods:
- name(string $name): name of list to delete
Stop words
Create a list of stop words
Available methods:
- name(string $name): name of list to create
- addSynonyms(array/string $list): stop words to add. One array entry for each stop word.
Check if a list of stop words exists
Available methods:
- name(string $name): name of list to check
Get existing lists of stop words
Get stop words of a list
Available methods:
- name(string $name): name of list to get
Delete a list of stop words
Available methods:
- name(string $name): name of list to delete
More like this queries
Create a more like this query template
Go to API documentation for this method
Available methods:
- template(string $template): name of more like this query template to create
- docQuery(string $docQuery): query to match document
- likeText(string $likeText): searched text
- analyzerName(string $analyzer): name of analyzer to apply on searched text
- fields(array $fields): array of fieldnames to use
- minWordLen(int $value): minimum length of words
- maxWordLen(int $value): maximum length of words
- minDocFreq(int $value): minimum frequency of document
- minTermFreq(int $value): minimum frequency of term
- maxNumTokensParsed(int $value): number of max token to parse
- maxQueryTerms(int $value): number of max query terms to use
- boost(boolean $value): enable boost
- stopWords(string $value): name of an existing stop words list
- returnedFields(array $fields): An array of fieldnames to return with results
- Filtering options
- queryFilter(string $filter): add a filter with a pattern query. For example :
lang:en
. - negativeFilter(string $filter): add a negative query filter.
- geoFilter(string $shape, string $unit, int $distance): add a geo filter.
- negativeGeoFilter(string $shape, string $unit, int $distance): add a negative geo filter
- filter(string $field): helper method, alias to
queryFilter()
. - filterField(string $field, string / array $filter, string $join, boolean $addQuotes): other way to add a query filter.
- Parameters:
$field
: name of field on which apply filter.$filter
: value(s) on which filter.$join
: if $filter is an array of values, type of join to use between values: OR or AND.$addQuotes
: whether to add quotes around filtered values or not.
- queryFilter(string $filter): add a filter with a pattern query. For example :
Delete a more like this query template
Go to API documentation for this method
Available methods:
- template(string $template): name of more like this query template to delete.
Get list of more like this query templates
Go to API documentation for this method
Get details of a more like this query template
Go to API documentation for this method
Available methods:
- template(string $template): name of more like this query template to retrieve.
Execute a more like this search
Go to API documentation for this method
Available methods:
- template(string $template): name of more like this query template to use
Every other methods of OpenSearchServer\MoreLikeThis\Create
can be used there.
Spellcheck queries
It is not possible at the moment to create Spellcheck query templates through API. Spellcheck query templates can be listed, deleted and used for a search.
Get list of spellcheck query templates
Delete a spellcheck query template
Execute a spellcheck search
Scheduler
Get status of a scheduler job
Go to API documentation for this method
Available method:
- name(string $name): name of scheduler job
Execute a scheduler job
Go to API documentation for this method
Available method:
- name(string $name): name of scheduler job
- variable(string $name, string $value): some tasks can receive variables.
- variables(array $variables): helper method, calls
variable()
for each item in array.
Replication
Get list of replications
Go to API documentation for this method
Get details about one replication
Go to API documentation for this method
Available method:
- name(string $name): name of the replication
Create or update a replication
Go to API documentation for this method
Available method:
- name(string $name): name of the replication
- replicationType(string $value): type of replication (use constants defined in
OpenSearchServer\Request
). - remoteUrl(string $value): URL of the target OpenSearchServer instance
- remoteLogin(string $value): login for the target instance
- remoteApiKey(string $value): API key
- remoteIndexName(string $value): target index name
- secTimeOut(string $value): timeout in secondes
Start a replication
Go to API documentation for this method
Available method:
- name(string $name): name of the replication
Delete a replication
Go to API documentation for this method
Available method:
- name(string $name): name of the replication
===========================
OpenSearchServer PHP Client Copyright 2008-2016 Emmanuel Keller / Jaeksoft http://www.opensearchserver.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.