Showing posts with label sitecore9. Show all posts
Showing posts with label sitecore9. Show all posts

Monday, September 29, 2025

Mastering Advanced Search Queries with GraphQL in Sitecore XM Cloud - Part 3

Hi Sitecore folks!,

As your Sitecore content ecosystem evolves, the need for advanced and flexible search queries becomes paramount. Simple GraphQL queries are great for small datasets, but as the content grows and becomes more complex, so too must your queries. This article explores advanced search querying techniques, pagination, and real-world examples that you can implement in Sitecore XM Cloud to optimize content discovery and boost user experience.

Why Advanced Search Queries Matter

When working with Sitecore, especially in large-scale projects, simple queries quickly hit their limits. Advanced querying is essential for handling:

  • Multiple Conditions: Using logical operators like AND/OR for more granular control.
  • Exclusion Filters: Omitting certain results based on specific criteria.
  • Sorting and Pagination: Managing large datasets for better performance and usability.
  • Filtering on Complex or Nested Fields: Targeting multi-value or deeply nested fields.

GraphQL offers the flexibility needed to tackle these challenges efficiently, enabling developers to create precise, high-performing queries that meet both functional and performance requirements.

Tips for Writing Efficient GraphQL Queries

To get the most out of your GraphQL queries in Sitecore, consider the following best practices:

  1. Use Logical Operators (AND/OR/NEQ): Combine conditions effectively for highly specific filtering.
  2. Implement Pagination: Always paginate large result sets to avoid unnecessary data loading and to improve user experience.
  3. Sort Results for Better UX: Sort results based on fields like date or relevance to enhance how users interact with your data.
  4. Test Queries Before Integration: Use tools like GraphQL Playground to test and refine your queries, ensuring they work as expected before going live.

Common Comparison Operators

Understanding how and when to use comparison operators is key to building effective queries. Here’s a quick reference:

Operator Meaning Example Use Case

    EQ Equal to Department = "Engineering"

    NEQ Not equal to Status != "Inactive" 

    GT Greater than HireDate > "2022-01-01"

    LT Less than Salary < 50000 

    GTE Greater or equal Experience >= 5 

    LTE Less or equal Age <= 30

    IN In a list Department IN ("Engineering", "Marketing")

Practical Query Examples

Let’s explore some advanced query examples that leverage these techniques:

1. Filtering by Path, Template ID, and User Name with Pagination

In this example, we query for filtered items based on path, template ID, and user name, with pagination for improved performance.

query FilteredItemsResult(
$pageSize: Int = 10
$after: String
$rootItem: String!
$filterValue: String!
$templateId: String!
) {
ExpertData: search(
where: {
AND: [
{ name: "_path", value: $rootItem, operator: CONTAINS }
{ name: "_templates", value: $templateId, operator: EQ }
{ name: "UserName", value: $filterValue, operator: CONTAINS }
]
}
first: $pageSize
after: $after
) {
pageInfo {
endCursor
hasNext
}
results {
name
id
UserName: field(name: "UserName") { value }
}
}
}

Key Points:

  • AND Grouping: All conditions must be met.
  • Cursor-Based Pagination: Handles large datasets efficiently.

2. Advanced Event Query: Multi-Criteria Filtering

Here we combine OR filters within an AND block to find events based on location, available seats, sponsorship status, and rating. We also exclude events tagged as “Internal” or organized by “Test Org”.

query {
search(
where: {
AND: [
{ name: "_templates", value: "Event", operator: EQ }
{ name: "Status", value: "Published", operator: EQ }
{ name: "StartDate", value: "2025-01-01", operator: GTE }
{ name: "EndDate", value: "2025-12-31", operator: LTE }
{
OR: [
{ name: "City", value: "London", operator: EQ }
{ name: "City", value: "Berlin", operator: EQ }
]
}
{ name: "SeatsAvailable", value: "1", operator: GTE }
{ name: "IsVirtual", value: "false", operator: EQ }
{
OR: [
{ name: "IsSponsored", value: "true", operator: EQ }
{ name: "Rating", value: "4.5", operator: GT }
]
}
{ name: "Tags", value: "Internal", operator: NEQ }
{ name: "Organizer", value: "Test Org", operator: NEQ }
]
}
orderBy: [
{ fieldName: "StartDate", direction: ASC }
{ fieldName: "Rating", direction: DESC }
]
first: 10
) {
total
results {
items {
id
name
fields {
Title { value }
City { value }
StartDate { value }
SeatsAvailable { value }
IsVirtual { value }
IsSponsored { value }
Rating { value }
Tags { value }
Organizer { value }
}
}
pageInfo { endCursor hasNextPage }
}
}
}

