Mongodb select document using Phalcon php ODM - phalcon

I am developing an application using phalcon php and Mongo DB. I want to select post_type = 'page' from the following document
{
"_id" : ObjectId("53f896db461584542200002b"),
"post_con" : {
"post_date" : "12-05-14",
"post_title" : "Test",
"post_content" : "test content",
"post_category" : "test cat",
"post_type" : "page",
"post_status" : "published",
"post_modified" : "12-05-14"
},
"comment_status" : "open",
"link_code" : "test-page",
"seo" : {
"meta_desc" : "test desc",
"meta_key" : "test key"
}
}

For those who are searching for the same, here is the full code.
$post = Posts::find(array(
'conditions'=>array('post_con.post_type'=>'blog') ));
$this->view->postlist = $post;
And in view,
{% for posts in postlist %}
{{ posts.post_con['post_title'] }}
{{ posts.post_con['post_content'] }}
{% endfor %}
Hoe this will help for someone.

Related

Shopware 6 custom endpoint for admin api doesn't return only the requested fields

I have a custom endpoint for the admin api which returns some products.
{% block response %}
{% set criteria = {
"includes": {
"product": ["id", "name"],
"cover": ['id']
},
"associations": {
"cover": {},
},
}%}
{% set products = services.repository.search('product', criteria) %}
{% set response = services.response.json({ 'products': products }) %}
{% do hook.setResponse(response) %}
{% endblock %}
When i call this endpoint i want to receive only the products ids and names as described in the criteria. But i get the full object.
I posted an example response below:
{
"apiAlias": "api_feed_data_response",
"products": {
"entity": "product",
"total": 50,
"aggregations": [],
"page": 1,
"limit": 100,
"elements": [
{
"parentId": null,
"childCount": 0,
"taxId": "a4440e5086e14cf793627c9d670694aa",
"manufacturerId": "cc1c20c365d34cfb88bfab3c3e81d350",
"unitId": null,
"active": true,
"displayGroup": "75eef7154e9f22229e54e37b3ca0e54b",
"manufacturerNumber": null,
"ean": null,
"sales": 0,
...
}
How can i get only the requested fields (id, name) ?
Starting with 6.5 of shopware it will be possible with:
{% block response %}
{% set criteria = {
"fields": {
"product": ["id", "name"],
"cover": ['id']
},
"associations": {
"cover": {},
},
}%}
...
{% endblock %}
So you should use fields instead of includes.
The difference between those two is that includes are only filtered out at the CRUD-API level,but before the response is encoded in the API layer the entities contain all fields. As you have a custom API-endpoint the filtering does not work in this case.
The fields are filtered out directly at the DB level, so that only the defined fields are fetched from the database, that means that your response in your custom API endpoint will also only include those fields.

Liquid template code in liquid to find records having specific list of keywords

I have this Liquid template to find items containing the Term value string and it works correctly:
{
"query": {
"bool": {
"must" : {
"term" : { "Content.ContentItem.ContentType" : "Product" }
},
"filter": [
{ "term": { "Content.ContentItem.Published" : "true" }},
{ "wildcard": { "Content.ContentItem.FullText" : "*{{Term}}*" }}
]
}
}
}
My FullText format is customized by:
{{Model.Content.Product.SearchKeywords.Text}} {{Model.Content.Product.Alias.Text}}
which SearchKeywords is a field in Product ContentType.
But I do not know how to find items having specific list of keywords like ["LTB-72-5", "FPS", "LBS"]

How to fix this schema markup, I am getting the error code Duplicate key found

Can you please help me fix this Schema markup. When testing on Google Structured Data Testing tool, I am getting the error code:
Duplicate key found in object declaration on line 119
<!-- JSON-LD markup generated by Google Structured Data Markup Helper. -->
<script type="application/ld+json">
{
"#context" : "http://socialwetalk.me",
"#type" : "LocalBusiness",
"name" : "SocialWeTalk",
"image" : [ "http://socialwetalk.me/wp-content/uploads/2019/03/macbook_mockup-1.png", "http://socialwetalk.me/wp-content/uploads/2018/08/service-summary-2.png" ],
"priceRange" : "$450 - $850",
"telephone" : "+961 76 020 274",
"email" : "info#socialwetalk.me",
"address" : {
"#type" : "PostalAddress",
"streetAddress" : "Hamra, Jeanne d'Arc",
"addressLocality" : "Beirut"
},
"geo" : {
"#type" : "GeoCoordinates",
"latitude" : "33.897835",
"longitude" : "35.481523"
},
"#type":"Review",
"itemReviewed":{"#type":"Product","name":"SocialWeTalk"}
"reviewRating":{"#type":"Rating","ratingValue":4.5,"bestRating":5}
"author":{"#type":"Person","name":"Samir Tutunji"}
"reviewBody":"SocialWeTalk helped us understand where our customers are coming from, and came up with an innovative concept online to keep them coming..."}
}
</script>
I am using Google Structured Data testing tool to validate my work
Its fixed and reformatted
<!-- JSON-LD markup generated by Google Structured Data Markup Helper. -->
<script type="application/ld+json">
{
"#context" : "http://schema.org",
"#type" : "LocalBusiness",
"name" : "SocialWeTalk",
"image" : [ "http://socialwetalk.me/wp-content/uploads/2019/03/macbook_mockup-1.png", "http://socialwetalk.me/wp-content/uploads/2018/08/service-summary-2.png" ],
"priceRange" : "$450 - $850",
"telephone" : "+961 76 020 274",
"email" : "info#socialwetalk.me",
"address" : {
"#type" : "PostalAddress",
"streetAddress" : "Hamra, Jeanne d'Arc",
"addressLocality" : "Beirut"
},
"review" : [
{
"#type" : "Review",
"author" : {
"#type" : "Person",
"name" : "Pro Retrofits"
},
"reviewBody" : "We love our clients"
}, {
"#type" : "Review",
"author" : {
"#type" : "Person",
"name" : "Crunch"
},
"reviewBody" : "We love our clients"
}, {
"#type" : "Review",
"author" : {
"#type" : "Person",
"name" : "SocialWeTalk"
}],
"geo" : {
"#type" : "GeoCoordinates",
"latitude" : "33.897835",
"longitude" : "35.481523"
}
}
</script>
<script type="application/ld+json">
{
"#context":"http://socialwetalk.me","#type":"Review",
"itemReviewed":{"#type":"Product","name":"SocialWeTalk"},
"reviewRating":{"#type":"Rating","ratingValue":4.5,"bestRating":5},
"author":{"#type":"Person","name":"Samir Tutunji"},
"reviewBody":"SocialWeTalk helped us understand where our customers are coming from, and came up with an innovative concept online to keep them coming..."}
</script>

Cisco ISE API POST (500 Error)

I am having difficulty creating a new endpoint in Cisco ISE using their API. Here is my code:
import json
import requests
from requests.auth import HTTPBasicAuth
# LAB Endpoint
API_ENDPOINT ="myurl.com:9060/ers/config/endpoint"
data= {
"ERSEndPoint" : {
"name": "name",
"description": "description",
"mac" : "99:99:99:99:99:99",
"profileId" : "profileId",
"staticProfileAssignment" : "false",
"groupId" : "groupId",
"staticGroupAssignment" : "false",
"portalUser" : "portalUser",
"identityStore" : "identityStore",
"identityStoreId" : "identityStoreId",
"customAttributes" : {
"customAttributes" : {
"key1" : "value1",
"key2" : "value2"
}
}
}
}
headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}
r = requests.post(url = API_ENDPOINT, data = json.dumps(data), headers=headers, auth=('user', 'pwd'))
print r.text
I keep receiving a 500 error.
> { "ERSResponse" : {
> "operation" : "POST-create-endpoint",
> "messages" : [ {
> "title" : "CREATE: DB internal error during CRUD operation Unable to create the endpoint. ORA-02291: integrity constraint
> (CEPM.REF_ROLE_MASTER) violated - parent key not found\n",
> "type" : "ERROR",
> "code" : "CRUD operation exception"
> } ],
> "link" : {
> "rel" : "related",
> "href" : "https://ezlrtvise22.msstore.microsoftstore.com:9060/ers/config/endpoint",
> "type" : "application/xml"
> } } }
It seems like it keeps throwing some weird Oracle DB key error. Any suggestions? I have tried using a REST Firefox extension to test as well and I still get the same error. Thanks!
The value for groupId and profileID need to be the respective uuids of the group/profile you want to put this device in. (Or you can leave out the profileID key entirely since it's not required.)
See https://example.com:9060/ers/config/endpointgroup to list all the endpoint groups (with their UUIDs).

What is the default doc sequence of the result from an Elasticsearch filter request?

I recently run an Elasticsearch filter request that is
{
"from" : 0,
"size" : 10,
"query" : {
"filtered" : {
"filter" : {
"bool" : {
"must" : {
"terms" : {
"a_id" : [ 257793, 257798, 257844 ]
}
}
}
}
}
},
"explain" : false,
"fields" : "a_id"
}
So that I can find all docs with a_id in 257793, 257798, 257844 and the results are 257844, 257798, 257793. So far so good.
Then I find that whatever the sequence of the term numbers are, the return docs are always in the same a_id order. That is, even I run
"terms" : {
"a_id" : [257798, 257844, 257793 ]
}
The result docs are in the order of 257844, 257798, 257793 as well.
So I am so curious about the mechanism behind the Elasticsearch filtering. Can anyone help me and give me a hint?
By default, ES returns in descending order of _score. You can provide the sort option, to say in which order and based on what you want the results to be returned. For e.g., for based on date field
{
"sort": { "date": { "order": "desc" }}
"query" : {
"term" : { "user" : "kimchy" }
}
}
You can get more information:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
https://www.elastic.co/guide/en/elasticsearch/guide/current/_sorting.html