public ResultEvent(@NonNull final Searcher searcher, @NonNull final JSONObject json, @NonNull final Query query, final int requestSeqNumber) { super(searcher); this.results = new SearchResults(json); this.query = query; this.requestSeqNumber = requestSeqNumber; }
serverUsed = content.optString("serverUsed", null); parsedQuery = content.optString("parsedQuery", null); facets = parseFacets(content.optJSONObject("facets")); disjunctiveFacets = parseFacets(content.optJSONObject("disjunctiveFacets")); page = content.optInt("page"); nbPages = content.optInt("nbPages");
private void updateListeners(@NonNull JSONObject content, boolean isLoadingMore) { for (AlgoliaResultsListener listener : resultListeners) { listener.onResults(new SearchResults(content), isLoadingMore); } }
@Nullable @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES); final String query = uri.getLastPathSegment().toLowerCase(); try { SearchResults results = new SearchResults(index.searchSync(new Query(query).setHitsPerPage(getLimit()).setAttributesToHighlight("query"))); for (int i = 0; i < results.hits.length(); i++) { JSONObject hit = results.hits.getJSONObject(i); final String suggestion = hit.getString("query"); if (!suggestion.equalsIgnoreCase(query)) { String displaySuggestion = shouldReturnHighlightResult ? getHighlightedSuggestion(hit) : suggestion; cursor.addRow(new Object[]{hit.getString("objectID").hashCode(), displaySuggestion, suggestion}); } } return cursor; } catch (AlgoliaException e) { throw new RuntimeException(e); } catch (JSONException e) { throw new RuntimeException(e); } }