3. Combining Filters for Tags and Authors

This query finds articles or news posts tagged with specific labels and authored by designated individuals, all sorted by the most recent publish date.

query {
search(
where: {
AND: [
{
OR: [
{ name: "Tags", value: "News", operator: CONTAINS }
{ name: "Tags", value: "Article", operator: CONTAINS }
]
}
{
OR: [
{ name: "Author", value: "Alice", operator: EQ }
{ name: "Author", value: "Bob", operator: EQ }
]
}
]
}
orderBy: [{ fieldName: "PublishDate", direction: DESC }]
first: 6
) {
total
results {
items {
id
name
fields {
Title { value }
Author { value }
Tags { value }
}
}
pageInfo { endCursor hasNextPage }
}
}
}

Key Points:

  • Nested OR within AND: Complex filtering allows for a flexible and tailored query.
  • Ordering by Date: Ensures the most recent articles appear first.

4. Filtering by Values Greater Than a Specified Amount

This query filters employees by department, hire date, and template, returning a list of employees hired after January 1, 2022, from either the Engineering or Marketing department.

query {
search(
where: {
AND: [
{ name: "_templates", value: "Employee", operator: EQ }
{ name: "Department", value: "Engineering;Marketing", operator: IN }
{ name: "HireDate", value: "2022-01-01", operator: GT }
]
}
orderBy: [
{ fieldName: "Department", direction: ASC }
{ fieldName: "HireDate", direction: DESC }
]
first: 12
) {
total
results {
items {
id
name
fields {
FirstName { value }
LastName { value }
Department { value }
HireDate { value }
Manager {
value
}
}
}
pageInfo { endCursor hasNextPage }
}
}
}

Conclusion

Advanced GraphQL queries provide Sitecore developers with the flexibility to handle complex search scenarios, enabling personalized content discovery and more efficient content management. By mastering pagination, logical operators, and filters, you can create powerful, scalable solutions that enhance user experience while improving performance.

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.

Wednesday, March 13, 2024

Getting Started With Sitecore SXA Scriban

 Hi All,

We were recently required to create an SXA-based project with the requirement to use the SXA capability with as little code as possible.

I discovered that the SXA Scriban template was really helpful on that trip. The Scriban feature is really helpful, in my opinion. With the SXA Scriban template, there are a tonne of possibilities. We may generate multiple rendering variants by utilizing the Scriban template. 

LiquidJS is a technology used in the Scriban template. With that, we can use plain HTML inside the template and call object values using a syntax similar to MVC by simply placing "{{ }}" in place of dynamic values.

Ex:

 <div class="promo-text">  
   <div>  
     <div class="field-promotext">  
       {{ i_item.PromoText }}  
     </div>  
   </div>  
   <div class="field-promolink">  
     {{ i_item.PromoLink }}  
   </div>  

You need to be aware of the SXA cerating rendering variation before you go on this quest. If not, kindly click the following link to generate a rendering variation.

To begin using Scinban, you essentially need three things:

The embedding functions for the Scriban template may be found at 
https://doc.sitecore.com/xp/en/developers/sxa/93/sitecore-experience-accelerator/the-embedded-functions-for-the-scriban-template.html 

The embedded items and objects in the Scriban context can be found at 
https://doc.sitecore.com/xp/en/developers/sxa/93/sitecore-experience-accelerator/the-embedded-items-and-objects-in-the-scriban-context.html

https://doc.sitecore.com/xp/en/developers/sxa/93/sitecore-experience-accelerator/item-and-field-extensions.html is the URL for item and field extensions.


