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> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn 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+&. 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]kmLTlD4IUKK@?5BUkRf8dJM@U6]>Kc^c5F X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:16548 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).