swiss-php-friends/solr-query-builder

Common library to build Apache Solr queries

This package's canonical repository appears to be gone and the package has been frozen as a result.

v1.0.0 2014-10-29 08:13 UTC

This package is not auto-updated.

Last update: 2019-02-08 22:04:39 UTC


README

A simple PHP library to build Apache Solr queries

Features

  • Fluid query-builder API
  • Wildcard support
  • Fuzzy search
  • Integer- and string-range support
  • Fully unit-tested
  • Solr version support (3 & 4)

Installation

Use composer:

composer.phar require swiss-php-friends/solr-query-builder

Usage

The library provides a simple, fluid query builder. E.g.:

use SPF\SolrQueryBuilder\QueryBuilder;
use SPF\SolrQueryBuilder\Query\QueryInterface

$qb = new QueryBuilder;

// simple wildcard query
$query = $qb->select()
    ->where('text_en', 'foo')
    ->orWhere('text_en', 'bar', QueryInterface::WILDCARD_SURROUNDED)
    ->getQueryString();
    
// nesting
$query = $qb->select()
    ->nest()
        ->where('text_de', 'foo')
        ->andWhere('text_en', 'bar')
    ->endNest()
    ->orWhere('id', 2)
    ->getQueryString();

// value building (e.g. fuzzy-search or ranges)
$query = $qb->select()
    ->where('text_de', $qb->createFuzzySearchValue('foo', 0.7))
    ->orWhere('text_en', $qb->createStringRange('bar', 'baz'))
    ->orWhere('id', $qb->createNumericRange(10, 100))
    ->getQueryString();

Documentation

For a complete function reference see the API-Docs.

The tests also provide a good overview of the query builder and hot it works.

May the coverage-report provide you with some more information...

Contribution

You are very welcome to contribute. Report bugs and feature-requests to the GitHub Issue Tracking, or propose a PullRequest.

For contributions, please use the Symfony Coding Standard and write unit-tests.

Release Notes

See GitHub Releases