You are on page 1of 6

Sitecore Search Developers Cheat Sheet

by Kiran Patil (kpatil) via cheatography.com/20093/cs/2946/

Basics Basics (cont) Supported IQueryable methods

Terms & "​tes​t" or "​‐ c.Whe​re(​"​tes​‐ Exclusive title:​‐ c.Tit​le.B​et​‐ Restri​ction Where var results =
Phrases hello t") or Range {Aida TO wee​n("A​ida​", Operators from d in
dolly" c.Wher​‐ Carmen} "​Car​men​", queryable
e("hello Inclus​‐ where d.Name
dolly") or ion.None) == "​Sit​eco​re"
c.Wher​e("t​‐ Boosting jakarta^4 c.Tit​le.E​qu​‐ select d; or
est​" || "​‐ apache als​("ja​kar​‐ var results =
hello dolly") ta".B​oo​st(4)) querya​ble.Wh​‐

Fields title:​"The c.Title == || c.Titl​e.E​‐ ere(d =>


Right way" "The Right qua​ls(​“ap​‐ d.Name == "​‐
and way" or ache”) Sit​eco​re");
text:"g​o" c.Text == "​‐ Projection Select var results =
Boolean "​jakarta where c.Titl​‐
go" or Or apache​" e.E​qua​ls(​"​‐ Operators from d in
c.Equa​ls(​"​‐ OR jakarta queryable
go") jakarta apache​") || select d.Name;

WildCard amber c.Con​tac​tNa​‐ c.Equa​ls(​"​jak​‐ or var results

me.C​on​tains art​a") = querya​‐

("am​ber​") ble.Se​lect(d
Boolean "​jakarta where c.Equa​‐
=> d.Name);
Prefix amber c.Cont​act​Nam​e.S​‐ And apache​" ls(​"​jakarta
amber tar​tsW​ith​("am​‐ AND "​‐ apache​") && Anonymous results =
ber​") or c.Cont​act​‐ Apache c.Equa​ls(​"​‐ types querya​ble.Se​‐
Nam​e.E​nds​Wit​‐ Lucene​" Apache lect(d => new
h("a​mbe​r") Lucene​") { d.Name, d.Id
Fuzzy roam~ or c.Con​tac​tNa​‐ Boolean "​jakarta where c.Equa​‐
});
roam~0.8 me.L​ik​e("r​‐ Not apache​" Unsupp​‐ SelectMany
ls(​"​jakarta
oam​") or NOT "​‐ apache​") && orted
c.Cont​act​Nam​‐ Apache !c.Equ​als​‐ Partit​ioning Take results = querya​‐
e.L​ike​("ro​‐ Lucene​" ("Apache Operators ble.Ta​ke(​10);
am", 0.8) Lucene​") Partit​ioning Skip results =
Proximity "​jakarta c.Con​tac​tNa​‐ Grouping (jakarta where (c.Title Operators querya​ble.Sk​‐
apache​"~1 me.L​ik​e("j​‐ OR ip(​10);
== "​jak​art​a"
0 akarta apache) || c.Title == Partit​ioning Page results =
apache​", 10) AND "​apa​che​") && Operators querya​ble.Pa​‐
Inclusive mod_da​‐ c.Mod​ifi​edD​‐ website (c.Title == "​‐ ge(2, 100);
Range te:​[20​‐ ate.Be​twe​‐ web​sit​e")
020101 en(​"​200​201​‐
TO 01", "​200​301​‐
20030101] 01", Inclus​‐
ion.Both)

By Kiran Patil (kpatil) Published 29th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/kpatil/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 1 of 6. http://crosswordcheats.com

sitecorebasics.wordpress.com/
Sitecore Search Developers Cheat Sheet
by Kiran Patil (kpatil) via cheatography.com/20093/cs/2946/

Supported IQueryable methods (cont) Supported IQueryable methods (cont) Supported IQueryable methods (cont)

Ordering OrderBy results = Element First - results = Element Single​‐ result =


Operators querya​ble.Or​‐ Operators Condition querya​‐ Operators OrD​‐ querya​ble.Si​‐
derBy(d => ble.Fi​rst(d efault ngl​eOr​Def​aul​‐
d.Name); => d.Name == t(); or result
Ordering OrderBy results = "​Sit​eco​re"); = querya​‐
Operators Descending querya​ble.Or​‐ Element FirstO​‐ results = ble.Si​ngl​eOr​‐
der​ByD​esc​end​‐ Operators rDe​fault - Def​ault(d =>
querya​‐
ing(d => Simple d.Id > 10);
ble.Fi​rst​‐
d.Name);
OrD​efa​ult(); Quanti​‐ Any - results =
Ordering ThenBy results = fiers Simple querya​ble.An​‐
Element FirstO​‐ results =
Operators querya​ble.Or​‐
Operators rDe​fault - querya​‐ y();
derBy(d =>
Condition ble.Fi​rst​‐ Quanti​‐ Any - results =
d.Name​).T​‐
OrD​efa​ult(d fiers Grouped querya​‐
henBy(d =>
d.Id); => d.Name == ble.Any(d =>
"​Sit​eco​re"); d.Name == "​‐
Ordering ThenBy results =
Element ElementAt Sit​eco​re");
Operators Descending querya​ble.Or​‐ results =
derBy(d => Operators querya​‐ Quanti​‐ Unsupp​‐ All
d.Name​).T​hen​‐ ble.El​eme​‐ fiers orted
ByD​esc​end​ing(d ntA​t(10); Aggregate Count - results =
=> d.Id); Element Last 'result = querya​‐ Operators Simple querya​ble.Co​‐
Unsupp​‐ Reverse Operators ble.La​st();' or unt();
orted result = Aggregate Count - results =
Grouping Unsupp​‐ GroupBy - querya​‐ Operators Condi​‐ querya​ble.Co​‐
Operators orted Simple 1 ble.Last(d => tional unt(d => d.Id
GroupBy - d.Id > 10); < 10);
Simple 2 Element LastOr​‐ result = Aggregate Unsupp​‐ Sum Min Max
GroupBy - Operators Default querya​‐ Operators orted Average
Simple 3
ble.La​stO​‐ Aggregate
GroupBy -
rDe​fau​lt(); or Join Unsupp​‐ Cross Join Group
Nested
result = Operators orted Join Cross Join
GroupBy -
querya​‐ with Group Join
Comparer
GroupBy -
ble.La​stO​‐ Left Outer Join
rDe​fault(d =>
Comparer,
Mapped d.Id > 10);

Set Unsupp​‐ Distinct Union Element Single result =


Operators orted Intersect Except Operators querya​‐
ble.Si​ngl​e();
Element First - results =
Operators Simple or result =
querya​‐
querya​‐
ble.Fi​rst();
ble.Si​ngle(d
=> d.Id >
10);

By Kiran Patil (kpatil) Published 29th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/kpatil/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 2 of 6. http://crosswordcheats.com

sitecorebasics.wordpress.com/
Sitecore Search Developers Cheat Sheet
by Kiran Patil (kpatil) via cheatography.com/20093/cs/2946/

IQueryable Extensions IQueryable Extensions (cont) IQueryable Extensions (cont)

Filtering results = Pivot var results = Other Between results = querya​‐


querya​ble.Fi​‐ Faceting querya​ble.Fa​‐ ble.Wh​ere​(item =>
lter(d => d.Id > cet​Piv​otOn(p => item.P​ric​e.B​etw​‐
4 && d.Id < 8); p.Face​tOn(d => een​(50.0f,

Facets Simple var results = d.Name​).F​ace​‐ 400.0f, Inclus​‐


Faceting querya​ble.Fa​‐ tOn(d => ion.Bo​th)); or

cetOn(d => d.Year)); var results = querya​‐

d.Name); var facets = ble.Wh​ere​(item =>

facets = result​‐ result​s.G​etF​‐ item.P​ric​e.B​etw​‐

s.G​etF​ace​ts(); ace​ts(); een​(2.0f, 12.0f,

foreach (var foreach (var Inclus​ion.Both)

category in category in || item.P​ric​e.B​‐

facets.Ca​teg​‐ facets.Ca​teg​‐ etw​een​(80.0f,

ories) { Consol​‐ ories) { 400.0f, Inclus​‐

e.W​rit​eLi​ne(​‐ Consol​e.W​rit​‐ ion.Bo​th)); or

cat​egory .Name); eLi​ne(​cat​egory results = querya​‐

foreach (var .Name); foreach ble.Wh​ere(d =>

facetValue in (var facetValue d.Date.Be​twe​‐

catego​ry.V​alues) in catego​ry.V​‐ en(new DateTi​me(​‐

{ Consol​e.W​rit​‐ alues) { 2004, 12, 31),

eLi​ne(​"{0}: Consol​e.W​rit​‐ DateTi​me.Now,

{1}", facetV​alu​‐ eLi​ne(​"{0}: Inclus​ion.Bo​th));

e.Name, facetV​‐ {1}", facetV​‐ or results =

alu​e.A​ggr​egate); alu​e.Name, querya​ble.Wh​ere(d

} } facetV​alu​e.A​‐ => d.Id.B​etw​‐


ggr​egate); } } een(1, 4, Inclus​‐

Boosting results = ion.Bo​th)); or

querya​ble.Wh​‐ results = querya​‐

ere(d => d.Id ble.Wh​ere(d =>

== 7.Boos​t(2​‐ d.Id.B​etw​een(1,

f)).Wh​ere(d => 4, Inclus​ion.Lo​‐

d.Temp​lat​e.C​‐ wer)); or results =

ont​ain​s("o​")); querya​ble.Wh​ere(d
=> d.Id.B​etw​‐
een(1, 4, Inclus​‐
ion.Up​per)); or
results = querya​‐
ble.Wh​ere(d =>
d.Id.B​etw​een(1,
4, Inclus​ion.No​‐
ne));

By Kiran Patil (kpatil) Published 29th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/kpatil/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 3 of 6. http://crosswordcheats.com

sitecorebasics.wordpress.com/
Sitecore Search Developers Cheat Sheet
by Kiran Patil (kpatil) via cheatography.com/20093/cs/2946/

IQueryable Extensions (cont) IQueryable Extensions (cont) Daily Life usages (cont)

Other string.Co​ results = querya​‐ GetResults results = querya​‐ This using (var context =
ntains ble.Wh​ere(d => ble.Ge​tRe​sul​ts(​).H​‐ converts Conten​tSe​arc​hMa​nag​‐
!d.Tem​pla​te.C​on​‐ its.Wh​ere(i => the query er.G​et​Ind​ex(​ite​m).C​re​‐
tai​ns(​"​Hel​lo:)); i.Docu​men​t.N​ame.Co​‐ to ate​Sea​rch​Con​text()) {
nta​ins​("o")​).W​her​‐ something IQuery​abl​e<S​ear​chR​‐
Other string.Co​ results = querya​‐
your
mpareTo ble.Wh​ere(d => e(hit => hit.Score > esu​ltI​tem> search​Query
provider
!d.Nam​e.C​omp​are​‐ 0.6); = contex​t.G​etQ​uer​yab​‐
unders​‐
To(​"​Hel​lo") == GetFacets results = querya​‐ le<​Sea​rch​Res​ult​Ite​m>
tands. For
1); ble.Wh​ere(d => d.Id > (​).W​her​e(item =>
example,
0).Fac​etOn(d => item[“​_name”] ==
Other Equal results = querya​‐ for Lucene
d.Temp​late, 0).Get​‐ “Sitec​ore”) }
ble.Wh​ere(d => it is
d.Id.E​qua​l(4)); Fac​ets(); converted
to:
Other Matches results = querya​‐
Daily Life usages _name:​sit​‐
ble.Wh​ere(i =>
This using (var context = ecore
i.Temp​lat​e.M​atc​‐
hes​("^.*​$")); returns Conten​tSe​arc​hMa​nag​er.G​‐
the et​Ind​ex(​ite​m).C​re​ate​‐
Other MatchW​‐ results = querya​‐
results of Sea​rch​Con​text()) {
ildcard ble.Wh​ere(i =>
a query IQuery​abl​e<S​ear​chR​esu​‐
i.Temp​lat​e.W​‐
on your ltI​tem> search​Query =
here(i => i.Temp​‐ search
contex​t.G​etQ​uer​yab​le<​‐
lat​e.M​atc​hWi​ldc​‐ index
Sea​rch​Res​ult​Ite​m>(​).W​‐
ard​("H?​li*​m"))); and
her​e(item => item.Name
Other Like results = querya​‐ returns it
== “Sitec​ore”) }
ble.Wh​ere(i => as a
i.Temp​lat​e.L​ike​‐ Search​‐

("Ci​tec​oar​")); Res​‐
ultItem
Other string.St​‐ results = querya​‐
type.
art​sWith ble.Wh​ere(d =>
!d.Nam​e.S​tar​tsW​‐
ith​("He​llo​"));

Other string.En​ results = querya​‐


dsWith ble.Wh​ere(d =>
!d.Nam​e.E​nds​Wit​‐
h("H​ell​o"));

By Kiran Patil (kpatil) Published 29th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/kpatil/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 4 of 6. http://crosswordcheats.com

sitecorebasics.wordpress.com/
Sitecore Search Developers Cheat Sheet
by Kiran Patil (kpatil) via cheatography.com/20093/cs/2946/

Daily Life usages (cont) Daily Life usages (cont) Daily Life usages (cont)

+ using (var context = Find all var index = Conten​tSe​‐ find all items conte​xt.G​et​Que​rya​ble​‐
(+_na​‐ Conten​tSe​arc​hMa​nag​er.G​et​‐ the items arc​hMa​nag​er.G​et​Ind​ex(​"​‐ that have <Se​arc​hRe​sul​tIt​em>​‐
me:​sit​‐ Ind​ex(​ite​m).C​re​ate​Sea​rch​‐ that have sit​eco​re_​mas​ter​_in​‐ some ().W​he​re(​res​ult​Ite​‐
ecore) Con​text()) { IQuery​abl​‐ “s” in dex​"); using (var content in m=>​res​ult​Ite​m["p​age​‐
+(titl​‐ e<S​ear​chR​esu​ltI​tem> their context = index.C​re​ate​‐ the "Page _ti​tle​"​]!=​"​"
e:test search​Query = contex​t.G​‐ names Sea​rch​Con​text()) { Title" field
body:​‐ find all items conte​xt.G​et​Que​rya​ble​‐
etQ​uer​yab​le<​Sea​rch​Res​ult​‐ Consol​e.W​rit​eLine(
cms) that have <Se​arc​hRe​sul​tIt​em>​‐
Ite​m>(​).W​her​e(item => contex​t.G​etQ​uer​yab​le<​‐
or (+ lorem in the
item[“​_name”] == “Sitec​‐ Sea​rch​Res​ult​Ite​m>(​).W​‐ ().W​he​re(​res​ult​Ite​‐
(+_n​‐ body
ore​”).W​he​re(item => her​e(r​esu​ltI​tem​=>r​esu​‐ m=>​res​ult​Ite​m["b​‐
ame​:si​‐
item.Title == “Test || ltI​tem.Na​me.C​on​tai​ns(​"​‐ ody​"​].C​ont​ain​s("l​ore​‐
tecore)
item.B​ody.Co​nta​ins​(“C​‐ s")) ); m"))
+(titl​‐
e:test
MS”)) } OR using (var Finding conte​xt.G​et​Que​rya​ble​‐ finding an conte​xt.G​et​Que​rya​ble​‐
body:​‐ context = Conten​tSe​arc​‐ the first <Se​arc​hRe​sul​tIt​em>​().F​‐ item where <Se​arc​hRe​sul​tIt​em>()
cms)) hMa​nag​er.G​et​Index item ir​stO​rDe​fau​lt(​res​ult​‐ item.F​iel​‐ .Where​(re​sul​tIt​em=​‐
(item).Cr​eat​eSe​arc​hCo​nte​‐ named Ite​m=>​res​ult​Ite​m.N​ame​‐ ds[​"​Tax​‐ >re​sul​tIt​em[​"​tax​ono​‐
xt()) { IQuery​abl​e<S​ear​‐ Sitecore onomy my_​ite​ms"].Co​nta​ins​‐
=="s​ite​cor​e")
chR​esu​ltI​tem> search​Query Items"] // is (Si​tec​ore.Co​nte​ntS​‐
Finding conte​xt.G​et​Que​rya​ble​‐
= contex​t.G​etQ​uer​yab​le<​‐ a multi list
the count ear​ch.U​ti​lit​ies.Id​‐
<Se​arc​hRe​sul​tIt​em>​().C​‐
Sea​rch​Res​ult​Ite​m> ().Whe​‐ field and
of items Hel​per.No​rma​liz​eGuid
ou​nt() contains "​‐
re(item => item.Name == in a ("{0​164​24D​F-8​65C​-49​‐
{01​642​‐
“Sitec​ore​”).W​he​re(item => database DC-​9D7​A-4​0EB​810​1C7​‐
4DF​-86​5C-​‐
item.Title == “Test || 17}​"​,tr​ue)))
Finding contex​t.G​etQ​uer​yab​le<​Sea​rch​‐ 49DC-
item.B​ody.Co​nta​ins​(“C​MS”)
all the Res​ult​Ite​m>(​).W​her​e(r​esu​ltI​‐ 9D7A-4​‐
items tem​=>r​esu​ltI​tem.Te​mpl​ate​‐ 0EB​810​‐
that use Nam​e==​"​Sample Item") 1C7​17}​"
a certain
template
same conte​xt.G​et​Que​rya​ble​‐
thing as <Se​arc​hRe​sul​tIt​em>​().W​‐
above he​re(​res​ult​Ite​m=>​res​‐
but this ult​Ite​m.T​emp​lat​eId​==I​‐
time D.P​ars​e("{​760​36F​5E-​CBC​‐
using the E-46D1 -AF0A-​414​3F9​B55​‐
template
7AA​}"))
id

By Kiran Patil (kpatil) Published 29th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/kpatil/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 5 of 6. http://crosswordcheats.com

sitecorebasics.wordpress.com/
Sitecore Search Developers Cheat Sheet
by Kiran Patil (kpatil) via cheatography.com/20093/cs/2946/

Daily Life usages (cont) Advanced Usages (cont)

Find var query = LinqHe​lpe​r.C​rea​‐ To get all ISear​chIndex


items teQ​uer​y(c​ontext, UIFilt​erH​‐ details related isearc​hIndex =
based elp​ers.Pa​rse​Dat​aso​urc​eSt​rin​‐ to search index Conten​tSe​arc​hMa​‐
on g(t​xtQ​uer​y.T​ext.Tr​im(​))).Se​‐ like IsClean, nag​er.G​et​Ind​ex(​"​‐
Data lect(x => x.GetI​tem()) LastUp​dated, YOU​RIN​DEX​NAM​E");
Source .AsEnu​mer​able() .Where(x => Number​OfD​‐
string ocu​men​ts,​‐
x.Language == Siteco​re.C​on​‐
Num​ber​OfF​‐
tex​t.L​ang​uage)
ields

Advanced Usages The _content [Inde​xFi​eld​(Si​‐


field tec​ore.Co​nte​ntS​‐
Get var search​Res​ultItem =
aggregates all ear​ch.B​ui​lti​nFi​‐
Particular contex​t.G​etQ​uer​yab​le<​Sea​‐
fields from the eld​s.C​ont​ent)]
template's rch​Res​ult​Ite​m>() .Where(x
item to allow public string
item for => x.Path.Co​nta​ins​(si​tec​‐ full text ItemCo​ntent {
current ore​Ite​m.P​ath​s.F​ull​Path)) searching
website get; set; }
.Where(x => x.Temp​lateId
and latest To do your <f​ieldMap type="S​‐
== Siteco​re.D​at​a.I​D.P​ars​‐
version of index field ite​cor​e.C​ont​ent​‐
e("Y​OUR​TEM​PLA​TEI​D"))
an item config​uration Sea​rch.Fi​eldMap,
.AsEnu​mer​able() .Where(x
only Siteco​re.C​on​ten​‐
=> x != null && x.GetI​‐
tem() != null && x.Version tSe​arc​h"> <fi​eld​‐

== x.GetI​tem​().V​er​sions. Names hint="r​aw:​‐

GetLat​est​Ver​sio​n().Ve​rsi​‐ Add​Fie​ldB​yFi​eld​‐

on.T​oS​tri​ng()); Nam​e">

By Kiran Patil (kpatil) Published 29th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/kpatil/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 6 of 6. http://crosswordcheats.com

sitecorebasics.wordpress.com/

You might also like