Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:40:29+00:00 2026-06-03T09:40:29+00:00

Situation: I have user model. attribute meta_data in db represents text type field. In

  • 0

Situation:
I have user model. attribute “meta_data” in db represents “text” type field.
In model it seriazized by custom class. ( serialize :meta_data, CustomJsonSerializer.new )

It means, when I have an instance of user, I can work with meta_data like with Hash.

User.first.meta_data['username']

Problem:

I need to write a search function, which will search users by given string. I can do it by manual building search query in rails ex. User.where("email LIKE '%#{string}%'")...
But what about meta_data ? Should I search in this field by LIKE statement too? If I will do so, it will decrease relevance of found record.

For example:

I have 2 users. One of them has username “patrick”, another one is “sergio”

meta data in db will look like this:

1) {username: patrick}

2) {username: sergio}

I want to find sergio , I enter a search string “ser” => but I have 2 results, instead of one. This meta_data string “{uSERname: Patrick}” also has “ser”, so it makes this record irrelevant.

Do you have any idea how to solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:40:31+00:00Added an answer on June 3, 2026 at 9:40 am

    That’s really the problem with serialized data. In theory, the serialization could be an algorithm that is very unsearchable. It could do a Hoffman encoding, or other compression, and store the serialization in binary. You are relying on the assumption that the serialization uses JSON and your string will still be findable as a sub-string in the serialization.

    Then the problem you are having is another issue. Other data in the serialization can mess up your results.

    In general, if you serialize data, you are making a choice to not be searchable.

    So a solution would be to add an additional field that you populate in a way that you control. Have a values field and store a pipe (|) delimited value that you can search. So if the data is {firstname: “Patrick”, lastname: “Stern”}, your meta_values field might be “Patrick|Stern”.

    Also, don’t use the where method with a string with #{} expansion of input values. The makes it vulnerable to SQL attacks. Instead use:

    where("meta_values is like :pattern", pattern: "%#{string}%")
    

    I know that may not look very different, but ActiveRecord will go through a sanitizing this way. If someone has a semi-colon in string, then ActiveRecord will escape the semi-colon in the search condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: I have class User with the follwing properies :
I have a profile class: class profile(db.Model): user = db.stringProperty() # Other properties ...
Situation: I have a team model, a user model and a teamate model for
Situation Consider I've got the following class structure: // a user model class UserModel
I have a meta class for the Django User model that I use to
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have situation where a user can manipulate a large set of data (presented
I have situation like this: user submits form with action='/pay' in '/pay' I have
I have a situation where user requests to do a long running process. I
I have a situation in which user can single tap a control, which show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.