Hi Tiago
On Tuesday, 26 February 2013 23:36:01 UTC-10, Tiago Cardoso wrote:
So basically for such cases I need to have a category that lists all brands separated by white space. What if the brands are themselves whitespaced (like 'American Express')? Will that influence the results in some way?
Good question. Normally not, but it depends. If you don't want to split the text data on /\s/ (whitespaces, the default), but have whitespaces indexed and for example split the incoming text into tokens using commas, then you would have to define a different indexing:
Index.new ... do
indexing splits_text_on: /\,/
end
This would result in the text being tokenized so:
"the input text, another token" -> ['the input text', ' another token']
instead of the default:
"the input text, another token" -> ['the', 'input', 'text', 'another', 'token']
The :from option answering to a proc would be indeed very helpful. Having the possibilty of nesting from associations would also be cool, but maybe that represents a lot more work from your side and also supporting a new DSL. I'd be alright with the proc option, though.
I think I prefer the less-funky-code-is-more approach. With category :bla, Picky simply calls method #bla on the object. When defining a source on the index, it will simply call #each on the source to get each object to index.
Example:
Index.new :bla do
source { Car.all }
category :name
end
This simply calls #each on Car.all to get each car, then calls #name on each car to get the name category data.
As an idea, feel free to make a SearchableCar class that uses Car and Wheels and offers a #brand method that returns a combination.
But yeah, I'll be thinking about the proc idea, definitely – or feel free to create a new issue on Github! :)
Florian