# Dynamic searchable fields, best practice?

**URL:** <https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458>\
**Category:** Rails\
**Created:** [May 12, 2010, 11:12am UTC](https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458 "2010-05-12T11:12:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![boblu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b19c9b/32.png) [@boblu](https://www.ruby-forum.com/u/boblu)\
**Post date:** [May 12, 2010, 11:12am UTC](https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458/1 "2010-05-12T11:12:36Z")

</div>

I have a Lexicon model, and I want user to be able to create dynamic  
feature to every lexicon.

And I have a complicate search interface that let user search on every  
single feature (including the dynamic ones) belonged to Lexicon model.

I could have used a serialized text field to save all the dynamic  
information if they are not for searching.

In case I want to let user search on all fields, I have created a  
DynamicField Model to hold all dynamically created features.

But imagine I have 1,000,000,000 lexicon, and if one create a dynamic  
feature for every lexicon, this will result creating 1,000,000,000  
rows in DynamicField model.

So the sql search function will become quite inefficient while a lot  
of dynamic features created.

Is there a better solution for this situation?

Which way should I take?

1. searching for a better db design for dynamic fields

2. try to tuning mysql(add cache fields, add index …) with current  
db design

---

<div class="post-metadata">

**Author:** ![boblu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b19c9b/32.png) [@boblu](https://www.ruby-forum.com/u/boblu)\
**Post date:** [May 12, 2010, 1:02pm UTC](https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458/2 "2010-05-12T13:02:04Z")

</div>

hi,

im trying to integrate a “ajax-chat” into my app. within the page where  
the user post a chatmessage runs a periodically\_call\_remote to update  
the message.  
now, before this happens, the user needs to create a “room” first. now  
my idea was that the controller could just do a replace\_html, which  
would b a div in the application-layout. but this doesnt work. if im  
looged in from a different browser, i dont see that update.  
clearly, im doing something “different here”.  
how would u do that, or any advise?

thx

---

<div class="post-metadata">

**Author:** ![boblu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b19c9b/32.png) [@boblu](https://www.ruby-forum.com/u/boblu)\
**Post date:** [May 12, 2010, 2:33pm UTC](https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458/3 "2010-05-12T14:33:53Z")

</div>

boblu wrote:

> I have a Lexicon model, and I want user to be able to create dynamic  
> feature to every lexicon.
> 
> And I have a complicate search interface that let user search on every  
> single feature (including the dynamic ones) belonged to Lexicon model.
> 
> I could have used a serialized text field to save all the dynamic  
> information if they are not for searching.

You might still want to. Perhaps you can write a routine that writes  
SQL queries that search through the YAML in the serialized field. It’s  
annoying, perhaps, but better than the alternative.

> In case I want to let user search on all fields, I have created a  
> DynamicField Model to hold all dynamically created features.
> 
> But imagine I have 1,000,000,000 lexicon, and if one create a dynamic  
> feature for every lexicon, this will result creating 1,000,000,000  
> rows in DynamicField model.
> 
> So the sql search function will become quite inefficient while a lot  
> of dynamic features created.

That doesn’t follow. You’d have to search through a billion lexicon  
regardless. Joining another table shouldn’t decrease the efficiency too  
much, I think

> Is there a better solution for this situation?
> 
> Which way should I take?
> 
> 1. searching for a better db design for dynamic fields
> 
> 2. try to tuning mysql(add cache fields, add index …) with current  
> db design

Your best bet here is probably 3: use a non-SQL database such as CouchDB  
or MongoDB. If you do decide to stick with an SQL database, I recommend  
PostgreSQL – it will probably deal better with your big tables.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![boblu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b19c9b/32.png) [@boblu](https://www.ruby-forum.com/u/boblu)\
**Post date:** [May 12, 2010, 4:23pm UTC](https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458/4 "2010-05-12T16:23:58Z")

</div>

[Please quote when replying. This is a mailing list, not just a Web  
forum.]

boblu wrote:

> Thank you for the detailed reply.
> 
> I will have a research on mongoDB.  
> And I am wonderring is there a way to integrate mongoDB with rails?

Yes.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![boblu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b19c9b/32.png) [@boblu](https://www.ruby-forum.com/u/boblu)\
**Post date:** [May 12, 2010, 4:24pm UTC](https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458/5 "2010-05-12T16:24:35Z")

</div>

Tom T. wrote:

> hi,
> 
> im trying to integrate a “ajax-chat” into my app. within the page where  
> the user post a chatmessage runs a periodically\_call\_remote to update  
> the message.  
> now, before this happens, the user needs to create a “room” first. now  
> my idea was that the controller could just do a replace\_html, which  
> would b a div in the application-layout. but this doesnt work. if im  
> looged in from a different browser, i dont see that update.  
> clearly, im doing something “different here”.  
> how would u do that, or any advise?
> 
> thx

Stop hijacking other people’s threads! Learn to create a new topic for  
new questions.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![boblu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b19c9b/32.png) [@boblu](https://www.ruby-forum.com/u/boblu)\
**Post date:** [May 12, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/dynamic-searchable-fields-best-practice/188458/6 "2010-05-12T16:14:42Z")

</div>

Thank you for the detailed reply.

I will have a research on mongoDB.  
And I am wonderring is there a way to integrate mongoDB with rails?
