PHPackages                             atk14/textmit-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. atk14/textmit-client

ActiveLibrary[Search &amp; Filtering](/categories/search)

atk14/textmit-client
====================

Client for indexing and searching engine Textmit.com

v1.4.4(2w ago)123.4k↓27.3%MITPHPPHP &gt;=5.6.0CI passing

Since Feb 16Pushed 2w ago3 watchersCompare

[ Source](https://github.com/atk14/TextmitClient)[ Packagist](https://packagist.org/packages/atk14/textmit-client)[ Docs](https://github.com/atk14/TextmitClient)[ RSS](/packages/atk14-textmit-client/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (14)Used By (0)

Textmit Client
==============

[](#textmit-client)

[![Tests](https://github.com/atk14/TextmitClient/actions/workflows/tests.yml/badge.svg)](https://github.com/atk14/TextmitClient/actions/workflows/tests.yml)

This is a client for indexing and searching engine [Texmit.com](https://www.textmit.com/api/). The client is written in PHP. It can be very easily integrated into an ATK14 application.

1. Basic usage
--------------

[](#1-basic-usage)

In the configuration file set the TEXTMIT\_API\_KEY constant.

```
define("TEXTMIT_API_KEY","123.eeee.abcde....");

```

Where do you get the TEXTMIT\_API\_KEY? Well at the moment the Textmit Engine is closed beta. So you need an invitation code in order to get the key. We are sorry.

### 1.1 Adding a document to the index

[](#11-adding-a-document-to-the-index)

```
$textmit = new \Textmit\Client();

// The socket timeout can be optionally increased
$adf = $this->textmit->getApiDataFetcher();
$adf->setSocketTimeout(30.0); // seconds

$textmit->addDocument([
  "type" => "article",
  "id" => 123,
  "language" => "en",
  "a" => "The most relevant textual part",
  "d" => "More relevant textual part",
  "c" => "Textual part with the default relevance",
  "d" => "The least relevant textual part"
]);

```

The same object can be indexed in a different language.

```
$textmit->addDocument([
  "type" => "article",
  "id" => 123,
  "language" => "cs",
  "a" => "Nejvíce relevantní část textu",
  "d" => "Více relevantní část textu",
  "c" => "Textová část s výchozí relevancí",
  "d" => "Nejméně relevantní část textu"
]);

```

Here is the shortest way how to add a document to the fulltext index. Text is weighted as "c". Default language is used.

```
$text->addDocument($article,"Lorem Ipsum");

```

### 1.2 Preparing fulltext data

[](#12-preparing-fulltext-data)

For easing process of fulltext data preparation, class FulltextData can be used.

```
$article = Article::GetInstanceById(333);

$fd_article = new \Textmit\FulltextData($article);
$fd_article->addHtml($article->getBody());
$fd_article->addText($addText->getTitle(),"a");
$fd_article->setDate($article->getPublishedAt()); // "2018-02-17 06:00:00"

$textmit->addDocument($fd_article->toArray());

```

FulltextData has method merge() for merging other FulltextData object, e.g. one can merge FulltextData of an Image into FulltextData of an Article. During merging, text weights of the merging object can be changed (typically lowered).

```
$fd_article->merge($fd_image,[
  "a" => "c",
  "b" => "c"
]);

```

### 1.3 Searching

[](#13-searching)

Searching can be performed in one specific language.

```
$result = $textmit->search("vitamins and minerals",[
  "type" => "article",
  "language" => "en",
  "offset" => 0,
  "limit" => 20,
]);
$records_found = $result->getTotalAmount();
print_r($result->getIds()); // ["123","124"...]

```

More types of document can be searched at once.

```
$result = $textmit->search("vitamins and minerals",[
  "language" => "cs",
  "types" => ["article","page","image_gallery","video"],
]);

foreach($result->getItems() as $item){
  $id = $item->getId();
  $type = $item->getType(); // "article", "page", "image_gallery" or "video'

  $object = $item->getObject(); // Article#123, Page#332, ImageGallery#453...
}

```

You can use "prefix search" to search without matching whole words.

```
// search for documents containing words vita, vitae, vitamine, vitality...
$result = $textmit->search("vita",[
  "prefix_search" => true,
]);

```

### 1.4 Deleting documents from the index

[](#14-deleting-documents-from-the-index)

#### 1.4.1 Deleting a single document

[](#141-deleting-a-single-document)

```
$textmit->removeDocument(123,"article");

```

#### 1.4.2 Deleting the whole index

[](#142-deleting-the-whole-index)

Method `destroyStage` deletes all documents of all types in the current stage. One project can have more stages, e.g. "PRODUCTION", "DEVELOPMENT", "TEST"...

```
$textmit->destroyStage();

```

#### 1.4.3 Deleting outdated documents

[](#143-deleting-outdated-documents)

One technique of indexing a small project (small website) is to index everything once in every day and then remove outdated documents. Outdated documents are those that have not been indexed or re-indexed after the given threshold date.

```
$textmit->removeObsoleteDocuments(date("Y-m-d H:i:s",time() - 60 * 60 * 24)); // 1 day

```

### 1.5 Configuration

[](#15-configuration)

There are several configuration constants.

```
define("TEXTMIT_API_KEY","...");
define("TEXTMIT_DEFAULT_LANGUAGE","en"); // "en", "cs"
define("TEXTMIT_DEFAULT_DOCUMENT_TYPE","article");
define("TEXTMIT_STAGE","auto"); // "DEVELOPMENT", "PRODUCTION", "auto" means auto detection - it leads to "PRODUCTION", "DEVELOPMENT@hostname" or "TEST@hostname"
define("TEXTMIT_API_BASE_URL","https://www.textmit.com/api/"); // This is default base url

```

### 1.6 Tracy panel integration

[](#16-tracy-panel-integration)

The Textmit package comes with Panel for easy integration into a popular debugger Tracy ()

```
$tracy_bar = Tracy\Debugger::getBar();
$tracy_bar->addPanel(new Textmit\Panel());

```

2. Installation
---------------

[](#2-installation)

Use the Composer to install the Texmit Client.

```
cd path/to/your/project/
composer require atk14/textmit-client

```

3. Extended integration into an ATK14 project
---------------------------------------------

[](#3-extended-integration-into-an-atk14-project)

### 3.1 Using Indexable interface in searchable models

[](#31-using-indexable-interface-in-searchable-models)

```
