Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select blogposts liquid query #3794

Closed
aghili371 opened this issue Jun 11, 2019 · 18 comments · Fixed by #4017
Closed

select blogposts liquid query #3794

aghili371 opened this issue Jun 11, 2019 · 18 comments · Fixed by #4017
Milestone

Comments

@aghili371
Copy link

how can i get blogpost for one blog? i have 3 blogs and i want to get post of any of them
{
"query": {
"term" : { "Content.ContentItem.ContentType" : "BlogPost" }
},
"sort": { "Content.ContentItem.CreatedUtc": { "order": "desc" } },
"size": 2
}

how i should set my condition? i can see any value related to blog code. maybe we need to access parent of the list in liquid.

@sebastienros
Copy link
Member

i have 3 blogs and i want to get post of any of them

Please rephrase, I personally don't understand it

@aghili371
Copy link
Author

@sebastienros for example in blog receipt, i want to create 3 different blogs (news, events, ...) and after that, i will add some blog post for everyone.

i want to show 2 latest blog posts in the index page for any blog types . with this query, it gives me all blogpost and i can't separate by blog types like just events or news posts.

@Skrypt
Copy link
Contributor

Skrypt commented Jun 12, 2019

You can't do that with Lucene Queries. I tried with Aggregate Queries and so far I've not had any success with it. Though, for that matter you will need to do SQL Queries since you are trying to retrieve elements from 3 different content types. Something that could be done is to implement ElasticSearch DSL to allow building custom indexes eventually. Right now you best bet is to use a SQL Query and to cache it with Liquid or Razor.

@aghili371
Copy link
Author

@Skrypt it really necessary to access sub items. i think it will easily if the OC be possible to index the parent id for every item. then we can have search by parent id.

@Skrypt
Copy link
Contributor

Skrypt commented Jun 12, 2019

You can try to do :

{
"query": {
"terms" : { "Content.ContentItem.ContentType" : ["BlogType1", "BlogType2"] }
},
"sort": { "Content.ContentItem.CreatedUtc": { "order": "desc" } },
"size": 2
}

Though it could possibly return more results than requested. I need to try at least with 3 blogs content types that have the same fields and parts.

@aghili371
Copy link
Author

i think it doesn't work. because i need subitems of these "BlogType1", "BlogType2".

@Skrypt
Copy link
Contributor

Skrypt commented Jun 12, 2019

Which are all blog posts? What are the names that you used for these "blog posts" or "articles"? The standard one is named "BlogPost". So you would instead put ["BlogPost", "BlogPostType2"]. But if your Blogs all contains BlogPosts then you just need to filter on the BlogPost type with the term query filter and not the term(s) one and it should work. Ahh ! Sorry I get it now you need to filter by BlogType.

@aghili371
Copy link
Author

i have blogs named "news" and "events" , i create them by "blog" type . I need to get the latest blogposts.

I get it now you need to filter by BlogType.

yes that is. 👍 and no way to filter.

@Skrypt
Copy link
Contributor

Skrypt commented Jun 12, 2019

You should try GraphQL 😉

@aghili371
Copy link
Author

aghili371 commented Jun 12, 2019

do you have help for graphql? i need to learn that :)

@Skrypt
Copy link
Contributor

Skrypt commented Jun 12, 2019

An example :

query MyQuery {
  blog(where: {displayText_in: "Blog"}) {
    createdUtc
    modifiedUtc
    publishedUtc
    list {
      contentItems {
        createdUtc
        modifiedUtc
        publishedUtc
        ... on BlogPost {
          createdUtc
          modifiedUtc
          displayText
          markdownBody {
            markdown
          }
        }
      }
    }
  }
}

@aghili371
Copy link
Author

thank's, where i can find an example to use this query with liquid?

@Skrypt
Copy link
Contributor

Skrypt commented Jun 12, 2019

There is no Liquid helpers for this ; you query the API through javascript or with a custom controller action on your frontend I believe.

@aghili371
Copy link
Author

i know , i should develop angularjs. if you have help for calling API please inform me.

@Skrypt
Copy link
Contributor

Skrypt commented Jun 12, 2019

You can query GraphQL this way :

https://localhost:44300/api/graphql?query=

And you copy/paste your JSON schema that comes from GraphiQL at the end of that URL.

@aghili371
Copy link
Author

@sebastienros using Graphql is good, but it's better to have access to parent id in the liquid query.

@sebastienros
Copy link
Member

@aghili371 it's doable with a SQL query as we already index the id of the container (the blog). It's in the ContainedPartIndex table. You could then do 3 queries, one for each container. You can even do it from Liquid by defining a parameterized SQL query that would take the blog name or id and return the latest blog posts.

Though we also need to add this index to the Lucene index.

@sebastienros sebastienros added this to the rc milestone Jun 13, 2019
@aghili371
Copy link
Author

Though we also need to add this index to the Lucene index.

thank you for feedback. It will be great to select by container id in a liquid query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants