Search by

adachsoft / project-search-lib

Arkadiusz Adach

Project metadata enrichment and cross-project search (metadata, semantic, hybrid).

Package info

gitlab.com/a.adach/project-search-lib

Issues

pkg:composer/adachsoft/project-search-lib

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-30 00:33 UTC

This package is auto-updated.

Last update: 2026-11-29 23:36:13 UTC


README

Project metadata enrichment and cross-project search (metadata, semantic, hybrid) for PHP.

Purpose

adachsoft/project-search-lib exposes a single, framework agnostic entry point for working with a catalog of projects described by adachsoft/project-config-lib:

  • it enriches project definitions (title, description, keywords) with metadata discovered in local project manifests such as composer.json, package.json and README.md,
  • it builds a searchable projection of every configured project,
  • it searches across all configured projects using metadata matching, semantic (embedding) matching or a hybrid of both.

The library does not ship storage, HTTP clients or embedding providers. Those concerns are implemented behind the interfaces of adachsoft/project-config-lib, adachsoft/embedding-contracts and adachsoft/vector-store-contracts, so the same facade works with files, databases, local models or remote APIs.

Features

  • Metadata search – weighted phrase matching over project id, title, description and keywords built on adachsoft/text-search (exact match first, similarity match as fallback).
  • Semantic search – vector similarity search over project documents embedded by any EmbedderInterface implementation and stored in any VectorStoreInterface implementation.
  • Hybrid search – weighted combination of metadata and semantic results with a single ranked hit list.
  • Project enrichment – fills in weak or missing descriptions and keywords from project manifests, with force and dryRun modes and a per-change report.
  • Semantic index management – collection creation, incremental upsert based on document hashes, orphan removal, and a status snapshot (stale, missing, orphaned counters).
  • Deterministic, immutable results – DTOs, value objects and typed collections for every request and response.
  • Validation at the boundary – query length, result limit, index configuration and collection names are validated with clear library exceptions.

Requirements

  • PHP 8.3 or newer
  • A ProjectConfigRepositoryInterface implementation from adachsoft/project-config-lib
  • For semantic and hybrid search: an EmbedderInterface implementation from adachsoft/embedding-contracts and a VectorStoreInterface implementation from adachsoft/vector-store-contracts

Installation

composer require adachsoft/project-search-lib

Integration

ProjectSearchFactory builds a ready to use ProjectSearchFacadeInterface. The facade is the only type you need to inject into your own code.

Metadata search only

<?php

declare(strict_types=1);

use AdachSoft\ProjectConfigLib\ProjectConfigRepositoryInterface;
use AdachSoft\ProjectSearchLib\Enum\SearchStrategyNameEnum;
use AdachSoft\ProjectSearchLib\ProjectSearchFactory;
use AdachSoft\ProjectSearchLib\Vo\SearchQueryVo;

/** @var ProjectConfigRepositoryInterface $projectConfigRepository */
$projectSearchFactory = new ProjectSearchFactory();
$projectSearchFacade = $projectSearchFactory->createMetadataOnly($projectConfigRepository);

$hits = $projectSearchFacade->search(
    new SearchQueryVo('http client'),
    SearchStrategyNameEnum::METADATA,
    10,
);

foreach ($hits as $hit) {
    printf("%s (%.2f) [%s]\n", $hit->title, $hit->score, implode(', ', $hit->matchedIn));
}

Metadata, semantic and hybrid search

<?php

declare(strict_types=1);

use AdachSoft\EmbeddingContracts\Contract\EmbedderInterface;
use AdachSoft\ProjectConfigLib\ProjectConfigRepositoryInterface;
use AdachSoft\ProjectSearchLib\Dto\SemanticIndexConfigDto;
use AdachSoft\ProjectSearchLib\ProjectSearchFactory;
use AdachSoft\VectorStoreContracts\Contract\VectorStoreInterface;
use AdachSoft\VectorStoreContracts\Enum\DistanceMetricEnum;

/** @var ProjectConfigRepositoryInterface $projectConfigRepository */
/** @var EmbedderInterface $embedder */
/** @var VectorStoreInterface $vectorStore */

$semanticIndexConfig = new SemanticIndexConfigDto(
    collectionName: 'project_search',
    embeddingModel: 'text-embedding-3-small',
    embeddingDimensions: 1536,
    distanceMetric: DistanceMetricEnum::COSINE,
    minScore: 0.2,
);

$projectSearchFactory = new ProjectSearchFactory();
$projectSearchFacade = $projectSearchFactory->createWithSemanticSearch(
    $projectConfigRepository,
    $embedder,
    $vectorStore,
    $semanticIndexConfig,
);

Semantic index lifecycle

<?php

// Build or refresh the vector index.
$buildResult = $projectSearchFacade->rebuildSemanticIndex(force: false);
printf("upserted=%d skipped=%d deleted=%d\n",
    $buildResult->recordsUpserted,
    $buildResult->recordsSkippedUpToDate,
    $buildResult->recordsDeleted,
);

// Inspect the index before searching.
$status = $projectSearchFacade->getSemanticIndexStatus();
if ($status->stale) {
    // Rebuild when projects were added, edited or removed since the last index run.
    $projectSearchFacade->rebuildSemanticIndex(force: true);
}

With force: false only documents whose content hash changed are embedded again; with force: true every document is re-embedded. Records of projects that no longer exist are deleted in both modes.

Enrichment

ProjectEnricher reads the base_path parameter of each project definition and inspects the manifest found there. Projects without a valid base_path, without a supported manifest or without useful metadata are reported in the result counters instead of raising an error.

<?php

// Report only, do not touch the repository.
$preview = $projectSearchFacade->enrich(force: false, dryRun: true);

foreach ($preview->changes as $change) {
    printf("%s <- %s\n", $change->projectId, $change->sourceLabel);
}

// Apply the changes.
$result = $projectSearchFacade->enrich(force: false, dryRun: false);

Modes:

forcedryRunBehaviour
falsetrue/falseFills description only when it is considered poor, and keywords only when empty.
truetrue/falseReplaces description and keywords with the manifest values.

Result limits and errors

search() accepts a limit between 1 and 25. Semantic and hybrid strategies are only available when the facade was created with an embedder and a vector store; otherwise SemanticSearchUnavailableException is thrown. All library exceptions extend AdachSoft\ProjectSearchLib\Exception\ProjectSearchException.

Examples

Runnable, step by step examples live in docs/examples:

Development

composer install
vendor/bin/phpunit --configuration phpunit.xml
vendor/bin/phpstan analyse
vendor/bin/rector
vendor/bin/php-cs-fixer fix

License

MIT. See the license field of composer.json.