Elastic Nest Html Strip on Automapp - elasticsearch

Hopefully a quick one I am automapping my Index and I just want to universally strip html from any field is this possible I have tried this
var des = new CreateIndexDescriptor("myindex")
.Settings(s =>s
.Analysis(a => a
.CharFilters(c => c.HtmlStrip("product"))))
.Mappings(ms => ms
.Map<Product>(m => m
.Properties(ps => ps
.Nested<ProductSpecification>(n => n
.Name(c => c.ProductSpecification)
.Properties(psp => psp
.Keyword(s => s
.Name(ps1 => ps1.Name)
)
.Keyword(s => s
.Name(ps1 => ps1.Value)
)
)
)
).AutoMap()
));

Related

Laravel group collection and sort by the biggest value

I have a Laravel collection with values, which I want to group by 'type' and sort by the biggest 'probability'. Here is how my collection looks like:
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Array
(
[type] => correct-score
[name] => 1-1
[probability] => 10.599257670442
[probability_odd] => 10.142219704667
[odd] =>
[value_bet] => 0
[prognose_type_id] => 12
[value_bet_diff] => -10.142219704667
)
[1] => Array
(
[type] => 3-way
[name] => 1
[probability] => 52.459602877727
[probability_odd] => 2.0491958402842
[prognose_type_id] => 1
[odd] => 2.48
[value_bet_diff] => 0.4308041597158
)
[2] => Array
(
[type] => 3-way
[name] => 2
[probability] => 24.682032371379
[probability_odd] => 4.3553949845985
[prognose_type_id] => 1
[odd] => 2.66
[value_bet_diff] => -1.6953949845985
)
[3] => Array
(
[type] => 3-way
[name] => X
[probability] => 22.857984044926
[probability_odd] => 4.7029519221256
[prognose_type_id] => 1
[odd] => 3.7
[value_bet_diff] => -1.0029519221256
)
[4] => Array
(
[type] => double-chance
[name] => 1X
[probability] => 37.658793461327
[probability_odd] => 2.8545789739758
[prognose_type_id] => 4
[odd] => 1.49
[value_bet_diff] => -1.3645789739758
)
[5] => Array
(
[type] => double-chance
[name] => X2
[probability] => 23.770008208152
[probability_odd] => 4.5225058005294
[prognose_type_id] => 4
[odd] => 1.55
[value_bet_diff] => -2.9725058005294
)
[6] => Array
(
[type] => double-chance
[name] => 12
[probability] => 38.570817624553
[probability_odd] => 2.7870811826288
[prognose_type_id] => 4
[odd] => 1.29
[value_bet_diff] => -1.4970811826288
)
[7] => Array
(
[type] => both-to-score
[name] => yes
[probability] => 58.505776168275
[probability_odd] => 1.8374254140447
[prognose_type_id] => 8
[odd] =>
[value_bet_diff] => -1.8374254140447
)
I want to achieve as result something like that:
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Array
(
[type] => correct-score
[name] => 1-1
[probability] => 10.599257670442
[probability_odd] => 10.142219704667
[odd] =>
[value_bet] => 0
[prognose_type_id] => 12
[value_bet_diff] => -10.142219704667
)
[1] => Array
(
[type] => 3-way
[name] => 1
[probability] => 52.459602877727
[probability_odd] => 2.0491958402842
[prognose_type_id] => 1
[odd] => 2.48
[value_bet_diff] => 0.4308041597158
)
[6] => Array
(
[type] => double-chance
[name] => 12
[probability] => 38.570817624553
[probability_odd] => 2.7870811826288
[prognose_type_id] => 4
[odd] => 1.29
[value_bet_diff] => -1.4970811826288
)
[7] => Array
(
[type] => both-to-score
[name] => yes
[probability] => 58.505776168275
[probability_odd] => 1.8374254140447
[prognose_type_id] => 8
[odd] =>
[value_bet_diff] => -1.8374254140447
)
Haven't been able to find similar solutions, so I finally decided to try here. Can you please help me?
Thanks in advance!
I think below can work;
$collection->sortByDesc('probability')->groupBy('type');
Sort by probability than group by type;
Probably better to do this in Eloquent, but as you have presented this as a collections problem;
assuming your collection is called $items
$sorted = $items->groupBy('type')
->map(function($group){
return $group->sortByDesc('probability')->take(1);
})
->flatten(1);
The most short:
$items = $collections
->sortByDesc('probability')
->unique('type');

