reactjsapisocrata

case-insensitive queries for a Socrata SoQL


I trying to find all the mixed case results.

For example 'Abee' will only return is searching that exact case.

I've looked in the like '...' option and tried upper (but it appears to be for the return not the query).

This is working query I'm passing.

https://data.nasa.gov/resource/gh4g-9sfh.json?$where=name%20like%20%27%25Abee%25%27

In my React app this is the function:

App.js

onChangeSearch = async (e) => {
    e.preventDefault(); 
    const name = e.target.elements.name.value;
    console.log('name: '+ name);
    const url = `${API_URL}?$limit=${API_LIMIT}&$where=name like %27%25${name}%25%27`;
    this.getData(url, 'meteorite');
  }

Form.js

const Form = props => (
    <form onSubmit={props.onChangeSearch}>
        <input type="text" name="name" placeholder="Name..." />
        <button>Search</button>
    </form>
);

I would the query itself to setup regardless if the user inputs 'ABEE', 'abee', or 'aBee'.


Solution

  • I think I found the solution:

    https://data.nasa.gov/resource/gh4g-9sfh.json?$limit=100&$where=upper(name)=%27ABEE%27

    The documentation included an example that wasn't that clear:

    upper(...)

    You can also use it within the $where parameter to do case-insensitive matches