First, you need to be familiar with the terms used in the Scriban context, such as i_home, i_datasource, i_item, i_site, i_page, o_language, o_model, o_pagemode, etc. To learn more about these terms, click the link below:

https://doc.sitecore.com/xp/en/developers/sxa/93/sitecore-experience-accelerator/the-embedded-items-and-objects-in-the-scriban-context.html

After taking a brief look at the aforementioned URL, you are aware of the fundamental objects that you may utilize in your Scriban template in order to access the things that you require. I_item and o_model, which I utilized the most in our project, are my personal favorites.


We can refer to the following documents to gain access to items and field extensions:

https://doc.sitecore.com/xp/en/developers/sxa/93/sitecore-experience-accelerator/item-and-field-extensions.html

It will be very beneficial for initiating the scriban and obtaining certain fundamental values in the scriban template.

You can search for the embedded function after you have covered these two subjects. Using that, you can use the following url to perform some basic operations, such as retrieving field values, displaying photos, retrieving link values, searching for things, retrieving dictionary values, etc.

https://doc.sitecore.com/xp/en/developers/sxa/93/sitecore-experience-accelerator/the-embedded-functions-for-the-scriban-template.html 

I'm hoping this will motivate you to begin working at SXA Scriban. Please let me know if I can be of any assistance to you. I'd be glad to assist you. We also value your feedback.

I'll try to include additional blogs with Scriban example codes and other proof-of-concept websites built entirely using SXA Scriban, complete with search features, in upcoming blog articles.

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.  

Some Other References: Clone an existing SXA component to create a brand new component

https://github.com/scriban/scriban/blob/master/doc/builtins.md

Thursday, July 27, 2023

Transition of Sitecore public feeds from MyGet to NuGet after November 2023

Hi All,


Might few of aware about Sitecore public feed transition from MyGet to Nuget after November 2023.

As that is currently in transition we faced build issue in our project and get to know about this issue.

One we updated the feed as per below link our project build started again without any issues.

For more details follow below link.

https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB1002999


I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles. Till that happy Sitecoring :) Please leave your comments or share this article if it’s useful for you. 

Tuesday, October 9, 2018

Sitecore 9 Installation step by step

Hi Folks,
Today I will try to cover how to install Sitecore Experience Platform 9 Initial Release.
Prerequisites
·       Windows 10
·       Windows PowerShell version 5.1 or later
·       MS SQL Server 2016 SP1 or later
·       MS SQL Management Studio
·       .Net Framework 4.6.2 or later
·       Web Deploy 3.6
·        SOLR 6.6.2
·       Java Runtime Environment
·       NSSM
·       Sitecore Install Framework
·       Packages for XP Single (On Premises deployment)
·       SIFLess.exe (For Quick Installation) optional                               ­­
Installation steps:
At first go with the prerequisites.
If you done with the prerequisites then you need to setup step by step.
1.       Install SQL server and SQL management studio
·       Install MS SQL server and also install MS SQL management studio (ssms) with mix mode authentication and setup password for ‘sa’ user that will be needed for Sitecore installation.
·       MS SQL Server 2017 download from here
·       MS SQL Management Studio 17 down load from here
·       Once you install both above SQL tool then you need to run a new query, for that open ssms and login with ‘SQL Server Authentication’ for user ‘sa’ with the password which you setup in previous step. After login you need to run below query for ‘Contained Database Authentication’
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
2.       Install web deploye 3.6 and JRE
After Install JRE setup environment path as below:
Variable Name: JAVA_HOME
Variable Value: C:\Program Files\Java\jre1.8.0_151
3.       Create a new folder F:\Sitecore9_Repository, you can choose your own directory path.
4.       Install Solr 6.6.2
·       Click here for download solr-6.6.2.
·       copy / paste solr-6.6.2.zip to F:\Sitecore9_Repository and unzip it.
·       Open Command prompt as administrator and navigate to bin folder of solr like “F:\Sitecore9_Repository\solr-6.6.2\bin “ and run ‘solr start’ as below:


·       After solr start you need to validate by open browser and navigate to http://localhost:8983/solr/#/
·       That show you running solr instance and showing you dashboard of solr.
5.       For make solr-6.6.2 run as window service instead of manually start all the time need to follow below steps:
·       Click here for download NSSM
·       copy / paste nssm-2.24.zip to F:\Sitecore9_Repository and unzip it
·       Open Command prompt as administrator and navigate to win64  folder of NSSM and run ‘nssm install solr-6.6.2’ command as below and fill the arguments as below:
Application Path: F:\Sitecore9_Repository\solr-6.6.2\bin\solr.cmd
Startup directory: F:\Sitecore9_Repository\solr-6.6.2\bin
Arguments: start –f –p 8983


·       Once you click on Install service a success message come “Service ‘Service Name’ installed Successfully”, now navigate to window service and check with the name ‘solr-6.6.2’ service exist there or not. That service automatically started in case that is stop start it again.





6.       Currently solr working on HTTP , for run solr HTTPS we need to do below steps:
·       Download PowerShell script from here. For download Alt+Click. Paste this script into your Sitecore9_Repository folder.
     Original from here (Thanks kamsar for this contribution).
·       Open PowerShell with Administrator access or in admin mode.
·       Run this command for set unrestricted execution policy else wise you might face “running script is disabled on your system” error.
o   Set-ExecutionPolicy -Scope CurrentUser Unrestricted
·        Now navigate to Sitecore9_Repository folder and run above script as below:
       ./solrssl.ps1
·         After this script will ask to enter path for keytool  if your java sdk or jre not installed on default path.(~program files/java/jre/bin/keytool.exe)
·       Two certificates are generated in Sitecore9_Repository. Copy paste solr-ssl.keystore.jks and solr-ssl.keystore.p12 to F:\Sitecore9_Repository\solr-6.6.2\server\etc
·       open F:\Sitecore9_Repository\solr-6.6.2\bin\solr.in.cmd and add the lines below to it
o   set SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks
o   set SOLR_SSL_KEY_STORE_PASSWORD=secret
o   set SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks
o   set SOLR_SSL_TRUST_STORE_PASSWORD=secret
·       Here above “secret” is password that is set by “solrssl.ps1” script that you can change by edit the script if you need other password.
·       Restart solr-6.6.2 window service.
·        Open a browser, navigate to https://localhost:8983/
·       Congratulation now your solr run on HTTPS instead of HTTP.

7.       SItecore Installation Framework (SIF)
Open PowerShell(Windows PowerShell ISE) as admin: Run these below commands
·        Register-PSRepository -Name SitecoreGallery -SourceLocationhttps://sitecore.myget.org/F/sc-powershell/api/v2
·        Install-Module SitecoreInstallFramework
·       Update-Module SitecoreInstallFramework

8.       Log into https://dev.sitecore.net/  and download the Sitecore XP Sigle package (Sitecore 9.0.0 rev. 171002 (WDP XP0 packages).zip).


o   copy / paste Sitecore 9.0.0 rev. 171002 (OnPrem)_single.scwdp.zip to F:\Sitecore9_Repository
o   copy / paste Sitecore 9.0.0 rev. 171002 (OnPrem)_xp0xconnect.scwdp.zip to F:\Sitecore9_Repository
o   unzip XP0 Configuration files rev.171002.zip and copy / paste all files to F:\Sitecore9_Repository\Config
In Sitecore configs open sitecore-solr.json and xconnect-solr.json and will check "SolrUrl, SolrRoot and SolrService” parameters.
9.       SIFLESS.EXE for easier Sitecore installation.
·       Download SIFLess.zip and extract to F:\Sitecore9_Repository\SIF
·       Run SIFLess.exe and navigate to EZ mode and fill the details as below:



·       Click on test once everything getting green checks, click on Generate button. That will generate a PowerShell Scripts like SIFXXXXX.PS1
·       Now will run generated final script to create sitecore 9 instance.
·        Open PowerShell as admin:
·        Goto to the path ~/Sitecore9_Repository/SIF/
·        ./SIFXXXXX.PS1
Congratulations once you run above script within some time Sitecore 9 will be installed.

If you run any kind of issue then please go through below blog that will cover some issue which you might face during installation:
     
I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)


Please leave your comments or share this article if it’s useful for you.