Question: ```
#include<iostream>

void DFS(int);
int G[10][10], visited[10], n;

//G->Adjacency Matrix, n->no of vertices

void main()
{
int i,j;
cout<<"Enter vertices";
cin>>n
cout<<"Enter adjacency matrix";
for(i=0;i<n;i++)
    for(j=0;j<n;j++)
        cin>>G[j][i];

for(i=0;i<n;i++)
    visited[i]=0

DFS(0);

void DFS(int i)
{
int j;
cout<<"\n"<<i;
visited[i]=1;
for(j=0;j<n;j++)
    if(!visited[j] && G[i][j]==1)
            DFS(j);
}

```

What does the !visited[j] in the if condition mean? I understand that once you visit any node, you have to make the node bit in the array as 1, but how do we apply the not condition for any array?

Answer: 
As per your question:

`{"g"=>{"0"=>{"m"=>"and", "c"=>{"0"=>{"a"=>{"0"=>{"name"=>"total_revenue"}}, "p"=>"gt", "v"=>{"0"=>{"value"=>"1000"}}}}}}, "s"=>{"0"=>{"name"=>"stock_health", "dir"=>"asc"}}}`

this is how your param HASH looks like and you are storing it for future use(bookmark). The problem here is, these are storing as string in your database.

**Two solution that I can suggest is:**

***1. USE HStore (<http://www.postgresql.org/docs/9.0/static/hstore.html>)***

you can use HStore type column in your postgresql database to store those param hash which you can call as it is when required. NOTE: PostgreSQL database.

***2. STRING to HASH conversion:***

[How do I convert a String object into a Hash object?](https://stackoverflow.com/questions/1667630/how-do-i-convert-a-string-object-into-a-hash-object)

> 
> NOTE I do not recommend using eval() function, coz `eval` is not safe and we can't trust params
> 
> 
> 

**RECOMMENDATION:**

another workaround for you problem I have figure out is:

1) Before saving your bookmark params, convert them to json

```
# suppose bookmark is a column you are using in SavedSearch table to store those ransack search params[:q] then

bookmark = {"g"=>{"0"=>{"m"=>"and", "c"=>{"0"=>{"a"=>{"0"=>{"name"=>"total_revenue"}}, "p"=>"gt", "v"=>{"0"=>{"value"=>"1000"}}}}}}, "s"=>{"0"=>{"name"=>"stock_health", "dir"=>"asc"}}}

@saved_search = SavedSearch.new(save_search_params)
@saved_search.bookmark = bookmark.to_json
@saved_search.save

```

2) Now, before passing these values to ransack search, convert them into original hash by:

```
require 'json'
@saved_search = SavedSearch.find(id)
original_bookmark = JSON.parse(@saved_search.bookmark)

```

I hope, this will help you solve your problem....
Try this gem: <https://rubygems.org/gems/ransack_advanced_search>
is provides a nice interface for building queries and also allow you to name and store the search for later use. Is uses the serialize method from active\_record to save the query params from the database

```
class SavedSearch < ActiveRecord::Base
  validates_presence_of :context, :description, :search_params

  serialize :search_params
end

```

It will automatically convert the search\_params back to a hash when you read it from the database