Skip to content
VincentFoulon80 edited this page Jun 5, 2019 · 25 revisions

Indexing documents

For indexing documents you'll just need to have an array (or an object with public fields) matching any schema and use the update function. Be sure that you provided an "id" (a unique ID for your document) and a "type" (corresponding to a schema name)

$doc = [
    "id" => 1,
    "type" => "example-post",
    "title" => "this is my first blog post !",
    "content" => "I am very happy to post this first post in my blog !",
    "categories" => [
        "party",
        "misc."
    ],
    "date" => "2018/01/01",
    "comments" => [
        [
            "author" => "vincent",
            "date" => "2018/01/01",
            "message" => "Hello world!"
        ],
        [
            "author" => "someone",
            "date" => "2018/01/02",
            "message" => "Welcome !"
        ]
    ]
];
$engine->update($doc);

Searching through your documents

You can use the search function with your term in first parameter:

$response = $engine->search('second post');

There is also a second parameter to this function if you want more features like limit, offsets, or facets

$result = $engine->search("ipsum", ['limit' => 100, 'offset' => 3, 'facets' => ["categories","author"]]);

This line above will search the term "ipsum" through your documents, and will fetch 100 documents skipping the 3 first and at last it'll give you a list of every categories and authors stored in the index and how much of each there is.

More about faceting

To enable faceting into a field, you just need to use the "_filterable" parameter into your schema.
NOTE : Faceting needs rework so that you'll have results depending of your main search

Clone this wiki locally