DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Does the OCP Exam Still Make Sense?
  • A Data-Driven Approach to Application Modernization
  • IntelliJ IDEA Switches to JetBrains YouTrack
  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
  1. DZone
  2. Coding
  3. Java
  4. What’s a shingle in Lucene parlance?

What’s a shingle in Lucene parlance?

Grant Ingersoll user avatar by
Grant Ingersoll
·
Feb. 25, 11 · Interview
Like (0)
Save
Tweet
Share
13.66K Views

Join the DZone community and get the full member experience.

Join For Free

every now and then we get asked what the heck is a shingle in lucene, as in the shinglefilter or the shinglematrixfilter, so it seems worthwhile to provide some info on shingles in lucene, solr and lucidworks enterprise .  first off, a shingle is just a word-based n-gram, as opposed to a character-based n-gram (ngramtokenizer, ngramtokenfilter, edgengramtokenizer and edgengramtokenfilter provide the latter functionality).  we named it shingles just to differentiate the two when it comes to naming the filters and, well, because like shingles on your roof, they overlap each other.

what are shingles good for?  many people use them to create “pseudo-phrases” during the indexing process since the shingle ends up being a single token, which is then subject to the normal tf-idf scoring that is used in lucene.  in many cases, searching for phrases yields relevance improvements, but finding phrases at query-time can be more expensive than normal term queries, so people sometimes try to get ahead of the game and use shingles.

if you want to see shingles in action and compare them to n-grams, add the following field types to a sample solr schema:

<fieldtype name="shingle">
<analyzer>
<tokenizer class="solr.whitespacetokenizerfactory"/>
<filter class="solr.shinglefilterfactory" minshinglesize="2" maxshinglesize="5"/>
</analyzer>
</fieldtype>
<fieldtype name="ngram">
<analyzer>
<tokenizer class="solr.ngramtokenizerfactory" maxgramsize="5" mingramsize="2"/>
</analyzer>
</fieldtype>

next start up your solr instance and browse to http://localhost:8983/solr/admin/analysis.jsp and do the following steps:

  1. in the field row, choose “type” from the dropdown and enter shingle in the text area
  2. in the field value section, choose verbose output and enter “the quick red fox jumped over the lazy brown dogs”.
  3. hit submit.  you should see something like:

output of solr's analysis page

as you can see, there are multiple tokens put out for each position, many of which contain multiple words as a single token.

next, try the same sentence, but switch from “shingle” to “ngram” for the field type.  this time you should see the words split up into character groups.

for more info, see http://en.wikipedia.org/wiki/n-gram .  note, you might also find google book’s ngram viewer interesting too: http://ngrams.googlelabs.com/

Lucene

Opinions expressed by DZone contributors are their own.

Trending

  • Does the OCP Exam Still Make Sense?
  • A Data-Driven Approach to Application Modernization
  • IntelliJ IDEA Switches to JetBrains YouTrack
  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: