use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.
the class MainActivity method onNewIntent.
@SuppressLint("NewApi")
@Override
public void onNewIntent(Intent intent) {
if (nfc_capable && sp.getBoolean("nfc_search", false)) {
android.nfc.Tag tag = intent.getParcelableExtra(android.nfc.NfcAdapter.EXTRA_TAG);
String scanResult = readPageToString(tag);
if (scanResult != null) {
if (scanResult.length() > 5) {
SearchFieldDataSource source = new JsonSearchFieldDataSource(this);
if (source.hasSearchFields(app.getLibrary().getIdent())) {
List<SearchField> fields = source.getSearchFields(app.getLibrary().getIdent());
for (SearchField field : fields) {
if (field.getMeaning() == SearchField.Meaning.BARCODE) {
List<SearchQuery> queries = new ArrayList<>();
queries.add(new SearchQuery(field, scanResult));
app.startSearch(this, queries);
return;
}
}
}
Intent detailIntent = new Intent(this, SearchResultDetailActivity.class);
detailIntent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, scanResult);
startActivity(detailIntent);
}
}
}
}
use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.
the class Primo method buildSearchParams.
protected List<NameValuePair> buildSearchParams(List<SearchQuery> query) throws IOException, OpacErrorException {
List<NameValuePair> params = new ArrayList<>();
String tab = "";
if (data.has("searchtab")) {
tab = "&tab=" + data.optString("searchtab", "default_tab");
}
String html = httpGet(opac_url + "/action/search.do?mode=Advanced&ct=AdvancedSearch&vid=" + vid + tab, getDefaultEncoding());
Document doc = Jsoup.parse(html);
for (Element input : doc.select("form[name=searchForm] input[type=hidden]")) {
if (!input.attr("name").trim().equals("")) {
params.add(new BasicNameValuePair(input.attr("name"), input.val()));
}
}
params.add(new BasicNameValuePair("fn", "search"));
int i = 1;
for (SearchQuery q : query) {
if (q.getValue().equals("")) {
continue;
}
if (q.getKey().startsWith("#")) {
params.add(new BasicNameValuePair(doc.select(q.getKey()).attr("name"), q.getValue()));
} else {
if (i > 3) {
throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 3, 3));
}
params.add(new BasicNameValuePair(doc.select("#exlidInput_scope_" + i).attr("name"), q.getKey()));
params.add(new BasicNameValuePair(doc.select("#input_freeText" + (i - 1)).attr("name"), q.getValue()));
params.add(new BasicNameValuePair(doc.select("#exlidInput_precisionOperator_" + i).attr("name"), "contains"));
params.add(new BasicNameValuePair(doc.select("#exlidInput_boolOperator_" + i).attr("name"), "AND"));
i++;
}
}
return params;
}
use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.
the class Primo method parse_search.
protected SearchRequestResult parse_search(Document doc, int page) throws OpacErrorException, IOException {
doc.setBaseUri(opac_url + "/action/search.do");
List<SearchResult> reslist = new ArrayList<>();
int resnum = -1;
if (doc.select(".EXLResultsNumbers").size() > 0) {
try {
resnum = Integer.valueOf(doc.select(".EXLResultsNumbers em, .PaginationLabel strong").first().text().trim().replace(".", "").replace(",", "").replace(" ", "").replace("Ergebnisse", ""));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
for (Element resrow : doc.select(".EXLResult")) {
SearchResult res = new SearchResult();
StringBuilder description = new StringBuilder();
description.append("<b>").append(resrow.select(".EXLResultTitle").text()).append("</b>");
if (resrow.select(".EXLResultAuthor").size() > 0) {
description.append("<br />").append(resrow.select(".EXLResultAuthor").text());
}
if (resrow.select(".EXLResultDetails").size() > 0) {
description.append("<br />").append(resrow.select(".EXLResultDetails").text());
}
String availSelect = ".EXLResultAvailability span, .EXLResultAvailability em";
if (resrow.select(availSelect).size() > 0) {
description.append("<br />").append(resrow.select(availSelect).first().ownText());
}
res.setInnerhtml(description.toString());
if (resrow.select(".EXLResultStatusAvailable").size() > 0) {
res.setStatus(SearchResult.Status.GREEN);
} else if (resrow.select(".EXLResultStatusNotAvailable").size() > 0) {
res.setStatus(SearchResult.Status.RED);
} else if (resrow.select(".EXLResultStatusMaybeAvailable").size() > 0) {
res.setStatus(SearchResult.Status.YELLOW);
}
res.setPage(page);
for (Element a : resrow.select(".EXLResultTitle a, a.EXLThumbnailLinkMarker, .EXLDetailsTab a")) {
Map<String, String> q = getQueryParamsFirst(a.absUrl("href"));
if (q.containsKey("doc")) {
res.setId(q.get("doc"));
break;
}
}
if (res.getId() == null) {
continue;
}
if (resrow.select("img.EXLBriefResultsCover").size() > 0) {
String src = resrow.select("img.EXLBriefResultsCover").first().absUrl("src");
if (!src.contains("pixel.png")) {
res.setCover(src);
}
}
for (Map.Entry<String, SearchResult.MediaType> cls : mediaTypeClasses.entrySet()) {
if (resrow.hasClass(cls.getKey()) || resrow.select("." + cls.getKey()).size() > 0) {
res.setType(cls.getValue());
break;
}
}
if (resrow.select("a.EXLBriefResultsDisplayMultipleLink").size() > 0) {
String url = resrow.select("a.EXLBriefResultsDisplayMultipleLink").first().absUrl("href");
List<SearchQuery> query = new ArrayList<>();
TextSearchField field = new TextSearchField("url", "url", false, false, "url", false, false);
field.setVisible(false);
query.add(new SearchQuery(field, url));
res.setChildQuery(query);
}
reslist.add(res);
}
return new SearchRequestResult(reslist, resnum, page);
}
use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.
the class Heidi method search.
@Override
public SearchRequestResult search(List<SearchQuery> queries) throws IOException, OpacErrorException {
last_query = queries;
List<NameValuePair> params = new ArrayList<>();
if (sessid == null) {
start();
}
int index = 0;
int page = 1;
String homebranch = "";
params.add(new BasicNameValuePair("fsubmit", "1"));
params.add(new BasicNameValuePair("sess", sessid));
params.add(new BasicNameValuePair("art", "f"));
params.add(new BasicNameValuePair("pagesize", String.valueOf(pagesize)));
for (SearchQuery query : queries) {
if (query.getKey().equals("_heidi_page")) {
page = Integer.parseInt(query.getValue());
params.add(new BasicNameValuePair("start", String.valueOf((page - 1) * pagesize + 1)));
} else if (query.getKey().equals("_heidi_branch")) {
homebranch = query.getValue();
} else if (query.getKey().equals("f[teil2]")) {
params.add(new BasicNameValuePair(query.getKey(), query.getValue()));
} else {
if (!query.getValue().equals("")) {
index = addParameters(query.getKey(), query.getValue(), params, index);
}
}
}
params.add(new BasicNameValuePair("vr", "1"));
if (index == 0) {
throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
}
if (index > 3) {
throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 3, 3));
}
while (index < 3) {
index++;
if (index != 3) {
params.add(new BasicNameValuePair("op" + index, "AND"));
}
params.add(new BasicNameValuePair("kat" + index, "freitext"));
params.add(new BasicNameValuePair("var" + index, ""));
}
// Homebranch selection
httpGet(opac_url + "/zweigstelle.cgi?sess=" + sessid + "&zweig=" + homebranch, ENCODING, false, cookieStore);
// The actual search
String html = httpGet(opac_url + "/search.cgi?" + URLEncodedUtils.format(params, "UTF-8"), ENCODING, false, cookieStore);
return parse_search(html, page);
}
use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.
the class Littera method buildSearchUrl.
protected String buildSearchUrl(final List<SearchQuery> query, final int page) throws IOException, JSONException, URISyntaxException {
final URIBuilder builder = new URIBuilder(getApiUrl());
final List<SearchQuery> nonEmptyQuery = new ArrayList<>();
for (SearchQuery q : query) {
if (q.getValue().equals(""))
continue;
if (q.getKey().startsWith("sort")) {
builder.addParameter(q.getKey(), q.getValue());
} else {
nonEmptyQuery.add(q);
}
}
if (nonEmptyQuery.isEmpty()) {
builder.setParameter("mode", "n");
} else if (nonEmptyQuery.size() == 1 && "q".equals(nonEmptyQuery.get(0).getSearchField().getId())) {
builder.setParameter("mode", "s");
builder.setParameter(nonEmptyQuery.get(0).getKey(), nonEmptyQuery.get(0).getValue());
} else {
int i = 0;
for (SearchQuery q : nonEmptyQuery) {
// crit_, value_, op_ are 0-indexed
String key = q.getKey();
String value = q.getValue();
if ("q".equals(key)) {
// fall back to title since free search cannot be combined with other criteria
key = "ht";
value = "*" + value + "*";
}
builder.setParameter("crit_" + i, key);
builder.setParameter("value_" + i, value);
if (i > 0) {
builder.setParameter("op_" + i, "AND");
}
i++;
}
builder.setParameter("mode", "a");
// 1-index
builder.setParameter("critCount", String.valueOf(i));
}
// 1-indexed
builder.setParameter("page", String.valueOf(page));
builder.setParameter("page_size", "30");
return builder.build().toString();
}
Aggregations