elasticsearch-php, google like search with fix for spelling errors - php

I am building an E-commerce project with demo database of products, brands and vendors.I have implemented auto suggest in search bar,it works.
what I am unable to do is fix for spelling errors. For eg-if a user search for Motorola as motoroal no results is given.
Can anybody point me to right direction?

That's not a easy task.
I use the following setup:
'analysis' => [
'filter' => [
'nGram_filter' => [
'type' => 'edgeNGram',
'min_gram' => '1',
'max_gram' => '20',
'token_chars' => [
'letter',
'digit',
'punctuation',
'symbol',
],
],
],
'analyzer' => [
'nGram_analyzer' => [
'type' => 'custom',
'tokenizer' => 'whitespace',
'filter' => [
'lowercase',
'asciifolding',
'nGram_filter',
],
],
]
]
Then I set my fields map to use the nGram_analyzer as analyzer.
The edgeNGram tokenizer will break your words in this way:
motorola will be break into: m mo mot moto motor motoro motorol motorola
This setup will act like an auto complete, predicting what your user is trying to search.
To help with spelling errors, you will need to apply some similar analyzer to the search_analyzer on your field mapping.

Related

TYPO3 BE TCA type Preview Image

i search for a Solution:
How can i add a Preview Image for a TCA type?
Example: I have 3 different types and would like to display a preview image for them. The same as the t3 backend layouts.
Just like the Backend-Layout:
Maybe there is a solution to this?
The documentation is explaining it:
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Examples.html#select-drop-down-for-records-represented-by-images
This is the example code:
[
'columns' => [
'select_single_12' => [
'label' => 'select_single_12 foreign_table selicon_field',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_styleguide_elements_select_single_12_foreign',
'fieldWizard' => [
'selectIcons' => [
'disabled' => false,
],
],
],
],
],
]
And the code for the field of the connected table is this:
[
'ctrl' => [
'title' => 'Form engine elements - select foreign single_12',
'label' => 'fal_1',
'selicon_field' => 'fal_1',
// ...
],
'columns' => [
// ...
'fal_1' => [
'label' => 'fal_1 selicon_field',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'fal_1',
[
'maxitems' => 1,
],
$GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
),
],
],
// ...
];
As you have a strange label inside your field it's not clear if you want to link to an image, to a text or even to a field that offers a combination like it's done with relations to the table sys_file by the intermediate table sys_file_ref.
So defining more precise what you need exactly might help to give you a more detailed answer. You can edit your answer to add this description.

Translate yii2 based website

I have created a website using Yii2 . And I am new also in Yii2. I have read the translation options of Yii2 here http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html . It seemed a bit complex to me and I didn't understand what really to do well.
So what about copy the project to a subdomain and just replace the words with its translations? Or should I learn Yii2 translation option and use it?
Any advice is very important me. Thanks in advance!
You can use this function for translations:
<?=Yii::t('app','Text to translate')?>
and in MyProject/messages/en/app.php
return [
'Text to translate' => 'Translated text',
'Other Text to translate' => 'Other Translated text',
];
you need to define in web.php default language
'language'=>'en'
and in web.php components array
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
//'sourceLanguage' => 'en-US',
'fileMap' => [
'app' => 'app.php',
'app/error' => 'error.php',
],
],
],
],

Yii DbMessageSource App* Error

I am currently building a second system with yii2. It will use some tables from a Yii1 database for translation. The Yii1 project was originally translated using files but this has now been moved to the db. All the translations of the Yii1 system use one of three categories app,flash,email of which the vast majority use app.
In the Yii2 project I have the following in the web.php config file.
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\DbMessageSource',
'db' => 'cdb',
'sourceMessageTable' => 'translation_source',
'messageTable' => 'translation',
'forceTranslation'=>true,
],
],
],
All of the translations on the system that use app are not translated, however, all other categories are. If I change the above code to
'i18n' => [
'translations' => [
'app*' => [
Then I get an error for other categories but not app and the app strings are translated as expected. The error I get is
Unable to locate message source for category 'flash'.
If however I change my config to the following, this works for all translations.
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\DbMessageSource',
'db' => 'cdb',
'sourceMessageTable' => 'translation_source',
'messageTable' => 'translation',
'forceTranslation' => true,
],
'app*' => [
'class' => 'yii\i18n\DbMessageSource',
'db' => 'cdb',
'sourceMessageTable'=>'translation_source',
'messageTable' => 'translation',
'forceTranslation' => true,
],
],
],
It just seems odd that I am having to include effectively the same code block twice. Can anyone tell me how I can achieve this in one array or is this the expected behaviour?
** Update **
I do see some mention of * in the docs Docs. I also see some mention of this in the Forum

Empty values in Elasticsearch query string

I am using ES for my Laravel app in order to search a table/type.
My users can search a total of 5 columns which means that there can be a total of 31 query combinations.
So my question is now if I can use the same query but dont provide ES with all the seach params. Or somehow write dynamic queries.
Eg:
'filtered' => [
'query' => [
'match' => ['title' => Input::get('query')]
],
'filter'=> [
'bool' => [
'must' => [
['term' => [ 'type' => 1] ],
['term' => [ 'state' => 22] ],
['term' => [ 'city' => ] ], (empty)
[
'range' => [
'price' => [
'gte' => , (empty)
'lte' => , (empty)
]
]
]
]
]
],
],
Otherwise I have to write 31 different combinations of this query - If ES dont have anything that can help me. And I can use Laravels eloquent ORM for this.
Thanks in advance
You can use Elasticquent
Elasticquent makes working with Elasticsearch and Eloquent models easier by mapping them to Elasticsearch types. You can use the default settings or define how Elasticsearch should index and search your Eloquent models right in the model.
Elasticquent uses the official Elasticsearch PHP API. To get started, you should have a basic knowledge of how Elasticsearch works (indexes, types, mappings, etc).
https://github.com/adamfairholm/Elasticquent

Elastic Search deleteByQuery multiple terms

I'm having trouble duplicating my MySQL delete query in elastic search, I am using this documentation: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete-by-query.html using the PHP wrapper for Laravel.
I'm trying this:
$this->es->deleteByQuery([
'index' => 'users',
'type' => 'user',
'body' => [
'query' => [
'term' => ['field1' => $this->field1],
'term' => ['field2' => $this->field2],
'term' => ['temp' => 0]
]
]
]);
Its suppose to be a DELETE FROM users WHERE field1 = $this->field1 AND field2 = $this->field2...
I'm having trouble translating the WHERE AND syntax to Elastic Search.
Any help?
Your second comment was mostly correct:
I think I have have gone overboard right now. I have body => query =>
filter => filtered => bool => must => term, term, term. Do I need the
filter => filtered arrays?
The bool filter is preferable over the bool query, since filtering is often much faster than querying. In your case, you are simply filtering documents that have the various terms, and don't want them contributing to the score, so filtering is the correct approach.
This should be done though the query clause, however, since the top-level filter clause is used for a different purpose (filtering facets/aggregations...it was in-fact renamed to post_filter in 1.0 to signify that it is a "post filtering" operation).
Your query should look something like this:
$this->es->deleteByQuery([
'index' => 'users',
'type' => 'user',
'body' => [
'query' => [
'filtered' => [
'filter' => [
'must' => [
['term' => ['field1' => $this->field1]],
['term' => ['field2' => $this->field2]],
['term' => ['temp' => 0]]
]
]
]
]
]
]);

Categories