voila
voila

Reputation: 1666

Solr store and search ordinal numbers with suffixes

Suppose I have to store student academic details like...

  1. College name -- text field searchable
  2. Student Class -- text field searchable
  3. Subjects -- multivalue field , text field searchable

How do I store/handle "Student class" because student can search like this "students of class 4th" , "Students of class 4" , "student of class fourth"

How Can I handle these (4th, 4, fourth) variations? What are elegant ways to do so.

Thanks Amit Aggarwal

Upvotes: 0

Views: 159

Answers (1)

Fuu
Fuu

Reputation: 3474

One way to solve this problem is to use a field type that supports query time synonyms. Check out the "text_general" type in the example solr schema.

In practice you would add rows like this to the synonyms.txt file in your cores conf dir:

# numbers
1,1st,first
2,2nd,second
3,3rd,third
4,4th,fourth

Now, lets suppose you had a document such as:

{ "college":"Princeton", "class":"1", "subjects":["CS 101", "introduction to full text search"]}

You could then retrieve that document if you do a query such as:

class:first

In this example the search query is directed towards one field, which may or may not be what you want. If you need to target the search query with number synonym matching into multiple fields( ie, search query with no field specifier, just the search term), you could copy all those fields content into a single synonym searchable field (using copyField) such as content_synonyms and then run the query against this field by default.

Upvotes: 1

Related Questions