Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.factual.driver;
  
  import java.util.List;
  import java.util.Map;

Represents a top level Factual query. Knows how to represent the query as URL encoded key value pairs, ready for the query string in a GET request. (See toUrlQuery())

Author(s):
aaron
 
 public class Query implements Filterable {
 
   private boolean includeRowCount;

  
Holds all parameters for this Query.
 
   protected final Parameters queryParams = new Parameters();

  
Sets a full text search query. Factual will use this value to perform a full text search against various attributes of the underlying table, such as entity name, address, etc.

Parameters:
term the text for which to perform a full text search.
Returns:
this Query
 
   public Query search(String term) {
     addParam(.term);
     return this;
   }

  
Sets the maximum amount of records to return from this Query.

Parameters:
limit the maximum amount of records to return from this Query.
Returns:
this Query
 
   public Query limit(long limit) {
     addParam(., (limit > 0 ? limit : null));
     return this;
   }

  
Sets the fields to select. This is optional; default behaviour is generally to select all fields in the schema.

Parameters:
fields the fields to select.
Returns:
this Query
 
   public Query only(String... fields) {
     for (String field : fields) {
     }
     return this;
   }

  

Returns:
array of select fields set by only(), null if none.
 
   public String[] getSelectFields() {
   }

  
Sets this Query to sort field in ascending order.

Parameters:
field the field to sort in ascending order.
Returns:
this Query
 
   public Query sortAsc(String field) {
     return this;
   }

  
Sets this Query to sort field in descending order.

Parameters:
field the field to sort in descending order.
Returns:
this Query
 
   public Query sortDesc(String field) {
     return this;
   }

  
Sets how many records in to start getting results (i.e., the page offset) for this Query.

Parameters:
offset the page offset for this Query.
Returns:
this Query
  public Query offset(long offset) {
    addParam(., (offset > 0 ? offset : null));
    return this;
  }

  
The response will include a count of the total number of rows in the table that conform to the request based on included filters. This will increase the time required to return a response. The default behavior is to NOT include a row count.

Returns:
this Query, marked to return total row count when run.
  public Query includeRowCount() {
    return includeRowCount(true);
  }

  
When true, the response will include a count of the total number of rows in the table that conform to the request based on included filters. Requesting the row count will increase the time required to return a response. The default behavior is to NOT include a row count.

Parameters:
includeRowCount true if you want the results to include a count of the total number of rows in the table that conform to the request based on included filters.
Returns:
this Query.
  public Query includeRowCount(boolean includeRowCount) {
    this. = includeRowCount;
    return this;
  }

  
Begins construction of a new row filter.

Deprecated:
use field(java.lang.String)
Parameters:
field the name of the field on which to filter.
Returns:
A partial representation of the new row filter.
  public QueryBuilder<Querycriteria(String field) {
    return new QueryBuilder<Query>(thisfield);
  }

  
Begins construction of a new row filter for this Query.

Parameters:
field the name of the field on which to filter.
Returns:
A partial representation of the new row filter.
  public QueryBuilder<Queryfield(String field) {
    return new QueryBuilder<Query>(thisfield);
  }

  
Adds a filter so that results can only be (roughly) within the specified geographic circle.

Parameters:
circle The circle within which to bound the results.
Returns:
this Query.
  public Query within(Circle circle) {
    return this;
  }

  
Used to nest AND'ed predicates.
  public Query and(Query... queries) {
    return this;
  }

  
Used to nest OR'ed predicates.
  public Query or(Query... queries) {
    return this;
  }

  
Adds filter to this Query.
  public void add(Filter filter) {
    .add(filter);
  }

  
Set a parameter and value pair for specifying url parameters, specifically those not yet available as convenience methods.

Parameters:
key the field name of the parameter to add
value the field value that will be serialized using value.toString()
Returns:
this Query
  private Query addParam(String keyObject value) {
    .setParam(keyvalue);
    return this;
  }

  
Builds and returns the query string to represent this Query when talking to Factual's API. Provides proper URL encoding and escaping.

Example output:

 filters=%7B%22%24and%22%3A%5B%7B%22region%22%3A%7B%22%24in%22%3A%5B%22MA%22%2C%22VT%22%2C%22NH%22%5D%7D%7D%2C%7B%22%24or%22%3A%5B%7B%22first_name%22%3A%7B%22%24eq%22%3A%22Chun%22%7D%7D%2C%7B%22last_name%22%3A%7B%22%24eq%22%3A%22Kok%22%7D%7D%5D%7D%5D%7D
 

(After decoding, the above example would be used by the server as:)

 filters={"$and":[{"region":{"$in":["MA","VT","NH"]}},{"$or":[{"first_name":{"$eq":"Chun"}},{"last_name":{"$eq":"Kok"}}]}]}
 

Returns:
the query string to represent this Query when talking to Factual's API.
  protected Map<StringObjecttoUrlParams() {
    Parameters additional = null;
    if () {
      additional = new Parameters();
      additional.setParam(.,true);
    }
    return .toUrlParams(additional);
  }
  public String toString() {
    try {
      return URLDecoder.decode(UrlUtil.toUrlQuery(toUrlParams()), "UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
  }
  public List<FiltergetFilterList() {
    return .getFilterList();
  }
  public String toUrlQuery() {
    return UrlUtil.toUrlQuery(toUrlParams());
  }
New to GrepCode? Check out our FAQ X