Ages are difficult, because Sphinx stores times and dates as timestamps from 
Unix's epoch (1st Jan 1970) - so you can't store times earlier than that 
(Sphinx has no concept of signed integers either, annoyingly, so negative 
values won't get you anywhere).

You could calculate your own timestamp value with a different epoch, and store 
it as an integer - indeed, you could do it as number of days instead of number 
of seconds since a given point. Something to ponder, at least.

-- 
Pat

On 30/01/2012, at 11:52 PM, GregoryHouse wrote:

> Hi Pat,
> 
> I've decided to rebuild my country select and add values as integers
> to be stored in my db. I think that's much easier and efficient. Also
> in future I'll be able to add a countries table if I need to and still
> be able to use the stored integers to reference things in the
> countries table.
> All I have to do after this country select is done is age filtering.
> That one seems tricky as I'll have to write some code to work out a
> users age from their birthday then use that age in the filter some how
> 
> On Jan 30, 12:37 pm, "Pat Allan" <[email protected]> wrote:
>> Hi Gregory
>> 
>> You can search on specific fields - which may do the job for the country 
>> string data. The one catch there is if it's full country names, some 
>> countries may match as part of others (Democratic Republic of Congo vs 
>> Republic of Congo is one that comes to mind). It could be better to store 
>> and search on the country codes instead? The carmen gem may help with this.
>> 
>> That said, your current setup (as listed in your email) may work fine - but 
>> you should be using :conditions, not :conditions_all.
>> 
>> Cheers
>> 
>> --
>> Pat
>> 
>> On 30/01/2012, at 1:28 PM, GregoryHouse wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Having a bit of an issue with country select.
>> 
>>> **What I'm trying to do:**
>> 
>>> I'm trying to add an extra filter to my /browser page to allow users
>>> to filter results by a country from a select drop down menu also.
>> 
>>> **So far filtering by:**
>> 
>>> texted typed in location <br />
>>> gender <br />
>>> ethnicity <br />
>>> marital status <br />
>>> sexual preference <br />
>> 
>>> all work fine.
>> 
>>> Filtering works for attributes that are/were stored as integers. Take
>>> a look at my view form and you'll see I have a few select menus and
>>> these have 'Strings' that are represented by integer values:
>> 
>>> **My view:**
>> 
>>>      <%= form_tag browsers_path, :method => 'get' do %>
>>>          <p>
>>>            Location: <%= text_field_tag :location, params[:location]
>>> %>
>>>        <br />
>>>            Country: <%= country_select(:profile, :country, [ "United
>>> Kingdom", "France", "Germany" ], :prompt => "Select Country") %>
>>>        <br />
>>>            Gender: <%= select_tag :gender,
>>>                       options_for_select([["Select", nil],
>>>                          ["Male", 1],
>>>                         ["Female", 2]], params[:gender]) %>
>>>        <br />
>>>            Ethnicity: <%= select_tag :ethnicity,
>>>                       options_for_select([["Select", nil],['Black',
>>> 1 ],['White / Caucasian', 2 ],['European', 3 ],['Asian', 4 ],
>>> ['Indian', 5 ],['Middle Eastern', 6 ],['Native American', 7 ],
>>> ['Hispanic', 8 ],['Mixed Race', 9 ],['Other Ethnicity', 10 ]],
>>> params[:ethnicity]) %>
>>>        <br />
>> 
>>>            Marital status: <%= select_tag :marital_status,
>>>                       options_for_select([[' Select', nil],['Single',
>>> 1 ],['Dating', 2 ],['In relationship', 3 ],['Married', 4 ],['Living
>>> Together', 5 ],['Divorced', 6 ],['Separated', 7 ],['Widowed', 8 ]],
>>> params[:marital_status]) %>
>>>        <br />
>>>            Sexual preference: <%= select_tag :sexual_preference,
>>>                       options_for_select([[' Select', nil],
>>> ['Straight', 1 ],['Gay', 2 ],['Bi-sexual', 3 ]],
>>> params[:sexual_preference]) %>
>>>        <br />
>>>            <%= submit_tag "Search", :name => nil %>
>>>          </p>
>>>          <% end %>
>> 
>>> Everything works fine except for country select because it is stored
>>> as a string and has no integer value. For thinking sphinx attributes I
>>> think they have to be integers.. well from what I read anyway.
>> 
>>> Anyway a fix for would be to create a country select list containing
>>> an array of countries with values and then use a select tag in the way
>>> I've done with gender, marital status etc. This would take some time
>>> though and I would have to make modifications to previous work and
>>> populate my db with sample data again.
>> 
>>> **1)** I'm wondering if theres a quick way to do what I'm trying to do
>>> working with what I have now?
>> 
>>> **2)** Should I have been storing countries as integers rather than
>>> strings in the first place?
>>> what I'm asking is if that would be better practice seeing as less
>>> space would be taken up in the database using integers rather than
>>> strings..
>> 
>>> **3)** country_select seems to want a model to talk to "profile". This
>>> was fine when I was working on profile with my profile model updating
>>> the db, with things a user had to fill out their profile but now this
>>> is not needed.
>> 
>>> My model:
>> 
>>>    class Profile < ActiveRecord::Base
>> 
>>>      belongs_to :user
>>>      belongs_to :photo
>> 
>>>      # thinking sphinx
>>>      define_index do
>> 
>>>        indexes location
>>>        indexes country
>>>    has gender
>>>    has ethnicity
>>>    has marital_status
>>>    has sexual_preference
>>>    has birthday
>> 
>>>      end
>> 
>>> My controller:
>> 
>>>    class BrowsersController < ApplicationController
>>>      def index
>>>            @default_image = "/assets/default_avatar.jpg"
>>>        filters = {} # creates empty hash to pass in params.. i think
>>> any way
>>>        filters[:gender]            = params[:gender].to_i if
>>> params[:gender].present? # self explanitory
>>>        filters[:ethnicity]         = params[:ethnicity].to_i if
>>> params[:ethnicity].present? # self explanitory
>>>        filters[:marital_status]    = params[:marital_status].to_i if
>>> params[:marital_status].present? # self explanitory
>>>        filters[:sexual_preference] = params[:sexual_preference].to_i
>>> if params[:sexual_preference].present? # self explanitory
>>>        #filters[:birthday]          =
>>> (params[:birthday].to_time.to_i..Time.now.to_i)
>> 
>>>            @users = Profile.search params[:country],  # search with params
>>> of location field in form
>>>                                           :page => params[:page], # will
>>> paginate setting
>>>                                           :per_page => 20, # will paginate
>>> setting
>>>                                           :conditions_all => { :country =>
>>> params[:country]},
>>>                                           :with => filters
>> 
>>>      end
>>>    end
>> 
>>> Kind regards
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Thinking Sphinx" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to 
>>> [email protected].
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to