Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16548
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="ISO-8859-1" |
| Message-ID | <1523166.s9Bo9gtfRQ@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Thu, 11 Oct 2012 01:13:20 +0200 |
| User-Agent | KNode/4.4.11 |
| Content-Transfer-Encoding | 7Bit |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Subject | Re: Searching object using AND and OR |
| Newsgroups | comp.lang.javascript |
| References | <ZaOdnXdCIZD3ZejNnZ2dnUVZ_vWdnZ2d@westnet.com.au> |
| Followup-To | comp.lang.javascript |
| MIME-Version | 1.0 |
| Lines | 50 |
| NNTP-Posting-Date | 11 Oct 2012 01:13:21 CEST |
| NNTP-Posting-Host | e6756ae0.newsspool4.arcor-online.net |
| X-Trace | DXC=\XeWgXegPHO0YVY]kmLTlD4IUK<Cl32<A4Fo<]lROoRA8kF<OcfhCOK\hWdEekMToMDZm8W4\YJNLJ`:FmdeL>K@?5BUkRf8dJM@U6]>Kc^c5F |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:16548 |
Followups directed to: comp.lang.javascript
Show key headers only | View raw
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