All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.dse.graph.api.predicates.Search Maven / Gradle / Ivy

/*
 * Copyright DataStax, Inc.
 *
 * This software can be used solely with DataStax Enterprise. Please consult the license at
 * http://www.datastax.com/terms/datastax-dse-driver-license-terms
 */
package com.datastax.dse.graph.api.predicates;

import com.datastax.dse.graph.internal.EditDistance;
import com.datastax.dse.graph.internal.SearchPredicate;
import org.apache.tinkerpop.gremlin.process.traversal.P;

public class Search {

  /**
   * Search any instance of a certain token within the text property targeted (case insensitive).
   *
   * @param value the token to look for.
   * @return a predicate to apply in a {@link
   *     org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}.
   */
  public static P token(String value) {
    return new P<>(SearchPredicate.token, value);
  }

  /**
   * Search any instance of a certain token prefix within the text property targeted (case
   * insensitive).
   *
   * @param value the token to look for.
   * @return a predicate to apply in a {@link
   *     org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}.
   */
  public static P tokenPrefix(String value) {
    return new P<>(SearchPredicate.tokenPrefix, value);
  }

  /**
   * Search any instance of the provided regular expression for the targeted property (case
   * insensitive).
   *
   * @param value the token to look for.
   * @return a predicate to apply in a {@link
   *     org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}.
   */
  public static P tokenRegex(String value) {
    return new P<>(SearchPredicate.tokenRegex, value);
  }

  /**
   * Search for a specific prefix at the beginning of the text property targeted (case sensitive).
   *
   * @param value the value to look for.
   * @return a predicate to apply in a {@link
   *     org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}.
   */
  public static P prefix(String value) {
    return new P<>(SearchPredicate.prefix, value);
  }

  /**
   * Search for this regular expression inside the text property targeted (case sensitive).
   *
   * @param value the value to look for.
   * @return a predicate to apply in a {@link
   *     org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}.
   */
  public static P regex(String value) {
    return new P<>(SearchPredicate.regex, value);
  }

  /**
   * Supports finding words which are a within a specific distance away (case insensitive).
   *
   * 

Example: the search expression is {@code phrase("Hello world", 2)} * *

    *
  • the inserted value "Hello world" is found *
  • the inserted value "Hello wild world" is found *
  • the inserted value "Hello big wild world" is found *
  • the inserted value "Hello the big wild world" is not found *
  • the inserted value "Goodbye world" is not found. *
* * @param query the string to look for in the value * @param distance the number of terms allowed between two correct terms to find a value. * @return a predicate to apply in a {@link * org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}. */ public static P phrase(String query, int distance) { return new P<>(SearchPredicate.phrase, new EditDistance(query, distance)); } /** * Supports fuzzy searches based on the Damerau-Levenshtein Distance, or Edit Distance algorithm * (case sensitive). * *

Example: the search expression is {@code fuzzy("david", 1)} * *

    *
  • the inserted value "david" is found *
  • the inserted value "dawid" is found *
  • the inserted value "davids" is found *
  • the inserted value "dewid" is not found *
* * @param query the string to look for in the value * @param distance the number of "uncertainties" allowed for the Leveinshtein algorithm. * @return a predicate to apply in a {@link * org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}. */ public static P fuzzy(String query, int distance) { return new P<>(SearchPredicate.fuzzy, new EditDistance(query, distance)); } /** * Supports fuzzy searches based on the Damerau-Levenshtein Distance, or Edit Distance algorithm * after having tokenized the data stored (case insensitive). * *

Example: the search expression is {@code tokenFuzzy("david", 1)} * *

    *
  • the inserted value "david" is found *
  • the inserted value "dawid" is found *
  • the inserted value "hello-dawid" is found *
  • the inserted value "dewid" is not found *
* * @param query the string to look for in the value * @param distance the number of "uncertainties" allowed for the Leveinshtein algorithm. * @return a predicate to apply in a {@link * org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal}. */ public static P tokenFuzzy(String query, int distance) { return new P<>(SearchPredicate.tokenFuzzy, new EditDistance(query, distance)); } }