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

  • Working on an Unfamiliar Codebase
  • Logging Best Practices Revisited [Video]
  • Real-Time Made Easy: An Introduction to SignalR
  • Extending Java APIs: Add Missing Features Without the Hassle
  1. DZone
  2. Data Engineering
  3. Databases
  4. Wildcard queries and how Solr handles them

Wildcard queries and how Solr handles them

Rafał Kuć user avatar by
Rafał Kuć
·
Aug. 20, 11 · News
Like (0)
Save
Tweet
Share
13.92K Views

Join the DZone community and get the full member experience.

Join For Free

One of our readers reported a very interesting problem, which can be summarized to the following question – “Why doesn’t ReversedWildcardFilterFactory doesn’t work with Polish letters ?”. This entry will attempt to answer this question.

Type and field definition

Our reader has the following type of data defined in the schema.xml file:

<fieldType name="c_string" class="solr.TextField">
 <analyzer type="index">
  <tokenizer class="solr.KeywordTokenizerFactory"/>
  <filter class="solr.ASCIIFoldingFilterFactory"/>
  <filter class="solr.LowerCaseFilterFactory" />
  <filter class="solr.ReversedWildcardFilterFactory" />
 </analyzer>
 <analyzer type="query">
  <tokenizer class="solr.KeywordTokenizerFactory"/>
  <filter class="solr.ASCIIFoldingFilterFactory"/>
  <filter class="solr.LowerCaseFilterFactory" />
  <filter class="solr.ReversedWildcardFilterFactory" />
 </analyzer>
</fieldType>

One of the fields in the schema.xml file looks like this:

<field name="word" type="c_string" indexed="true" stored="true" />

Data

For the purpose of this post I used the following data:

<add>
 <doc>
  <field name="id">1</field>
  <field name="word">Zażółć gęślą jaźń</field>
 </doc>
</add>

Problem definition

The problem has been defined as follows: “I have the Polish characters in the field named word. When I make a wildcard request with the Polish character, such as “word:*ą*” Solr doesn’t find any documents“.

What should we remember when using ReversedWildcardFilterFactory

When using ReversedWildcardFilterFactory be sure to define this filter only for the index analyzer, and not to define it for query analyzer. Thus, a revised c_string definition should look like this:

<fieldType name="c_string" class="solr.TextField">
 <analyzer type="index">
  <tokenizer class="solr.KeywordTokenizerFactory"/>
  <filter class="solr.ASCIIFoldingFilterFactory"/>
  <filter class="solr.LowerCaseFilterFactory" />
  <filter class="solr.ReversedWildcardFilterFactory" />
 </analyzer>
 <analyzer type="query">
  <tokenizer class="solr.KeywordTokenizerFactory"/>
  <filter class="solr.ASCIIFoldingFilterFactory"/>
  <filter class="solr.LowerCaseFilterFactory" />
 </analyzer>
</fieldType>

Is it working now ?

When we send the follwing query to Solr:

http://localhost:8983/solr/select?q=word:*ś*

It still does not return any results. Why ?

Solr and wildcard handling

The answer to the question posted above is simple enough – Solr does not analyze queries in which there are wildcards. Yes, this means that the filter ASCIIFoldingFilterFactory, during indexing, turns Polish characters onto their counterparts from the ASCII table characters, but when making queries this is not happening, despite the fact that the filters are defined correctly. And that is why we do not get any search results. However, in this was the case, we should get the query results after sending the following query:

http://localhost:8983/solr/select?q=word:*s*

And this is exactly the case, the above returns the search results we expected.

Possible solutions

If someone asked me what would I suggested to solve the problem, I would reply that at this time I would remove the Polish characters from the queries which have wildcards. Since version 1.5, Solr, ReversedWildcardFilterFactory will correctly handle characters outside the basic ASCII table, so there will be no need to use ASCIIFoldingFilterFactory, and hence, the problem will not exist.



Database

Published at DZone with permission of Rafał Kuć, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Working on an Unfamiliar Codebase
  • Logging Best Practices Revisited [Video]
  • Real-Time Made Easy: An Introduction to SignalR
  • Extending Java APIs: Add Missing Features Without the Hassle

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: