Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Couchbase PHP SDK 2.2.0 — Example With Full Text Search

DZone's Guide to

Couchbase PHP SDK 2.2.0 — Example With Full Text Search

We have a look at how to use the latest Couchbase PHP SDK via full-text search. Read on to see how it's done!

· Big Data Zone
Free Resource

Access NoSQL and Big Data through SQL using standard drivers (ODBC, JDBC, ADO.NET). Free Download 

Today I'd like to announce the PHP SDK 2.0.0 GA, which brings a couple of new fetures along with more fixes and improvements. In this blog post I will demonstrate one of them (for a full list of changes refer to the Release Notes).

Full Text Search API

You may have heard about this API previously, but this time lets show it from PHP. We assume you have installed Couchbase 4.5 as a minimum and have setup the enhanced sample bucket beer-sample with defined Full Text index. More information about configuring index find in Full Text search section of SDK guide.

openBucket('beer-sample');

//we use a simple form of search:
$query = CouchbaseSearchQuery::match('national');

//we fire the search and look at results
$result = $bucket->query(new CouchbaseSearchQuery('beerIndex', $query));
printf("score      id\n----------------------------\n");
foreach ($result->hits as $row) {
  printf("%f   %s\n", $row->score, $row->id);
}
printf("----------------------------\n");
printf("total hits: %d\n", $result->metrics['total_hits']);
~ $ php search.php 
score      id
----------------------------
0.574057   penn_brewery-penn_marzen
0.542845   penn_brewery-penn_oktoberfest
0.536256   chelsea_brewing_company
0.529263   bluegrass_brewing_company_inc
0.528675   labatt_ontario_breweries-labatt_extra_dry
0.489116   rahr_sons_brewing_company-iron_thistle
0.474812   pabst_brewing_company
0.451381   rogue_ales-dad_s_little_helper
0.447907   pabst_brewing_company-lone_star
0.442591   great_divide_brewing-denver_pale_ale_dpa
----------------------------
total hits: 17

Find more examples in Searching from the SDK.

Getting the release

To install this release, use the following command and make sure you have libcouchbase 2.6.1+ installed (more details at Start Using the SDK page):

pecl install couchbase-2.2.0

If you encounter any issues, please post directly to the Couchbase forums at https://forums.couchbase.com/c/php-sdk. Additionally, bugs can be reported directly through our issue tracker.

The fastest databases need the fastest drivers - learn how you can leverage CData Drivers for high performance NoSQL & Big Data Access.

Topics:
php ,ga ,sdk ,release ,couchbase ,example ,full text search ,code

Published at DZone with permission of Sergey Avseyev, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}