-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laravel / Eloquent #5
Comments
Hi, of course. Json file used only for example. Moreover, it is even better to cache in Redis/etc. The only thing to understand. Index data must be fully loaded into script memory before starting the search. |
Thanks for your reply. Let me see if I understand properly:
well, obviously, I have no clue how to use this lib, and would love some more doc for a real case like mine. thanks |
Working with faceted search consists of 2 stages. Stage 1. Building the index. Fetch all rows from the database that need to be indexed and pass them to a faceted index. $index->add(...) Then save the resulting index to the database. $data = $index->getData();
$yourDbStorage->saveIndexData($data); You need to re-index periodically, depending on how often your data changes. Stage 2. Search $index->setData($yourDbStorage->loadIndexData()); Then we search $search->find(...); Faceted search itself is not full-text and cannot search for incomplete matches. It is designed to filter by attributes values. How to be with fultext-search: #3 |
Thanks a lot @k-samuel for this. I totally get the concept of it all. thanks. It is the concrete implementation of the index that I have difficulty to envion. How does this look like in reality I was thinking to sync the index whenever a record is updated but it does not seem to be the principle at use here? |
The easiest option in pseudocode $sql = ' INSERT INTO my_facet_table (`category`,`index_data`) VALUES ("my_index_name", "'.json_encode($index->getData()).'")';
$query->execute($sql); where index_data is LONGTEXT or JSON column At this moment realtime index option is not implemented. Only full indexing. |
Workaround. You can create update queue for records and launch indexer after update event. For example after uploading pricelist or batch update of product records. |
The index data is a black box by design. Think of it as the binary data of the index itself. After collecting them, you need to save them somewhere in order to later reuse. Try running the example https://github.com/k-samuel/faceted-search/tree/master/examples and see how the code works. Attribute values are passed as filters to the search, which can be found from $search->findAcceptableFiltersCount / findAcceptableFilters These are exact matches of values. If you pass the "green" color to the filter, then the attribute should contain exactly that value. Full-text search by part of the title or phrase is not provided, this is a slightly different direction. I hope this helps. |
yes it helps Thanks @k-samuel I can spot 3 use cases in my app:
For 1./ I am thinking to create the index in real time after executing the SQL query to retrieve the records that match the searched term, then create the index because I'd like to use the For 2./ similar to 1./ I guess For 3./ I will use an existing index maintained and refresh every XX minutes. |
Sounds good and Interesting. Before that, I did not think that the index can be built on the basis of the query results. For the first option, there is an alternative way - to get a list of identifiers that you found when searching for a term and pass them to findAcceptableFiltersCount as the second parameter. In this case, you do not have to rebuild the index every time. $filters = $search->findAcceptableFiltersCount([],$foundIds); |
thanks, it sounds great so far. I am trying your idea
any idea why? probably the way I build the index? |
...
$companies = $query->get();
foreach ($companies as $item) {
$recordId = $item->id;
$foundIds[] = $recordId;
$itemData = [
'capabilities' => $item['capabilities']->map(function ($value) use ($item) {
return $value->name;
})->toArray(),
'certificates' => $item['certificates']->map(function ($value) use ($item) {
return $value->name;
})->toArray(),
'tacs' => $item['tacs']->map(function ($value) use ($item) {
return $value->name;
})->toArray(),
'industries' => $item['industries']->map(function ($value) use ($item) {
return $value->name;
})->toArray(),
'enterprise_type' => $item->enterprise_type ? $item->enterprise_type->name : null,
'country' => $item->country ? $item->country->name : null,
];
$searchIndex->addRecord($recordId, $itemData);
}
$search = new Search($searchIndex);
$result = [
'filters' => $this->findFilters($search, $filters, $foundIds),
'results' => ['data' => $results, 'count' => count($results), 'limit' => $pageLimit],
]; |
It looks like a bug. I am planing to release of the new version of the library with fix today at 20:00 Moscow time. Thank you for finding the problem and helping to improve the project.
|
awesome! i updated to Is the |
It changes index structure (incompatible change) https://github.com/k-samuel/faceted-search/blob/master/changelog.md |
Hi,
would that be possible to use a DB as an index instead of a json file? Or I am misunderstanding something.
My tech stack is MySQL 5.7.x, OctoberCMS/Laravel with Eloquent
The text was updated successfully, but these errors were encountered: