Find-Item
Finds items using the Sitecore Content Search API.
Syntax
Detailed Description
The Find-Item command searches for items using the Sitecore Content Search API. The type SearchResultItem
is used as the type when working with IQueryable
.
© 2010-2020 Adam Najmanowicz, Michael West. All rights reserved. Sitecore PowerShell Extensions
Parameters
-Index <String>
Name of the Index that will be used for the search:
Find-Item -Index sitecore_master_index -First 10
Required?
true
Position?
1
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Criteria <SearchCriteria[]>
Simple form of search in which logical "AND" operations are needed.
Where "Filter" is one of the following values:
Equals
StartsWith
Contains
ContainsAny
ContainsAll
EndsWith
DescendantOf - performs a Contains with the field _path
Fuzzy
InclusiveRange - performs a Between using
int
,double
,datetime
, andstring
typesExclusiveRange - same as InclusiveRange
MatchesRegex - use something like
^.*$
MatchesWildcard - use something like
H?li*m
LessThan
GreaterThan
Where "Field" is the Index Field name found on the SearchResultItem
such as the following:
__smallcreateddate - CreatedDate
__smallupdateddate - Updated
_group - ID
_template - TemplateId
_templatename - TemplateName
_fullpath - Path
Where "Value" is one of the following:
string
string[]
Sitecore.Data.ID
Sitecore.Data.Items.Item
Sitecore.Data.Items.Item[]
object[] - when using
@()
you'll get this type, which will be treated as an array of stringsPSObject[]
System.Collections.ArrayList
System.Collections.Generics.List<string>
Where "Boost" is a positive number greater than 0
Fields by which you can filter can be discovered using the following script:
Where "Invert" is a boolean to indicate the following:
$false - This is the default value. Do exactly as the query is defined.
$true - Reverse the logic. For example, "Contains" is treated like "NotContains", "Equals" is treated like "NotEquals".
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Where <String>
Where the "Where" is the Dynamic Linq query and "WhereValues" includes the array of values to be replaced in the query.
Filtering Criteria using Dynamic Linq syntax: https://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-WhereValues <Object[]>
An Array of objects for Dynamic Linq "-Where" parameter as explained in: https://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Filter <String>
Where the "Filter" is the Dynamic Linq query and "FilterValues" includes the array of values to be replaced in the query.
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-FilterValues <Object[]>
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-WherePredicate <Expression<Func<SearchResultItem,bool>>>
Use the New-SearchPredicate
command to build the appropriate predicates.
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-FilterPredicate <Expression<Func<SearchResultItem,bool>>>
Use the New-SearchPredicate
command to build the appropriate predicates.
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-ScopeQuery <String>
When combined with the Query Builder field, a simple query can be crafted to return search results.
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-OrderBy <String>
Field by which the search results sorting should be performed. This is the .Net Property name as see on the SearchResultItem class. Dynamic Linq ordering syntax used. https://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-First <Int32>
Number of returned search results.
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Last <Int32>
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Skip <Int32>
Number of search results to be skipped skip before returning the results commences.
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
-Property <String[]>
An array of property names which match with the SearchResultItem
type.
Note: The use of Initialize-Item
is not supported because the object returned is no longer a SearchResultItem
and therefore unable to guarantee that Item
objects can be returned. #1123
Required?
false
Position?
named
Default Value
Accept Pipeline Input?
false
Accept Wildcard Characters?
false
Outputs
The output type is the type of the objects that the cmdlet emits.
Sitecore.ContentSearch.SearchTypes.SearchResultItem
Notes
Help Author: Adam Najmanowicz, Michael West
Examples
EXAMPLE 1
Fields by which filtering can be performed using the -Criteria parameter.
EXAMPLE 2
Find items using a search built by the Query Builder field.
EXAMPLE 3
Find all items of template "Sample Item" which are in "English" under the "Home" item using Dynamic LINQ syntax.
EXAMPLE 4
Find items using a complex search predicate.
EXAMPLE 5
Find items using logical AND conditions with ContainsAny. Demonstrates that different array types are handled.
Note: When searching for ID
s you can use the proper type like [ID[]]@("{C852E80E-ED49-4354-A397-6F66487F0E26}")
so SPE will handle the conversion to ShortID
.
EXAMPLE 6
Find items using logical AND with ContainsAll. Demonstrates looking in multilist fields.
EXAMPLE 7
Find an item by ID.
EXAMPLE 8
Find items within a data range. Possible filters are InclusiveRange
and ExclusiveRange
. When using dates, only yyyyMMdd is considered in the comparison so no need to get too precise.
EXAMPLE 9
Find and count all items beneath a root item using the item path.
EXAMPLE 10
Find and count all items beneath a root item using the item id.
EXAMPLE 11
Find items and sort (boost) based on the date field. If this were used on a field containing future dates you should expect to see them mixed with past dates. This example demonstrates using Solr functions.
EXAMPLE 12
Find items where the created date is older than the specified time in UTC.
EXAMPLE 13
Find items where the title contains the specified value. A custom implementation of SearchResultItem
is used to enable the use of the property Title
in the Dynamic Query.
EXAMPLE 14
Find items where the path contains the specified Id and base templates contain the specified Id using a Dynamic Query. A custom implementation of SearchResultItem
is used to enable the use of the property TemplateIds
in the Dynamic Query.
EXAMPLE 15
Find items where the title contains "Sitecore" using a Scope Query. A custom implementation of SearchResultItem
is used to enable the use of the property Title
in the Scope Query.
EXAMPLE 16
Find items where the template is "Sample Content" and the title contains "Sitecore" and created by "admin" using the Criteria Query. A custom implementation of SearchResultItem
is used to enable the use of the property Title
and Creator
in the Dynamic Query.
EXAMPLE 17
Find items matching a complex query. A custom implementation of SearchResultItem
is used to enable the use of the property Title
in the Predicate Query.
EXAMPLE 18
Find items under the Content tree where the language is "en" and there are more than two occurrences. This could be used to find duplicate item names at the same path.
EXAMPLE 19
Find the most recently updated item.
EXAMPLE 20
Find items where the expiration date has not passed (now to the future) or the expiration date is empty (never expires).
EXAMPLE 21
Use Skip and Take to page through results until all are returned.
Related Topics
Last updated