makinacorpus/php-lucene

简约、功能丰富的PHP Lucene语法查询构建器

1.2.1 2023-02-02 16:28 UTC

This package is auto-updated.

Last update: 2024-08-30 01:20:48 UTC


README

这是一个非常小的API片段,用于构建Lucene查询的查询构建器;用例众多,其中最明显的是Elastic Search和Apache SolR。

示例

use MakinaCorpus\Lucene\Query;

$query = new Query();

$query
    ->createTermCollection(Query::OP_OR)
    ->add("foo")
    ->add("bar")
;

$query
    ->createDateRange()
    ->setInclusive()
    ->setRange('1983-03-22', new \DateTime())
;

$query
    ->matchTerm('some_field', 'some value', null, 0.8)
    ->matchTerm('other_field', 'some_other_value', 1.3)
;

应该给出以下查询

(
    (foo OR bar)
    AND my_date_field:["1983\-03\-22T00\:00\:00\+0000" TO "2016\-06\-29T13\:10\:20\+0000"]
    AND some_field:"some value"~0.8
    AND other_field:some_other_value^1.3
)

当前状态

此API目前已在各种项目中使用近10年,尽管这个版本是一个完整的重构(大多数类被重命名),现在已在生产环境中运行了6个月。

可能存在一些错误,并且缺乏一些测试,但到目前为止它仍在工作。