Elastica multi_field setup - mapping

I'm trying to use multi_field syntax of elasticsearch in combination with Elastica. I create an index and an mapping which looks like this:
$mapping->setProperties(array(
'id' => array('type' => 'string', 'include_in_all' => true),
'title' => array('type' => 'string', 'include_in_all' => true),
'publisher' => array('type' => 'multi_field', 'include_in_all' => TRUE, 'fields' =>
array('publisherName' => array('type' => 'string', 'index' => 'analyzed'),
'untouched' => array('type' => 'string', 'index' => 'not_analyzed')
)
));
So far, so good. I can run queries against the title field.
But when I try to query the field "publisher" in http://example.com:9200/_plugin/head/ I'm not able to select the field publisher or to create a structured query. I looks, that the field publisher is not in the index.
But I can build facets on publisher.untouched which works very well. Whats wrong in my mapping? I need to search for the publisher.

See the docs on multi_field mapping. Looks like you need to set a default field by changing 'publisherName' to just 'publisher'.

Related

Laravel 8 not translating validation attributes

I am trying to localise the messages in my form validation using Laravel's validate() function, as follows:
$validated = $request->validate([
'email' => 'bail|required|email',
'g-recaptcha-response' => 'required|captcha',
]);
In my lang/en.php etc files I have translations for 'required', as follows:
'required' => 'The :attribute field is required.',
And I have an entry in the attributes array, as follows:
'attributes' => [
'g-recaptcha-response' => 'Recaptcha',
],
However, the translated attribute does not get called in any of the languages.
What am I doing wrong?
This works if you change the validator to facade.
use Illuminate\Support\Facades\Validator;
$validator = Validator::make($request->all(), [
'email' => 'bail|required|email',
'g-recaptcha-response' => 'required|captcha',
]);
And return the erros with $validator->messages()->getMessages();.

Collection type migration from sf2.8 to sf3

Let's take into account this example: I've got a form type where I embed another type in a "collection fashion" as follows
->add('foo', CollectionType::class, [
'entry_type' => new FooType(),
'error_bubbling' => false,
'allow_add' => true,
'allow_delete' => true,
'required' => false,
'label' => ' ',
'entry_options' => [
'bar' => $options['bar'],
],
'by_reference' => false,
])
and all works fine (I can add and remove elements easily).
Since I'm upgrading the framework from 2.8 to 3.0, I've read changelog and noticed
The option type of the CollectionType has been removed in favor of the
entry_type option. The value for the entry_type option must be the
fully-qualified class name (FQCN).
So I've changed my form to
->add('foo', CollectionType::class, [
'entry_type' => FooType::class,
'error_bubbling' => false,
'allow_add' => true,
'allow_delete' => true,
'required' => false,
'label' => ' ',
'entry_options' => [
'bar' => $options['bar'],
],
'by_reference' => false,
])
but when I add elements to collection, it seems that ModelData are collapsed into the same element (the last one of the collection).
So, imagine that I post entities with ids [1,2,3], ViewData is correct whereas ModelData has an array collection with three elements: three foo(s) with id 3, so the same foo.
Does anyone understand what's going on here?
Edit
This is FooType meaningful code
$resolver->setDefaults([
'data_class' => 'Vendor\Bundle\Entity\Foo',
'empty_data' => new Foo(),
]);
It seems that this is a symfony bug (unconfirmed; read more) or a misuse of combination of FQCN in entry_type and new on empty_data of embedded form.
I'll update my answer properly when and if SF core team reply me in the issue.

Why wash_out can't use identical data types in different soap actions?

I use wash_out from the master branch.
Why I can't use identical data types in different soap actions?
Sample:
soap_action "get_groups",
:args => {:page => :integer},
:return => {:data => [{:id => :integer, :name => :string}], :total => :integer}
soap_action "get_items",
:args => {:page => :integer},
:return => {:data => [{:id => :integer, :name => :string}], :total => :integer}
Also I tried wrap it in WashOut::Type but it not help.
Error:
ActionView::Template::Error (Duplicate use of `data` type name. Consider using classified types.)
I found a solution for myself.
WashOut can't work with nested objects.
Every hash must be replaced with WashOut::Type.
It should look like this:
{:data => [SomeType], :total => :integer}

Unknown record property / related component with multi refs to one table

in model definition
$this->hasMany('Photo', array(
'refClass' => 'StyleLangHasPhoto',
'local' => 'style_lang_id',
'foreign' => 'photo_id'));
$this->hasMany('Photo as Preview', array(
'refClass' => 'StyleLangHasPreviewPhoto',
'local' => 'style_lang_id',
'foreign' => 'photo_id'));
but getter getPreview and even $this->_get('Preview') throws Unknown record property / related component "Preview" on "StyleLang"
i've try to make like this
$this->hasMany('Photo as Slide', array(
'refClass' => 'StyleLangHasPhoto',
'local' => 'style_lang_id',
'foreign' => 'photo_id'));
$this->hasMany('Photo as Preview', array(
'refClass' => 'StyleLangHasPreviewPhoto',
'local' => 'style_lang_id',
'foreign' => 'photo_id'));
but nothing changes
what i'm doing wrong?
UDP1: getPhoto, setPhoto, setPreview works good
problem was solved
foreignAlias: in relations for Photo and Preview must be different
thanx

Or conditions in mongoid

I have two queries,
Post.where(:group_id.in => group_ids, :deleted => false)
Post.where(:user_id=>user.id,:deleted=>false)
I need to combine these query using or condition.
I tried like,
Post.where(:deleted => false).or({:user_id=>user.id},{:group_id.in => group_ids})
and
Post.any_of({:group_id.in=>group_ids},{:user_id=>user.id})
but I didn't get results.
You can do it like that:
Post.any_of({:group_id.in => group_ids, :deleted => false}, {:user_id => user.id, :deleted => false})
or:
Post.all_of(:deleted => true, :or => [{:group_id.in => group_ids}, {:user_id => user.id}])
You can call selector on any of these expressions to see mongodb query that will be generated to fetch data.

Resources