PHPackages                             xenos/asklucy - 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. xenos/asklucy

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

xenos/asklucy
=============

AskLucy – A PHP library for creating Lucene search queries

v2.0.1(7y ago)24.8k12PHPPHP &gt;=7.1.0

Since Jun 3Pushed 7y ago2 watchersCompare

[ Source](https://github.com/XenosEleatikos/AskLucy)[ Packagist](https://packagist.org/packages/xenos/asklucy)[ Docs](https://github.com/XenosEleatikos/AskLucy)[ RSS](/packages/xenos-asklucy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (2)

[![Build Status](https://camo.githubusercontent.com/30e24342fc786beec1952a6c00402c0dde154ee00d1a7b41083ded1dba4f773f/68747470733a2f2f7472617669732d63692e6f72672f58656e6f73456c656174696b6f732f41736b4c7563792e737667)](https://travis-ci.org/XenosEleatikos/AskLucy)

AskLucy – A PHP Library for Creating Lucene Search Queries
==========================================================

[](#asklucy--a-php-library-for-creating-lucene-search-queries)

This project contains an easy to use PHP library for creating Lucene search queries.

Contents
--------

[](#contents)

- [Installation](#installation)
    - [Install with Git](#install-with-git)
    - [Install with Composer](#install-with-composer)
- [Usage](#usage)
    - [Creating Clauses](#creating-clauses)
        - [Creating a Term](#creating-a-term)
        - [Creating a Phrase](#creating-a-phrase)
        - [Creating a Range](#creating-a-range)
        - [Creating a Complex Query](#creating-a-complex-query)
    - [Fields](#fields)
        - [Setting a Field to a Term](#setting-a-field-to-a-term)
        - [Setting a Field to a Phrase](#setting-a-field-to-a-phrase)
        - [Setting a Field to a Range](#setting-a-field-to-a-range)
        - [Setting Fields in Complex Queries](#setting-fields-in-complex-queries)
    - [Operators](#operators)
        - [Setting an Operator to a Term](#setting-an-operator-to-a-term)
        - [Setting an Operator to a Phrase](#setting-an-operator-to-a-phrase)
        - [Setting an Operator to a Range](#setting-an-operator-to-a-range)
        - [Setting Operators in Complex Queries](#setting-operators-in-complex-queries)
    - [Relevance Boosting](#relevance-boosting)
    - [Fuzziness](#fuzziness)
    - [Proximity Search](#proximity-search)
    - [Range Search](#range-search)

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

[](#installation)

### Install with Git

[](#install-with-git)

```
git clone https://github.com/XenosEleatikos/AskLucy.git
```

### Install with Composer

[](#install-with-composer)

This project is available at [Packagist](https://packagist.org):

You can install it with the following command:

```
composer require xenos/asklucy
```

Usage
-----

[](#usage)

This library contains classes providing a `__toString()` method. By casting their instances with the `(string)`operator you will get clauses ready to use for Lucene search engine. For more details about the syntax of Lucene search queries you may [read the official docs](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html). But the following sections will give you all necessary information about building such queries.

A query to Lucene search engine consists of one ore more clauses for matching documents. There are four types of clauses:

1. Terms matching documents that contain a single word.
2. Phrases matching documents that contain a sequence of words.
3. Ranges matching documents that contain a value between a lower and an upper bound.
4. Complex queries containing one or more sub-clauses of any type.

### Creating Clauses

[](#creating-clauses)

#### Creating a Term

[](#creating-a-term)

To create a query matching documents that contain a single word, e. g. "word", just build a new `Term` as follows:

```
