Over a million developers have joined DZone.

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

Read this eGuide to discover the fundamental differences between iPaaS and dPaaS and how the innovative approach of dPaaS gets to the heart of today’s most pressing integration problems, brought to you in partnership with Liaison.

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.


//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("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.

Discover the unprecedented possibilities and challenges, created by today’s fast paced data climate and why your current integration solution is not enough, brought to you in partnership with Liaison

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.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}