Contentful query content type and filter on reference (multiple) - contentful

Within Contentful i have the content type "post". The post can have multiple categories (another content type). Now i'm trying to query the posts but filter them on category. My query looks something like this:
https://cdn.contentful.com/spaces/$space/entries?access_token=$token&include=3&fields.categories.fields.slug=features&limit=3&skip=0&content_type=post
The error returned:
You are trying to search on a reference to an unsupported type. You can only search on references to single entries
So basically i can only reference 1 category, but i need many not only in this use case but on a lot more. Any idea how to achieve this?

You could flip the query around and ask for entries that link to a certain category.
curl --include \
--request GET \
https://cdn.contentful.com/spaces/$SPACE_ID/environments/master/entries?access_token=$TOKEN&links_to_entry=7fYxxN67JKyUiYuE4Cq8sI&content_type=post
https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/links-to-entry

Related

How to retrieve items based on linked items from Contentful?

I have two content models in Contentful, an "Article" and a "Tag". Articles have a one-to-many relationship with tags. Is it possible using either the Contentful REST or GraphQL APIs to fetch articles based on multiple related tags?
Below is a cURL request taken from their documentation that demonstrates a way in which items can be retreived via a single related item.
curl --request GET "https://cdn.contentful.com/spaces/$SPACE\
/environments/$ENVIRONMENT/entries\
?access_token=$ACCESS_TOKEN\
&links_to_entry=$PRIMARY_ENTRY_ID"
My immediate thinking to retrieve items based on multiple related items was doing:
curl --request GET "https://cdn.contentful.com/spaces/$SPACE\
/environments/$ENVIRONMENT/entries\
?access_token=$ACCESS_TOKEN\
&links_to_entry=$PRIMARY_ENTRY_ID,$SECONDARY_ENTRY_ID"
This results in an error stating that multiple values for a filter CANNOT be used. Is there another way to accomplish this? If so, can someone provide an example using the REST and GraphQL APIs?
Thoughts, suggestions and/or solutions appreciated!

Filtering GetEntries by another Entry ID's existence within array of links attribute

I have a content type post where the entries have a categories attribute, which is an Array of Links (to a category content type).
I want to fetch all posts that have been tagged with a certain category. That is, Post entries where fields.categories[any link sys.id] = MyCategoryId.
I can only find an example only where the reference field is a singleton, not an array.
Would love any help, thanks!
You could specify your query like this:
/spaces/YOURSPACEID/entries?content_type=CONTENTTYPEID&fields.categories.sys.id=SOMEID
Notice that a content type restriction is necessary as we are filtering on a field property.
Also note that this only works because we're filtering on a system property directly accessible from the actual entry returned. If you wanted to filter on another property of the Category content type, for example title or description that is not currently supported.
Here's also a link to the official documentation including examples and explanations for the search api: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/query-entries

Kentico - Display List of related articles based on categories/subcategories

I have many articles and each is assigned under different categories/subcategories.
What I'd like to do is at the end of individual article, I'll display a list of Related Articles based on the category(s) that the current article is placed. I've added a Repeater but don't really know what to put in Content Filter/Category Name to achieve this. Hope it's not so complex. Thanks for your input!
You can achieve this in Portal without touching the code if you need to. The following steps are how you can achieve it (though they are rough and ready!)
In your Article page type, create a new query. This queries job is going to be to link the existing Document to any others that share the exact same categories. Your query should look like this:
SELECT ##TOPN## ##COLUMNS##
FROM View_CMS_Tree_Joined rel
INNER JOIN CMS_DocumentCategory relcat ON relcat.DocumentID=rel.DocumentID
INNER JOIN CMS_DocumentCategory doccat ON relcat.CategoryID=doccat.CategoryID
WHERE ##WHERE##
AND rel.DocumentID doccat.DocumentID
ORDER BY ##ORDERBY##
Now, replace you Repeater with a Repeater with custom query. In the setting, choose your newly created query for the Query name field using the selector control.
Set the WHERE clause to be doccat.DocumentID={% CurrentDocument.DocumentID #%}
Pick the appropriate transformation and you should be good to go.
This method requires an exact category match, so Categories > Cars > Mazda will not match to Categories > Cars.
Hopefully this is of some use :)
This article may give you some idea on creating a filter, but I don't think this is exactly what you want. It does show you have to get the documents thru the API.
You could do a custom query, something like this
SELECT *
FROM dbo.View_CMS_Tree_Joined vctj
WHERE vctj.DocumentID IN
(
SELECT DocumentID
FROM CMS_DocumentCategory
WHERE CategoryID IN
(
SELECT CategoryID
FROM CMS_Category
WHERE dbo.CMS_Category.CategoryName = 'Name Here'
)
);

querieng document which doesn't have a given field or is empty string in Solr

I am doing a query with solr where I need to find documents without a given field say 'name' and I am trying following part;
$q=+status:active -name:["" TO *]'
But it sends both all the documents with and without that field.
Can anyone help me figure this out?
the field name is a normal String type and is indexed.
I am using nodejs. Can anyone help me with this
According to docs:
-field:[* TO *] finds all documents without a value for field
Update
I tried it but it sends even the ones with the field non empty
Then my wild quess is that you are using search query q instead of using filter query fq. Since you are using multiple statements in query I assume that q does some extra magic to get the most relevant documents for you, which can lead to returning some non-wanted results.
If you want to get the strict set of results you should use filter query fq instead, see docs.

CAML Query with Contains and Or Clause Issue

What I want to achieve : Take a keyword array as input and query Sharepoint List to return all rows which contain the keywords in the list.
I have built a simple CAML query to query my list with one keyword (pdf) .
<Query><Where><Contains><FieldRef Name='Keyword'/><Value Type='Text'>pdf</Value></Contains></Where></Query>
This works fine.
But, when I try to use Or clause in the CAML query(see below), I get the following error
"One or more field types are not installed properly. Go to the list settings page to delete these fields."
<Query><Where><Or><Contains><FieldRef Name='Keyword'/><Value Type='Text'>pdf</Value></Contains></Or></Where></Query>
I googled for the syntax and everything looks good. Please let me know what is missing.
Thanks in advance.
In CAML Query if you want to use OR you must and should have 2 conditions.
The field reference name must be the internal name. You can find this by going to the colmn page in list/library settings and the name is the end of the URL. Spaces and underscores in the name must be handled differently.

Resources