using Nest DateRange

Using this example, I came up with the following query. I don't get any results from this, but if I replace "01/01/2017" with 'null' then I get records (all from 2014 so i know it should be returning data). Can anyone help me please?
var response = elasticClient.Search<AnalyticsFormData>(x => x
.Type("formdata")
.Size(500)
.Query(q => q.Bool(b => b.Must
(mu => mu.MatchPhrase(m => m
.Field(f => f.AppId)
.Query(input.FormAppId)))
.Filter(fi => fi
.DateRange(r => r
.Field(f => f.LastUpdated)
.LessThanOrEquals(DateMath.Anchored("01/01/2017"))))))
.Sort(s => s.Ascending(f => f.LastUpdated)));
Either you have an incorrect field mapping, or incorrect date format. Try the following:
Create a new index with automapping
elasticClient.CreateIndex(indexName,
create => create.Mappings(
mappings => mappings.Map<AnalyticsFormData>(map => map.AutoMap())
)
);
Use the following approach to set the date
var response = client.Search<AnalyticsFormData>(x => x
.Size(500)
.Query(q => q.Bool(b => b.Must
(mu => mu.MatchPhrase(m => m
.Field(f => f.AppId).Query("FormAppId")))
.Filter(fi => fi
.DateRange(r => r
.Field(f => f.LastUpdated)
.LessThanOrEquals(new DateTime(2017, 1, 1))))))
.Sort(s => s.Ascending(f => f.LastUpdated)));

Getting data from Laravel Collection

I realize this is a dumb question, but I can't find an answer for it. I am missing some understanding around how collections work
I am querying a google places API for information about a location
$response = GooglePlaces::textSearch('10 Downing Street', $optionnalParameters);
This works and gives me a response, which I can var_export:
Illuminate\Support\Collection::__set_state(array(
'items' =>
array (
'html_attributions' =>
array (
),
'results' =>
Illuminate\Support\Collection::__set_state(array(
'items' =>
array (
0 =>
array (
'formatted_address' => '10 Downing St, London SW1A 2AA, United Kingdom',
'geometry' =>
array (
'location' =>
array (
'lat' => 51.503363499999999,
'lng' => -0.12762480000000001,
),
'viewport' =>
array (
'northeast' =>
array (
'lat' => 51.503432400000001,
'lng' => -0.12551999999999999,
),
'southwest' =>
array (
'lat' => 51.503156800000014,
'lng' => -0.12832640000000001,
),
),
),
'icon' => 'https://maps.gstatic.com/mapfiles/place_api/icons/civic_building-71.png',
'id' => 'ffd85a3e543406e34703ee947c73ef54f5e167fe',
'name' => '10 Downing Street',
'photos' =>
array (
0 =>
array (
'height' => 2534,
'html_attributions' =>
array (
0 => 'Christopher Chan',
),
'photo_reference' => 'CoQBdwAAAHdqDNRUhalI7Ko_YXqckWM5M7I1IeD0xXOvjnxruS4BYCFnt99lCEy5xQJh7XtTvGTfZbKlnVhbxaJ_OloLxaPyoInqIpgRY-3LyB3Q70tDX3izeraFEM4Bw-ExmRzz6h18iMQlKb0DoDXnW26uO4RR-7YFjPNi6M0y5D7cmrl9EhAmI7GerM-TXpKD3BVVTtOWGhQZotS0ZNI2nK9G7jXxDEyvoQ5IxQ',
'width' => 3801,
),
),
'place_id' => 'ChIJRxzRQcUEdkgRGVaKyzmkgvg',
'rating' => 3.3999999999999999,
'reference' => 'CmRSAAAAh-Drhh9G_EW3azxZSikW_jR-ZjI2lhZTw6MfWqh9EiTaCEy4uW2okv_g6QfaKoupoeDu3DpfS6MjIvUvp6cc2uAoLlyH9NbkMrnQg9q3ED3R91OejmAScjRhe8G47kJ1EhD_oYVFakm4n6I27j-8iN6oGhQVH6rv1t6uGQBVVOqy1fCAB17JOg',
'types' =>
array (
0 => 'point_of_interest',
1 => 'establishment',
),
),
),
)),
'status' => 'OK',
),
))
I want to get the formatted_address element from the collection. it appears under the results element, that in turn has a collection under it with elements Items,0,formatted_address.
when i start trying to 'walk down' to the element i require I get index not found for Items
var_export($response['results']['items']);
so essentially, how am I supposed to interact with collections? i have tried google but most the links tell me about the extra functions that collections provide and not how to get data from it
any help greatly appreciated.
I think https://laravel.com/docs/5.3/collections#method-all explains what you are missing. You want to call
->all()
on your Collection to return the underlying array represented by the collection.
Than you can access fields in the returned array.

