Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16548
| Message-ID | <1523166.s9Bo9gtfRQ@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-10-11 01:13 +0200 |
| Subject | Re: Searching object using AND and OR |
| Newsgroups | comp.lang.javascript |
| References | <ZaOdnXdCIZD3ZejNnZ2dnUVZ_vWdnZ2d@westnet.com.au> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Andrew Poulos wrote:
> I've got a large (potentially hundreds of indexes) object that looks
> something like
>
> var obj = {
> "a":["apple","banana"],
> "b":["fish","apple","car","run","jump"],
> "c":["car,"truck","motorcycle","banana"],
> "d":["banana","boat","car","bicycle"],
> ...
> };
>
> Where array elements can only be individual words.
>
> Its straightforward enough to go through the object and return all
> indexes where a "search" word matches an element in the index's array
> but I'm stuck trying to work out how to even approach allowing the use
> of "AND" and "OR".
>
> For example, to search for
> banana AND (bicycle OR motorcycle)
> would return "c" and "d".
Since you are looking for the property names, based on the words, ISTM you
should transform `obj' into an index object that is referred by
{
"apple": ["a", "b"],
"banana" ["a", "c", "d"],
"bicycle": ["d"],
"boat": ["d"],
"car": ["b", "c", "d"],
"fish": ["b"],
"jump": ["b"],
"motorcycle": ["c"],
"run": ["b"],
"truck": ["c"],
...
};
Then, applying knowledge about the equivalence of boolean and set
operations, the solution should present itself.
HTH
PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Searching object using AND and OR Andrew Poulos <ap_prog@hotmail.com> - 2012-10-11 09:36 +1100
Re: Searching object using AND and OR Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-11 01:13 +0200
Re: Searching object using AND and OR Dr J R Stockton <reply1241@merlyn.demon.co.uk.invalid> - 2012-10-11 20:00 +0100
Re: Searching object using AND and OR Gene Wirchenko <genew@ocis.net> - 2012-10-11 16:39 -0700
Re: Searching object using AND and OR JJ <jaejunks_at@_googlemail_dot._com> - 2012-10-12 13:25 +0000
csiph-web