PHPackages                             halk/item-similarity - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. halk/item-similarity

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

halk/item-similarity
====================

Content-based, schema-less recommendation service

10PHP

Since Aug 22Pushed 10y ago1 watchersCompare

[ Source](https://github.com/halk/item-similarity)[ Packagist](https://packagist.org/packages/halk/item-similarity)[ RSS](/packages/halk-item-similarity/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/91beaa81bce65a9134ad18f2e33d09ac43b618fb84078f45824c6c179ba1ab7f/68747470733a2f2f7472617669732d63692e6f72672f68616c6b2f6974656d2d73696d696c61726974792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/halk/item-similarity)[![Code Coverage](https://camo.githubusercontent.com/cf7f01131b286014220b79379181766915a1bc048282e2904fecfee196b93f84/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f68616c6b2f6974656d2d73696d696c61726974792f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/halk/item-similarity/?branch=master)[![GitHub license](https://camo.githubusercontent.com/850eae1099d2b05f53383473d7cd51f9bc1ab09b7d0d9e5122f1dd930efdcc6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6173686170652f6170697374617475732e737667)](https://github.com/halk/item-similarity/blob/master/LICENSE)

Item Similarity: content-based, schema-less recommendation service
==================================================================

[](#item-similarity-content-based-schema-less-recommendation-service)

A simple recommendation service which computes the similarity of items.

Since this is part of my ongoing [MSc project](https://github.com/halk/msc-project-report), README will be improved by October.

Concept
-------

[](#concept)

### Similarity Computation

[](#similarity-computation)

The similarity between two items is computed as follows:

Given the following two JSON documents:

```
a = {
    "brand": "Addi",
    "model": "Speedy",
    "colors": ["black", "white"],
    "category": "Shoes",
    "size": 42
}
b = {
    "brand": "Prima",
    "model": "Kazak",
    "colors": ["red", "white"],
    "category": "Sweater",
    "sleeves": "long"
}
```

First, any item features which are not in both documents are discared:

```
a = {
    "brand": "Addi",
    "model": "Speedy",
    "colors": "black,white",
    "category": "Shoes",
}
b = {
    "brand": "Prima",
    "model": "Kazak",
    "colors": "red,white",
    "category": "Sweater",
}
```

Second, the documents are converted into lists with the keys as a prefix to the values:

```
a = ["brand_Addi", "model_Ayak", "colors_black", "colors_white", "category_Shoes"]
b = ["brand_Addi", "model_Kazak", "colors_red", "colors_white", "category_Sweater"]
```

Finally, the variant of the tanimoto coefficient is calculated:

```
nA = number of features in A
nB = number of features in B
nAB = number of intersecting features
score = nAB / (nA + nB - nAB)

```

### Similarity index

[](#similarity-index)

The index is kept in a MongoDB collection with a document for each feature. This document also keeps track of its similarity score against other documents. Every time a new record is processed, the similarity to other documents is computed and stored. This score is then added to the other document as well. Thus when a similarity score is requested for a document, the end result is already pre-computed.

### API

[](#api)

The index is managed by POST and DELETE requests. The score is fetched via GET.

The route prefix **{index}** allows maintaining more than one index within an instance.

**POST /{index}** Posts a document to the index and calculates the similarity score

**DELETE /{index}** Deletes a document

**GET /{index}?itemIds=1,2,3** Returns similar items for the items in the GET parameter.

Installation
------------

[](#installation)

```
$ git clone https://github.com/halk/item-similarity
$ cd item-similarity
$ cp config/config.php.dist config/config.php
```

Please see [recowise-vagrant](https://github.com/halk/recowise-vagrant) for provisioning details.

Tests
-----

[](#tests)

```
$ cp phpunit.xml.dist phpunit.xml
$ phpunit
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e71e5f4e77ed6d8d9162e1606a7ec3d1633930ddbbf4e92d2466813de3ddb87?d=identicon)[halk](/maintainers/halk)

---

Top Contributors

[![halk](https://avatars.githubusercontent.com/u/174395?v=4)](https://github.com/halk "halk (15 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")

### Embed Badge

![Health badge](/badges/halk-item-similarity/health.svg)

```
[![Health](https://phpackages.com/badges/halk-item-similarity/health.svg)](https://phpackages.com/packages/halk-item-similarity)
```

###  Alternatives

[sanzgrapher/filament-draggable-modal

Make Filament modals draggable.

172.2k1](/packages/sanzgrapher-filament-draggable-modal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
