app/src/main/java/org/weibeld/nytexplore/activity/MainActivity.java
private void loadData(int page) {
        // Read query parameter values from SharedPreferences
        String beginDate = nullify(mPref.getString(getString(R.string.pref_begin_date), ""));
        String endDate = nullify(mPref.getString(getString(R.string.pref_end_date), ""));
        String sortOrder = nullify(mPref.getString(getString(R.string.pref_sort_order), ""));
        String newsDesk = nullify(mPref.getString(getString(R.string.pref_news_desk), ""));
        String query = nullify(mQuery);

        // The "fq" parameter uses Lucene query syntax:
        //     field:value
        // If the value contains whitespace, enclose it in double quotes:
        //     field:"my value"
        // For specifying multiple values for a field enclose them in parentheses:
        //     field:("value 1" "value 2")
        // The default operator for multiple values is OR. It's possible to specify AND:
        //     field:("value 1" AND "value 2")
        // Multiple fields can be specified by separating them with a space:
        //     field1:("value 1" "value_2") field2:"value 3"
        // The default operator for multiple fields is OR. It's possible to specify AND:
        //     field1:("value 1" "value 2") AND field2:"value 3"
        //
        // Notes:
        //   - If an invalid token is submitted (e.g. invalid field name or news_desk category),
        //     then it is just ignored (no error returned). An error is only returned if the
        //     Lucene query syntax is invalid.
        //   - In general, the "q" parameter is optional (might make sense if, for example,
        //     searching all the articles of today with begin_date=...&end_date=...)
        if (newsDesk != null) {
            ArrayList<String> a = new ArrayList<>(Arrays.asList(newsDesk.split(":")));
            Iterator itr = a.iterator();
            newsDesk = "news_desk:(";
            while (itr.hasNext()) {
                newsDesk += "\"" + itr.next() + "\"";
                if (itr.hasNext()) newsDesk += " ";
                else newsDesk += ")";
            }
        }

        query(query, newsDesk, beginDate, endDate, sortOrder, page);
    }
// Read filters from SharedPreferences, and construct and execute the API query
Read filters from SharedPreferences, and construct and execute the API query
Read filters from SharedPreferences and construct and execute the API query
private void loadData(int page) {
        String beginDate = nullify(mPref.getString(getString(R.string.pref_begin_date), ""));
        String endDate = nullify(mPref.getString(getString(R.string.pref_end_date), ""));
        String sortOrder = nullify(mPref.getString(getString(R.string.pref_sort_order), ""));
        String newsDesk = nullify(mPref.getString(getString(R.string.pref_news_desk), ""));
        String query = nullify(mQuery);
         Notes:
           - If an invalid token is submitted (e.g. invalid field name or news_desk category),
             then it is just ignored (no error returned). An error is only returned if the
             Lucene query syntax is invalid.
           - In general, the "q" parameter is optional (might make sense if, for example,
             searching all the articles of today with begin_date=...&end_date=...)
        if (newsDesk != null) {
            ArrayList<String> a = new ArrayList<>(Arrays.asList(newsDesk.split(":")));
            Iterator itr = a.iterator();
            newsDesk = "news_desk:(";
            while (itr.hasNext()) {
                newsDesk += "\"" + itr.next() + "\"";
                if (itr.hasNext()) newsDesk += " ";
                else newsDesk += ")";
            }
        }
        query(query, newsDesk, beginDate, endDate, sortOrder, page);
    }
private void loadData ( int page ) { String beginDate = nullify ( mPref . getString ( getString ( R . string . pref_begin_date ) , "" ) ) ; String endDate = nullify ( mPref . getString ( getString ( R . string . pref_end_date ) , "" ) ) ; String sortOrder = nullify ( mPref . getString ( getString ( R . string . pref_sort_order ) , "" ) ) ; String newsDesk = nullify ( mPref . getString ( getString ( R . string . pref_news_desk ) , "" ) ) ; String query = nullify ( mQuery ) ; if ( newsDesk != null ) { ArrayList < String > a = new ArrayList < > ( Arrays . asList ( newsDesk . split ( ":" ) ) ) ; Iterator itr = a . iterator ( ) ; newsDesk = "news_desk:(" ; while ( itr . hasNext ( ) ) { newsDesk += "\"" + itr . next ( ) + "\"" ; if ( itr . hasNext ( ) ) newsDesk += " " ; else newsDesk += ")" ; } } query ( query , newsDesk , beginDate , endDate , sortOrder , page ) ; }
Read filters from SharedPreferences, and construct and execute the API query
Read filters from SharedPreferences and construct and execute the API query
// Read query parameter values from SharedPreferences // The "fq" parameter uses Lucene query syntax: //     field:value // If the value contains whitespace, enclose it in double quotes: //     field:"my value" // For specifying multiple values for a field enclose them in parentheses: //     field:("value 1" "value 2") // The default operator for multiple values is OR. It's possible to specify AND: //     field:("value 1" AND "value 2") // Multiple fields can be specified by separating them with a space: //     field1:("value 1" "value_2") field2:"value 3" // The default operator for multiple fields is OR. It's possible to specify AND: //     field1:("value 1" "value 2") AND field2:"value 3" // // Notes: //   - If an invalid token is submitted (e.g. invalid field name or news_desk category), //     then it is just ignored (no error returned). An error is only returned if the //     Lucene query syntax is invalid. //   - In general, the "q" parameter is optional (might make sense if, for example, //     searching all the articles of today with begin_date=...&end_date=...)