Thanks to James, I am now a lot closer to finalizing my advance search,
great big thanks..

However the range matching is still acting up and I am fighting with it not
being able to understand where I go wrong etc.

So here is the deal.
I want to be able to find all the books that has sold a range precentages of
the total stock

i.e say  book A initially had 1000 in stock, I have later sold a total of 63
books This book then has 937 books left therefore I have sold 6,3% of the
total stock.

I now am trying to make a search that allows me to find all books that have
sold between x%-y%. 0≤x/y≤100

So I set out by doing as James showed above

has "book_sold/book_total", :as => :sold, :type => :float

I then tried the following search to see how well this worked.

@books = Book.search :all, :conditions => { :sold => 0..0 }
@comp = Book.find(:all, :conditions => ( "book_sold = 0")

To my suprise, @books only contains 20 records as compared to my wish for
1036 that @comp gave me

anyone has any idea what I am missing here. the gray hairs are becoming more
and more

--Peter

On Wed, Apr 15, 2009 at 3:40 PM, James Healy <[email protected]> wrote:

> Peter Tellgren wrote:
> > I am now struggling with one last issue.
> > I am trying to index a difference between 2 fields (possible?)
> > I want to be able this way to search by books that has sold x out of y
> > available copies.
> >
> > something lilke: has books_total - books_sold, :as => books_left
> >
> > Is this even possible or should i just make a new column in my table
> > containing this value?
> > It seems I am in deep water as the index builder is throwing errors at
> me..
> > both columns are integer values though and I can add them seperatly..
>
> It is definitely possible to generate custom attributes.
>
>  has "books_total - books_sold", :as => books_left, :type => :integer
>
> Have a read of the comments for the has() method in
> lib/thinking_sphinx/index/builder.rd, it covers some of the syntax you
> might find useful.
>
> For searching, try the comments in lib/thinking_sphinx/search.rb
>
> -- James Healy <jimmy-at-deefa-dot-com>  Wed, 15 Apr 2009 23:36:04 +1000
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAknl47kACgkQ4oawkrbYo/keTACcCNJ8hHfxGz/RgpBpOXa7T+ID
> 6noAn0YGFhNhg7J+cO5emdNJw/5rKnDW
> =ekIB
> -----END PGP SIGNATURE-----
>
>

--~--~---------~--~----~------------~-------~--~----~
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