Download the PHP package baraja-core/doctrine-fulltext-search without Composer

On this page you can find all versions of the php package baraja-core/doctrine-fulltext-search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package doctrine-fulltext-search

BRJ logo
BRJ organisation

Doctrine Fulltext Search

Integrity check

A powerful, easy-to-use fulltext search engine for Doctrine entities with automatic relevance scoring, query normalization, and machine learning-powered suggestions.


🎯 Core Principles


πŸ—οΈ Architecture Overview

The package follows a modular architecture with clear separation of concerns:

πŸ”§ Main Components

Component Purpose
Search Main entry point, orchestrates the search process
SelectorBuilder Fluent API for building search queries with type validation
Container Service container holding all dependencies (PSR-11 compatible)
Core Internal search logic, processes candidate results
QueryBuilder Builds DQL queries with JOIN support for relations
Analytics Stores search statistics, powers "Did you mean?" feature
QueryNormalizer Normalizes queries, removes stopwords
ScoreCalculator Calculates relevance scores with year boost
SearchResult Collection of results implementing Iterator
SearchItem Single search result with entity, title, snippet, and score

πŸ“¦ Installation

It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.

To install, simply use the command:

Requirements

Nette Framework Integration

Register the DIC extension in your NEON configuration:

The extension automatically registers:

Manual Instantiation

You can create an instance of Search manually:

With custom normalizer and score calculator:


πŸš€ Basic Usage

Simple Array-Based Query

The simplest way to perform a search is by defining an entity map:

Fluent SelectorBuilder API

For better type safety and IDE autocompletion, use the SelectorBuilder:

Adding WHERE Conditions

Filter results with custom conditions:


πŸ› οΈ Column Modifiers

Column names support special prefixes that control how they're used in search:

Modifier Syntax Description
Title :column Used as result caption, displayed even without match
Search Only !column Searched but excluded from snippet output
Select Only _column Loaded but not searched or included in snippet
Normal column Searched and included in snippet

Examples

Using SelectorBuilder:


πŸ”— Entity Relationships

Search across related entities using dot notation:

Custom Getters

When the getter method differs from the column name:


πŸ” Advanced Query Features

Exact Match

Wrap phrases in quotes for exact matching:

Negative Match

Exclude words with minus prefix:

Number Intervals

Search for number ranges:


πŸ“Š Working with Results

SearchResult Entity

The search() method returns a SearchResult entity implementing Iterator:

Getting Results

SearchItem Methods

Each result is a SearchItem with these methods:

Method Return Type Description
getId() string\|int Entity identifier
getEntity() object Original Doctrine entity (PARTIAL loaded)
getTitle() ?string Normalized title
getTitleHighlighted() ?string Title with <i class="highlight"> tags
getSnippet() string Best matching text snippet
getSnippetHighlighted() string Snippet with highlighted words
getScore() int Relevance score (0-512)
entityToArray() array Entity as normalized array

Quick HTML Rendering

For rapid prototyping, SearchResult implements __toString():

This outputs styled HTML with:

Add ?debugMode=1 to URL to see scores in output.


βœ… "Did You Mean?" Feature

When search returns few or no results, the engine can suggest alternative queries:

How It Works

  1. Every search query and result count is stored in the search__search_query table
  2. Queries are scored based on frequency and result count
  3. When needed, the system finds similar queries using Levenshtein distance
  4. The best match is suggested based on combined scoring

Disable analytics for specific searches:


πŸ“ˆ Scoring System

Results are scored on a scale of 0-512 points based on multiple factors:

Score Calculation

Factor Points Description
Exact match +32 Haystack equals query exactly
Contains query +4 Query found as substring
Substring count +1-3 Bonus per occurrence (max 3)
Word match +1-4 Per word occurrence (max 4)
Empty content -16 Penalty for empty fields
Search-only column -4 Reduced weight for ! columns
Title column x6-10 Multiplier for : columns
Year boost x1-6 Bonus for current/recent years

Year Boost

The score calculator automatically boosts results containing recent years:

Custom Score Calculator

Implement IScoreCalculator for custom scoring:

Register in Nette DI:

The container will automatically use your implementation.


πŸ”„ Query Normalization

Queries are automatically normalized before processing:

Default Normalizer Features

  1. Whitespace normalization: Multiple spaces reduced to single
  2. Length limit: Truncated to 255 characters
  3. Stopword removal: Common words filtered (in, it, a, the, of, or, etc.)
  4. Duplicate removal: Repeated words kept only once
  5. Special character handling: %, _, {, } converted or removed
  6. Hash removal: #123 becomes 123

Custom Query Normalizer

Implement IQueryNormalizer for project-specific normalization:


βš™οΈ Configuration Options

Search Timeout

Configure maximum search time (default: 2500ms):

Exact Search Mode

Disable "Did you mean?" suggestions:

User Conditions

Add WHERE conditions to all entity queries:


πŸ“ Database Entity

The package creates one database table for analytics:

SearchQuery Entity

Table: search__search_query

Column Type Description
id UUID Primary key
query string Normalized search query (unique)
frequency int Number of times searched
results int Last result count
score int Calculated relevance (0-100)
insertedDate datetime First search time
updatedDate datetime Last search time

The table is automatically created when using Doctrine migrations with the package's entity mappings.


🎨 Styling Highlighted Results

The default highlighter wraps matched words in:

Add CSS for styling:

Custom Highlight Pattern

Use Helpers::highlightFoundWords() with custom pattern:


🌍 Internationalization

The search engine handles accented characters intelligently:

Supported character mappings:


πŸ”§ Troubleshooting

Column Not Found

The package validates column names against entity metadata. Check your entity properties or use the suggested alternative.

Empty Results

  1. Verify entity has data in the database
  2. Check if columns contain searchable text
  3. Try disabling query normalization for debugging
  4. Verify WHERE conditions aren't too restrictive

Performance Issues

  1. Add database indexes on searched columns
  2. Reduce the number of entities/columns in search
  3. Lower the search timeout
  4. Use ! modifier for large text columns
  5. Consider _ modifier for columns only needed in results

πŸ‘€ Author

Jan BarΓ‘Ε‘ek


πŸ“„ License

baraja-core/doctrine-fulltext-search is licensed under the MIT license. See the LICENSE file for more details.


All versions of doctrine-fulltext-search with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-mbstring Version *
baraja-core/lock Version ^v1.0
doctrine/orm Version ^2.9
psr/log Version ^2.0 || ^3.0
ramsey/uuid Version ^4.1
ramsey/uuid-doctrine Version ^1.7
voku/portable-ascii Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package baraja-core/doctrine-fulltext-search contains the following files

Loading the files please wait ...