1

I have a Javascript function which goes and searches Google Fusion table column values via search box field. I am trying to make it search multiple columns with OR clause but can not make it work.

function changeMap_1() {
  var whereClause;
  var searchString = document.getElementById('search-string_1').value.replace(/'/g, "\\'");
  if (searchString != '--Select--') {
    whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "'";
  }
  layer_0.setOptions({
    query: {
      select: "col5",
      from: "1xTAvPva0-iIJo6UAKS1UuERYQTjdYZfvqOlIX_HM",
      where: whereClause
    }
  });
}

This is the function above. I have multiple "whereClause" values but everything else is the same.

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "'";

whereClause = "'Address' CONTAINS IGNORING CASE '" + searchString + "'";

whereClause = "'City' CONTAINS IGNORING CASE '" + searchString + "'";

How can i combine these "whereClause"s to say this OR this OR this...?

I tried the following two, but they didn't work.

whereClause = "'Name' CONTAINS IGNORING CASE '" || "'City' CONTAINS IGNORING CASE '"  + searchString + "'";

and

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "'" || "'Name' CONTAINS IGNORING CASE '" + searchString + "'";

Any thoughts?

Jack A.
  • 4,245
  • 1
  • 20
  • 34
spiderzaur
  • 29
  • 1
  • 7
  • you should just look up https://linqjs.codeplex.com/ – Travis J Sep 22 '15 at 22:44
  • Have you tried `whereClause = "'Name' CONTAINS IGNORING CASE ' OR 'City' CONTAINS IGNORING CASE '" + searchString + "'"` – eggmatters Sep 22 '15 at 22:58
  • 1
    FusionTables Queries do not support `OR`. Related question [Google Fusion Table SQL query where clause - only AND works, not OR?](http://stackoverflow.com/questions/7904069/google-fusion-table-sql-query-where-clause-only-and-works-not-or) – geocodezip Sep 23 '15 at 02:01
  • Related question: [Fusion Tables filter conditions OR](http://stackoverflow.com/questions/10438720/fusion-tables-filter-conditions-or) – geocodezip Sep 23 '15 at 02:02
  • Thank you guys for the tips. I ended up merging all the columns into new column and then do a search inside that new column since it contains data from all columns. – spiderzaur Sep 23 '15 at 12:59
  • Could you post your solution as an answer please (and [accept it](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work) when you can)? – geocodezip Sep 23 '15 at 13:45

2 Answers2

1

Thank you guys for the tips. I ended up merging all the columns into new column and then do a search inside that new column since it contains data from all columns.

spiderzaur
  • 29
  • 1
  • 7
0

It looks like you're evaluating your OR statement before sending it as SQL. Could that be the issue?

Something like:

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "' | 'City' CONTAINS IGNORING CASE '" + searchString + "'";

Or like:

whereClause = "'Name' CONTAINS IGNORING CASE '" + searchString + "' OR 'City' CONTAINS IGNORING CASE '" + searchString + "'";

I'm not familiar with Google Fusion Tables but it looks like they have an SQL query style.

shennan
  • 10,798
  • 5
  • 44
  • 79