# Bitmask(bitwise operation) support in Ferret

**URL:** <https://www.ruby-forum.com/t/bitmask-bitwise-operation-support-in-ferret/92790>\
**Category:** Ferret\
**Created:** [April 24, 2007, 7:42am UTC](https://www.ruby-forum.com/t/bitmask-bitwise-operation-support-in-ferret/92790 "2007-04-24T07:42:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [April 24, 2007, 7:42am UTC](https://www.ruby-forum.com/t/bitmask-bitwise-operation-support-in-ferret/92790/1 "2007-04-24T07:42:40Z")

</div>

Hi,  
in my person model,  
I have a enumeration field “role” that take bits like 1, 2, 4, 8, 16,  
…  
they represent person roles(eg: admin(1), QA(2), manager(4) … ).  
Each person can take on multiple roles.

say there’s person A that’s both a admin and QA(the role value is “3”)

so if I search like “Person.find\_by\_content('role:(1))”, I expect it to  
return person A. but this clearlly doesn’t work.

Does Ferret support this kind of search?

or do I have to build in inverted index as mentioned at  
[http://www.mail-archive.com/removed\_email\_address@domain.invalid/msg00372.html](http://www.mail-archive.com/removed_email_address@domain.invalid/msg00372.html)

Thanks.  
Yaxm

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [April 24, 2007, 1:43pm UTC](https://www.ruby-forum.com/t/bitmask-bitwise-operation-support-in-ferret/92790/2 "2007-04-24T13:43:31Z")

</div>

Hi Yaxm,

I’m not sure about bitwise search operations, but you can index the  
return value of methods, as well as ActiveRecord attributes.

You could write a method called “role\_text” that returns a string  
according to the value of role: “admin manager”, and index that. Then  
you can search: ‘role\_text:admin’ and get all the admins.

Just make sure that the strings you use don’t get tokenized ambiguously  
(this depends on your analyzer I guess).

Hope this is useful.

John.

On Tue, 2007-04-24 at 07:42 +0200, Yaxm Y. wrote:

> so if I search like “Person.find\_by\_content('role:(1))”, I expect it to  
> return person A. but this clearlly doesn’t work.
> 
> Does Ferret support this kind of search?
> 
> or do I have to build in inverted index as mentioned at  
> [http://www.mail-archive.com/removed\_email\_address@domain.invalid/msg00372.html](http://www.mail-archive.com/removed_email_address@domain.invalid/msg00372.html)
> 
> Thanks.  
> Yaxm

–  
[http://johnleach.co.uk](http://johnleach.co.uk)
