PHPackages                             haiderjabbar/laravelsolr - 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. haiderjabbar/laravelsolr

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

haiderjabbar/laravelsolr
========================

A Laravel project including the laravelsolr package

65551↓50%6[2 issues](https://github.com/haiderjabbar/laravelsolr/issues)PHP

Since Mar 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/haiderjabbar/laravelsolr)[ Packagist](https://packagist.org/packages/haiderjabbar/laravelsolr)[ RSS](/packages/haiderjabbar-laravelsolr/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

laravelsolr
===========

[](#laravelsolr)

[![Laravel-Solr](https://github.com/haiderjabbar/laravelsolr/raw/main/laravelsolr.png?raw=true)](https://github.com/haiderjabbar/laravelsolr/blob/main/laravelsolr.png?raw=true)

A Laravel package for seamless integration with Apache Solr, providing easy-to-use commands for core management and a fluent interface for Solr operations.

Features
--------

[](#features)

- Create, update, and delete Solr cores via artisan commands
- Manage Solr fields with parent-child relationships
- Fluent query builder interface for Solr searches
- Support for parent-child document relationships
- Cross-collection joins
- Faceted search capabilities
- Complete test coverage

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

[](#installation)

```
composer require haiderjabbar/laravelsolr:dev-main
```

Add the service provider to your `config/app.php`:

```
'providers' => [
    // ...
    HaiderJabbar\LaravelSolr\LaravelSolrServiceProvider::class,
];
```

You should publish the config/solr.php config file with:

```
php artisan vendor:publish --provider="HaiderJabbar\LaravelSolr\LaravelSolrServiceProvider"
```

Available Commands
------------------

[](#available-commands)

```
# Create a new Solr core and migration file
php artisan solr:create-core coreName

# Update a Solr core with a new name
php artisan solr:update-core

# Delete a Solr core and its migration file
php artisan solr:delete-core coreName

# Create new Solr fields with optional parent and fields
php artisan solr:create-fields coreName

# Update existing Solr core fields
php artisan solr:update-fields

# Delete fields from a Solr core
php artisan solr:delete-fields

```

Basic Usage
-----------

[](#basic-usage)

### Adding Documents

[](#adding-documents)

```
use HaiderJabbar\LaravelSolr\Models\SolrModel;

$coreName = 'your_core_name';
$data = [
    'id' => 'unique_id',
    'name' => 'document_name',
    // ... other fields
];

$result = SolrModel::addDocument($coreName, $data);
```

### Updating Documents

[](#updating-documents)

```
$result = SolrModel::updateDocument($coreName, $data);
```

### Deleting Documents

[](#deleting-documents)

```
$result = SolrModel::deleteDocumentById($coreName, $id);
```

### Parent-Child Document Operations

[](#parent-child-document-operations)

```
// Add child documents to a parent
$result = SolrModel::addChildToParent($coreName, $parentId, "child", $childData);
```

### Controller Example

[](#controller-example)

```
use HaiderJabbar\LaravelSolr\Services\SolrQueryBuilder;
use Illuminate\Http\Request;
use HaiderJabbar\LaravelSolr\Models\SolrModel;

class SolrController extends Controller
{
    public function addDocument(Request $request)
    {
        $coreName = 'testCore';
        $data = [
            'id' => 1,
            'name' => 'name'
        ];

        $result = SolrModel::addDocument($coreName, $data);

        return $result
            ? response()->json(['message' => 'Document added successfully'])
            : response()->json(['message' => 'Failed to add document'], 500);
    }

    public function addChildDocument(Request $request, $parentId)
    {
        $coreName = 'testCore';
        $childData = $request->input('childData');

        $result = SolrModel::addChildToParent($coreName, $parentId, "child", $childData);

        if ($result) {
            return response()->json(['message' => 'Child documents added successfully']);
        }
        return response()->json(['message' => 'Failed to add child documents'], 500);
    }
}
```

Query Builder
-------------

[](#query-builder)

laravelsolr provides a powerful and fluent interface for building Solr queries through the `SolrQueryBuilder` class:

### Basic Usage

[](#basic-usage-1)

```
use HaiderJabbar\LaravelSolr\Services\SolrQueryBuilder;

$builder = new SolrQueryBuilder($coreName);
```

### Search Methods

[](#search-methods)

```
// Basic search
$builder->search('field', '=', 'value', $boost);

// OR search condition
$builder->orSearch('field', 'value', $boost);

// Where clause
$builder->where('field', '=', 'value', $priority);

// OR where clause
$builder->orWhere('field', '=', 'value', $priority);

// WHERE IN clause
$builder->whereIn('field', ['value1', 'value2']);

// Filter (fq parameter)
$builder->filter('field', '=', 'value');
```

Available operators:

- `=` Exact match
- `!=` Not equal
- `` Greater than
- `=` Greater than or equal
- `like` Contains
- `in` In array of values

### Sorting and Pagination

[](#sorting-and-pagination)

```
$builder
    ->sort('field asc')    // Add sorting
    ->start(0)             // Starting offset (pagination)
    ->rows(10);            // Number of rows to return
```

### Field Selection

[](#field-selection)

```
$builder->fl(['field1', 'field2', 'score']); // Select specific fields to return
```

### Parent-Child Document Queries

[](#parent-child-document-queries)

```
// Get parent with child
$builder
    ->whereParent('id', '=', 'parent_id', 20)
    ->returnBothParentAndChild()
    ->get();

// Get only children
$builder
    ->whereParent('id', '=', 'parent_id', 20)
    ->returnOnlyChild()
    ->fl(['*', 'score'])
    ->get();

// Get parent only
$builder
    ->whereParent('id', '=', 'parent_id', 20)
    ->returnOnlyParent()
    ->get();

// Query where parent and child
$builder
    ->whereParent('id', '=', 'parent_id', 20)
    ->whereChild('childId', '=', 'child_id', 20)
    ->get();
```

### Cross-Collection Joins

[](#cross-collection-joins)

```
// Simple join
$builder->crossCollectionJoin(
    'otherCore',           // From index
    'fromField',          // Field in from index
    'toField',            // Field in current index
    'field:value'         // Optional query
);

// Complex join with conditions
$builder->whereJoin('otherCore', 'fromField', 'toField', function($q) {
    $q->where('field1', '=', 'value1')
      ->where('field2', '=', 'value2');
});

// Cross collection join example
$result = $builder
    ->whereParent('id', '=', 'parent_id', 20)
    ->whereJoin('otherCore', 'id', 'id', function ($q) {
        $q->where("id", "=", "value1", 20)
         ->where("id", "=", "value2", 20);
    })
    ->returnBothParentAndChild()
    ->getWithJoinedDocuments("otherCore", "id", "id");
```

### Faceted Search

[](#faceted-search)

```
// Basic faceted search
$builder
    ->facet(true)
    ->facetFields(['field1', 'field2'])
    ->get();

// Complex faceted search
$builder
    ->whereParent('id', '=', 'parent_id', 20)
    ->whereChild('childId', '=', 'child_id', 20)
    ->facetFields(['id'])
    ->facet(true)
    ->fl(['*', 'score'])
    ->get();
```

### Query Execution

[](#query-execution)

```
// Basic query execution
$results = $builder->get();

// Get results with facets
$results = $builder->getWithFacets();

// Get results with joined documents
$results = $builder->getWithJoinedDocuments('otherCore', 'fromId', 'toId');
```

### Complete Example

[](#complete-example)

```
$builder = new SolrQueryBuilder($coreName);

$results = $builder
    ->whereParent('category', '=', 'electronics', 20)
    ->whereChild('price', '>=', 100)
    ->facet(true)
    ->facetFields(['brand', 'color'])
    ->sort('price desc')
    ->start(0)
    ->rows(20)
    ->fl(['id', 'name', 'price', 'score'])
    ->returnBothParentAndChild()
    ->get();
```

### Environment Configuration

[](#environment-configuration)

Make sure to set your Solr URL in your `.env` file:

```
SOLR_URL=http://localhost:8983/solr
```

Directory Structure
-------------------

[](#directory-structure)

```
laravelsolr/
├── src/
│   ├── Console/Commands/
│   │   ├── CreateSolrCore.php
│   │   ├── CreateSolrFields.php
│   │   ├── DeleteSolrCore.php
│   │   ├── DeleteSolrFields.php
│   │   ├── UpdateSolrCore.php
│   │   └── UpdateSolrFields.php
│   ├── Models/
│   │   └── SolrModel.php
│   ├── Schema/
│   │   └── SolrSchemaBuilder.php
│   ├── Services/
│   │   ├── CoreSolrService.php
│   │   ├── FieldsSolrService.php
│   │   └── SolrQueryBuilder.php
│   ├── laravelsolr.php
│   ├── LaravelSolrServiceProvider.php
│   └── SolrServiceProvider.php
└── tests/
    └── Unit/
        ├── Console/Commands/
        ├── Models/
        └── Services/

```

Testing
-------

[](#testing)

The package includes comprehensive tests for all features. To run the tests:

```
vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This package is open-source software licensed under the MIT license.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 88.9% 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/d18b01736f2b3bee173728896eba60997da76a8ec627b5cf3e69e88314a96251?d=identicon)[haiderjabbar](/maintainers/haiderjabbar)

---

Top Contributors

[![haiderjabbar](https://avatars.githubusercontent.com/u/123056440?v=4)](https://github.com/haiderjabbar "haiderjabbar (40 commits)")[![baselshlewett](https://avatars.githubusercontent.com/u/20260587?v=4)](https://github.com/baselshlewett "baselshlewett (3 commits)")[![huzaifaarain](https://avatars.githubusercontent.com/u/8613679?v=4)](https://github.com/huzaifaarain "huzaifaarain (2 commits)")

---

Tags

big-dataelasticsearchlaravellaravel-packagesearchsolr

### Embed Badge

![Health badge](/badges/haiderjabbar-laravelsolr/health.svg)

```
[![Health](https://phpackages.com/badges/haiderjabbar-laravelsolr/health.svg)](https://phpackages.com/packages/haiderjabbar-laravelsolr)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)[handcraftedinthealps/zendsearch

a general purpose text search engine written entirely in PHP 5

39921.0k35](/packages/handcraftedinthealps-zendsearch)

PHPackages © 2026

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