Search in sources :

Example 11 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class StarredFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    view = inflater.inflate(R.layout.fragment_starred, container, false);
    app = (OpacClient) getActivity().getApplication();
    adapter = new ItemListAdapter();
    listView = (ListView) view.findViewById(R.id.lvStarred);
    tvWelcome = (TextView) view.findViewById(R.id.tvWelcome);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Starred item = (Starred) view.findViewById(R.id.ivDelete).getTag();
            if (item.getMNr() == null || item.getMNr().equals("null") || item.getMNr().equals("")) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                List<SearchQuery> query = new ArrayList<>();
                List<SearchField> fields = new JsonSearchFieldDataSource(app).getSearchFields(app.getLibrary().getIdent());
                if (fields != null) {
                    SearchField title_field = null, free_field = null;
                    for (SearchField field : fields) {
                        if (field.getMeaning() == Meaning.TITLE) {
                            title_field = field;
                        } else if (field.getMeaning() == Meaning.FREE) {
                            free_field = field;
                        } else if (field.getMeaning() == Meaning.HOME_BRANCH) {
                            query.add(new SearchQuery(field, sp.getString(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId(), null)));
                        }
                    }
                    if (title_field != null) {
                        query.add(new SearchQuery(title_field, item.getTitle()));
                    } else if (free_field != null) {
                        query.add(new SearchQuery(free_field, item.getTitle()));
                    }
                    app.startSearch(getActivity(), query);
                } else {
                    Toast.makeText(getActivity(), R.string.no_search_cache, Toast.LENGTH_LONG).show();
                }
            } else {
                callback.showDetail(item.getMNr());
            }
        }
    });
    listView.setClickable(true);
    listView.setTextFilterEnabled(true);
    getActivity().getSupportLoaderManager().initLoader(0, null, this);
    listView.setAdapter(adapter);
    // Restore the previously serialized activated item position.
    if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
        setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
    }
    setActivateOnItemClick(((OpacActivity) getActivity()).isTablet());
    return view;
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SharedPreferences(android.content.SharedPreferences) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) List(java.util.List) ArrayList(java.util.ArrayList) Starred(de.geeksfactory.opacclient.objects.Starred)

Example 12 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class LibraryApiTestCases method scrollTestHelper.

public void scrollTestHelper(String q) throws OpacErrorException, IOException, JSONException {
    List<SearchQuery> query = new ArrayList<>();
    SearchField field = findFreeSearchOrTitle(fields);
    if (field == null) {
        throw new // TODO: prevent this
        OpacErrorException("There is no free or title search field");
    }
    query.add(new SearchQuery(field, q));
    SearchRequestResult res = api.search(query);
    assertTrue(res.getTotal_result_count() == -1 || res.getResults().size() <= res.getTotal_result_count());
    assertTrue(res.getResults().size() > 0);
    SearchResult third;
    if (res.getResults().size() >= 3) {
        third = res.getResults().get(2);
    } else {
        third = res.getResults().get(res.getResults().size() - 1);
    }
    DetailedItem detail;
    if (third.getId() != null) {
        detail = api.getResultById(third.getId(), "");
    } else {
        detail = api.getResult(third.getNr());
    }
    assertNotNull(detail);
    confirmDetail(third, detail);
    if (res.getResults().size() < res.getTotal_result_count()) {
        api.searchGetPage(2);
        SearchResult second = res.getResults().get(1);
        DetailedItem detail2;
        if (second.getId() != null) {
            detail2 = api.getResultById(second.getId(), "");
        } else {
            detail2 = api.getResult(second.getNr());
        }
        confirmDetail(second, detail2);
    }
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) SearchRequestResult(de.geeksfactory.opacclient.objects.SearchRequestResult) ArrayList(java.util.ArrayList) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) SearchResult(de.geeksfactory.opacclient.objects.SearchResult) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem)

Example 13 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class Pica method search.

@Override
public SearchRequestResult search(List<SearchQuery> query) throws IOException, OpacErrorException, JSONException {
    if (!initialised) {
        start();
    }
    List<NameValuePair> params = new ArrayList<>();
    int index = 0;
    start();
    params.add(new BasicNameValuePair("ACT", "SRCHM"));
    params.add(new BasicNameValuePair("MATCFILTER", "Y"));
    params.add(new BasicNameValuePair("MATCSET", "Y"));
    params.add(new BasicNameValuePair("NOSCAN", "Y"));
    params.add(new BasicNameValuePair("PARSE_MNEMONICS", "N"));
    params.add(new BasicNameValuePair("PARSE_OPWORDS", "N"));
    params.add(new BasicNameValuePair("PARSE_OLDSETS", "N"));
    for (SearchQuery singleQuery : query) {
        index = addParameters(singleQuery, params, index);
    }
    if (index == 0) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
    }
    if (index > 4) {
        throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 4, 4));
    }
    String html = httpGet(opac_url + "/LNG=" + getLang() + "/DB=" + db + "/SET=1/TTL=1/CMD?" + URLEncodedUtils.format(params, getDefaultEncoding()), getDefaultEncoding(), false, cookieStore);
    return parse_search(html, 1);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 14 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class VuFind method buildSearchParams.

protected List<NameValuePair> buildSearchParams(List<SearchQuery> query) {
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("sort", "relevance"));
    params.add(new BasicNameValuePair("join", "AND"));
    for (SearchQuery singleQuery : query) {
        if (singleQuery.getValue().equals(""))
            continue;
        if (singleQuery.getKey().contains("filter[]")) {
            params.add(new BasicNameValuePair("filter[]", singleQuery.getValue()));
        } else {
            params.add(new BasicNameValuePair("type0[]", singleQuery.getKey()));
            params.add(new BasicNameValuePair("bool0[]", "AND"));
            params.add(new BasicNameValuePair("lookfor0[]", singleQuery.getValue()));
        }
    }
    return params;
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 15 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class WebOpacNet method buildParams.

private int buildParams(List<SearchQuery> queryList, List<NameValuePair> params, int page) throws JSONException {
    int index = 0;
    StringBuilder queries = new StringBuilder();
    queries.append("erw:0");
    for (SearchQuery query : queryList) {
        if (!query.getSearchField().getData().getBoolean("filter")) {
            index = addParameters(query, queries, index);
        }
    }
    for (SearchQuery query : queryList) {
        if (query.getSearchField().getData().getBoolean("filter") && !query.getValue().equals("")) {
            queries.append("&").append(query.getKey()).append("=").append(query.getValue());
        }
    }
    params.add(new BasicNameValuePair("q", queries.toString()));
    params.add(new BasicNameValuePair("p", String.valueOf(page - 1)));
    params.add(new BasicNameValuePair("t", "1"));
    return index;
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Aggregations

SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)21 ArrayList (java.util.ArrayList)16 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)11 NameValuePair (org.apache.http.NameValuePair)9 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)8 DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)6 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)6 Element (org.jsoup.nodes.Element)4 SearchRequestResult (de.geeksfactory.opacclient.objects.SearchRequestResult)3 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)3 Document (org.jsoup.nodes.Document)3 OpacErrorException (de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException)2 SearchResult (de.geeksfactory.opacclient.objects.SearchResult)2 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)2 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1