How to collect such info in magento listing page?

I need the catalog_product_entity_media_gallery table value data only on listing page.
When i am going to listing page and use the print_r($_productCollection);
$_productCollection on listing page returns me a array like this.
[_resourceName:protected] => catalog/product
[_resource:protected] =>
[_resourceCollectionName:protected] => catalog/product_collection
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[entity_id] => 160
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => 104580
[has_options] => 0
[required_options] => 0
[created_at] => 2014-12-01 10:40:25
[updated_at] => 2014-12-01 11:51:15
[cat_index_position] => 1
[price] => 4.4900
[tax_class_id] => 4
[final_price] => 4.4900
[minimal_price] => 4.4900
[min_price] => 4.4900
[max_price] => 4.4900
[tier_price] =>
[name] => E Shisha E Liquid eKaiser *Menthol Flavour* 10ml Platinum Bottle Refill for Rechargeable E cigarette and E Shisha
[msrp_enabled] => 1
[msrp_display_actual_price_type] => 1
[thumbnail] => amazon_images/104580.jpg
[small_image] => amazon_images/104580.jpg
[image_label] =>
[small_image_label] =>
[thumbnail_label] =>
[url_key] => e-shisha-e-liquid-ekaiser-menthol-flavour-10ml-platinum-bottle-refill-for-rechargeable-e-cigarette-and-e-shisha
[short_description] => The eKaiser Platinum e Liquid range is made specifically for Cigarette smokers.
I need the only [small_image] value, which returns me only the amazon_images/104580.jpg
If any One have any idea, how to do it
Please help me.
Thank you
And also you can do like this :
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGallery('images') as $image) {
...
}
You can do like this on listing page.
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGalleryImages() as $image) {
var_dump($image->getUrl());
}
A for loop in listing with getModel will slow down your listing page considerably.
With listing page you should only use flat tables for collection.
So you need to make sure that small image is populated in flat table.

Iterating an array via Smarty in SugarCRM

When iterating an array in Smarty I am getting results conflicting with a print_r() of the same array.
When doing a print_r() on the array I can see that there are 2 objects in the array and each object is unique. However, when I run a print_r() on each item of the array (via foreach loop) I seem to get the same results for each item.
Can anyone identify what I'm doing wrong?
See the below code examples and results.
Code:
{$fields.rgggo_spreadsheetcellmap_documents.value->beans|#print_r}
Ouput:
Array
(
[a852b076-a5cb-dda9-3868-52010d6957ab] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => a852b076-a5cb-dda9-3868-52010d6957ab
[name] =>
[date_entered] => 08/06/2013 09:52am
[date_modified] => 08/06/2013 02:16pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] => Test 2
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => document_type_text_c
[row] => 3
[col] => 1
.... a bunch more stuff here
)
[f038918d-a13d-69f0-3541-51fff82f0497] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
)
When I iterate the array...
{{foreach from=$fields.rgggo_spreadsheetcellmap_documents.value->beans key=k item=v}}
<pre>
{$v|#print_r}
</pre>
{{/foreach}}
I get these results:
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
I found the answer in another stackoverflow question. The issue is double vs single curly brackets and their use in SugarCRM.
Is there a difference between using a single vs. double brace (delimiters) in SugarCRM Smarty tpls command construct?

Resources