Пример #1
0
  /**
   * Create a query based on the query string and the templates.
   *
   * @param query A free text query string
   * @param templates The parsers picks out key:value strings and uses the templates to replace them
   */
  @Override
  public Cursor<T> query(String q, Map<String, String> templates) throws Exception {
    assert q != null;
    String parts[] = q.split("\\s+");
    Search positive = new Search();
    Search negative = new Search();

    for (String p : parts) {
      Matcher m = QUERY.matcher(p);
      if (templates != null && m.matches()) {
        boolean neg = m.group(1) != null;
        String key = m.group(2);
        String type = templates.get(key);

        if (type != null) {
          type += "=%s";
          String word = m.group(3);
          if (neg) where("!(" + type + ")", word);
          else where(type, word);
        }
      } else {
        if (p.startsWith("-")) negative.addAll(p);
        else positive.addAll(p);
      }
    }
    for (String key : positive.set()) {
      where("__keywords=%s", key);
    }
    for (String key : negative.set()) {
      where("(!(__keywords=%s)", key);
    }
    return this;
  }
Пример #2
0
  /** Index the text and set the keywords field with the tokenized texts. */
  @Override
  public Cursor<T> word(String word) throws Exception {
    Search search = new Search();
    search.add(word);
    for (String s : search.set()) append("__keywords", s);

    return this;
  }
Пример #3
0
  /** Index the text and set the keywords field with the tokenized texts. */
  @Override
  public Cursor<T> text(String text) throws Exception {
    Search search = new Search();
    search.addAll(text);
    appendAll("__keywords", search.set());

    return this;
  }