Computed Fields

Download Report

Transcript Computed Fields

Content Search Using SOLR
Implementing Content Search for Car
Dealer Website
By: Dr. Ehab ElGindy
Technical Team Lead
Copyright
Copyright©©Sequence
SequenceCollective
CollectiveLtd
Ltd2014
2014
Contents
• Introduction
• Sitecore/Solr Configuration
• Demo Website
• Searching Items
• Computed Fields
• Facets
• Autocomplete (Bonus)
• QA
• Thank you
Copyright © Sequence Collective Ltd 2014
Chapter
title
Introduction
Copyright © Sequence Collective Ltd 2014
Introduction
What are we going to do today?
1. Understand how Sitecore and Solr work together.
2. Implement the search for a demo car dealer website.
3. Customise Sitecore and Solr configurations to implement the search logic.
4. Discuss the best practices of implementing Solr search in Sitecore.
Copyright © Sequence Collective Ltd 2014
Chapter
title Configuration
Sitecore/Solr
Copyright © Sequence Collective Ltd 2014
Sitecore/Solr Configuration
What Can I Configure and Where?
The Sitecore.ContentSearch.Solr.Indexes.config
controls:
• What Sitecore fields/data types to index
(schema-less by default)
• Computed fields (transform the data before
being sent to Solr)
• Url of the Solr Server.
• Core names.
• Indexing strategy.
Sitecore.ContentSearch.Solr.Indexes.config
The Solr Schema.xml config file controls:
• How fields will be indexed.
• How fields will be queried.
Schema.xml
Copyright © Sequence Collective Ltd 2014
Sitecore/Solr Configuration
Example (The Text – Dynamic Field) - Sitecore
title_t
body_t
Copyright © Sequence Collective Ltd 2014
Sitecore/Solr Configuration
Example (The Text – Dynamic Field) - Solr
Copyright © Sequence Collective Ltd 2014
Chapter
Awesometitle
Cars
Copyright © Sequence Collective Ltd 2014
Auto Complete
Computed
Fields
Facets
Search Results
Copyright © Sequence Collective Ltd 2014
Searching Cars
A Simple LINQ query
Copyright © Sequence Collective Ltd 2014
Searching Cars
The Search Entity Mapping
Base Template
Car Item Template
Copyright © Sequence Collective Ltd 2014
Chapter
title
Computed
Fields
Copyright © Sequence Collective Ltd 2014
Searching Cars
Computed Fields
Store additional information about Sitecore items in Solr such
as Image Url
What you need to do?
• Implement the IComputedIndexField interface
• Override the ComputeFieldValue method
• Update the Sitecore.ContentSearch.Solr.Indexes.config to
use the computed field
Copyright © Sequence Collective Ltd 2014
Searching Cars
Computed Fields
Page url is not indexed by default.
You will need to create a computed field to fix it.
Copyright © Sequence Collective Ltd 2014
Chapter
title
Search Query
Copyright © Sequence Collective Ltd 2014
Searching Cars
Search Query
Search for: BMW
Why not using
string.Contains()?
title_t:(BMW) OR body_t:(BMW)
.Where(i => i.Title.Contains(searchQuery))
Copyright © Sequence Collective Ltd 2014
Searching Cars
Search Query (using multiword queries)
Search for: Black BMW
title_t:(“Black BMW”) OR body_t:(“Black BMW”)
Spaces = Exact matching !!!
Quick workaround
Will this work?
title_t:(Black@BMW) OR body_t:(Black@BMW)
Copyright © Sequence Collective Ltd 2014
Chapter
Facets title
Copyright © Sequence Collective Ltd 2014
Facets
Facet Category
Facets
FacetValue.Name
• Use LINQ to specify the facets
FacetValue.AggregateCount
• Use the SearchResults.Facets property to enumerate the facets
• Each facet object contains it’s name and the aggregate count
Copyright © Sequence Collective Ltd 2014
Chapter
title (NGram)
Auto-Complete
Copyright © Sequence Collective Ltd 2014
Auto-Complete
NGram
• A way of converting text into smaller tokens.
• Min and max lengths are specified.
• For example the NGram(min=2, max=3) for the word “Awesome”
is (aw, we, es, so, om, me, awe, wes, eso, ome)
• The search auto-complete is a typical application of using
NGrams
Copyright © Sequence Collective Ltd 2014
Auto-Complete
Ngram – How to implement it in Sitecore?
• Define a new field type in Solr that uses the solr.NGramTokenizerFactory.
• Create a new field in Solr using the new field type.
• Use the CopyField feature in Solr to copy the title filed into the new field.
• Map the new field to SearchResultItem class in Sitecore.
• Write a LINQ query to filter the results using the new field.
Copyright © Sequence Collective Ltd 2014
Questions
Chapter title
Copyright © Sequence Collective Ltd 2014
Thank
you
Chapter
title
Dr. Ehab ElGindy
Technical Team Lead
Email:
[email protected]
Twitter: @ehabelgindy
Blog:
http://www.ehabelgindy.com
Copyright © Sequence Collective Ltd 2014