Class MockSearch

java.lang.Object
com.erudika.para.core.search.MockSearch
All Implemented Interfaces:
Search

@Singleton public class MockSearch extends Object implements Search
Author:
Alex Bogdanovski [[email protected]]
  • Constructor Details

    • MockSearch

      public MockSearch()
  • Method Details

    • index

      public void index(ParaObject po)
      Description copied from interface: Search
      Indexes an object. Only fields marked with Stored are indexed.
      Specified by:
      index in interface Search
      Parameters:
      po - the domain object the object to index
    • index

      public void index(String appid, ParaObject po)
      Description copied from interface: Search
      Indexes an object. Only fields marked with Stored are indexed.
      Specified by:
      index in interface Search
      Parameters:
      appid - name of the App
      po - the domain object
    • unindex

      public void unindex(ParaObject po)
      Description copied from interface: Search
      Removes an object from the index.
      Specified by:
      unindex in interface Search
      Parameters:
      po - the domain object
    • unindex

      public void unindex(String appid, ParaObject po)
      Description copied from interface: Search
      Removes an object from the index.
      Specified by:
      unindex in interface Search
      Parameters:
      appid - name of the App
      po - the domain object
    • indexAll

      public <P extends ParaObject> void indexAll(List<P> objects)
      Description copied from interface: Search
      Indexes multiple objects in a batch operation.
      Specified by:
      indexAll in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      objects - a list of objects
    • indexAll

      public <P extends ParaObject> void indexAll(String appid, List<P> objects)
      Description copied from interface: Search
      Indexes multiple objects in a batch operation.
      Specified by:
      indexAll in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      objects - a list of objects
    • unindexAll

      public <P extends ParaObject> void unindexAll(List<P> objects)
      Description copied from interface: Search
      Removes multiple objects from the index in a batch operation.
      Specified by:
      unindexAll in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      objects - a list of objects
    • unindexAll

      public <P extends ParaObject> void unindexAll(String appid, List<P> objects)
      Description copied from interface: Search
      Removes multiple objects from the index in a batch operation.
      Specified by:
      unindexAll in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      objects - a list of objects
    • unindexAll

      public void unindexAll(Map<String,?> terms, boolean matchAll)
      Description copied from interface: Search
      Removes multiple objects from the index matching a set of terms.
      Specified by:
      unindexAll in interface Search
      Parameters:
      terms - a list of terms
      matchAll - if true all terms must match ('AND' operation)
    • unindexAll

      public void unindexAll(String appid, Map<String,?> terms, boolean matchAll)
      Description copied from interface: Search
      Removes multiple objects from the index matching a set of terms. If the terms parameter is empty or null, all objects should be removed from index.
      Specified by:
      unindexAll in interface Search
      Parameters:
      appid - name of the App
      terms - a list of terms
      matchAll - if true all terms must match ('AND' operation)
    • findById

      public <P extends ParaObject> P findById(String id)
      Description copied from interface: Search
      Simple id search.
      Specified by:
      findById in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      id - the id
      Returns:
      the object if found or null
    • findById

      public <P extends ParaObject> P findById(String appid, String id)
      Description copied from interface: Search
      Simple id search.
      Specified by:
      findById in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      id - the id
      Returns:
      the object if found or null
    • findByIds

      public <P extends ParaObject> List<P> findByIds(List<String> ids)
      Description copied from interface: Search
      Simple multi id search.
      Specified by:
      findByIds in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      ids - a list of ids to search for
      Returns:
      the object if found or null
    • findByIds

      public <P extends ParaObject> List<P> findByIds(String appid, List<String> ids)
      Description copied from interface: Search
      Simple multi id search.
      Specified by:
      findByIds in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      ids - a list of ids to search for
      Returns:
      the object if found or null
    • findNearby

      public <P extends ParaObject> List<P> findNearby(String type, String query, int radius, double lat, double lng, Pager... pager)
      Description copied from interface: Search
      Search for Address objects in a radius of X km from a given point.
      Specified by:
      findNearby in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      query - the query string
      radius - the radius of the search circle
      lat - latitude
      lng - longitude
      pager - a Pager
      Returns:
      a list of objects found
    • findNearby

      public <P extends ParaObject> List<P> findNearby(String appid, String type, String query, int radius, double lat, double lng, Pager... pager)
      Description copied from interface: Search
      Search for Address objects in a radius of X km from a given point.
      Specified by:
      findNearby in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      query - the query string
      radius - the radius of the search circle
      lat - latitude
      lng - longitude
      pager - a Pager
      Returns:
      a list of objects found
    • findPrefix

      public <P extends ParaObject> List<P> findPrefix(String type, String field, String prefix, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have a property which value starts with a given prefix.
      Specified by:
      findPrefix in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      field - the property name of an object
      prefix - the prefix
      pager - a Pager
      Returns:
      a list of objects found
    • findPrefix

      public <P extends ParaObject> List<P> findPrefix(String appid, String type, String field, String prefix, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have a property which value starts with a given prefix.
      Specified by:
      findPrefix in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      field - the property name of an object
      prefix - the prefix
      pager - a Pager
      Returns:
      a list of objects found
    • findQuery

      public <P extends ParaObject> List<P> findQuery(String type, String query, Pager... pager)
      Description copied from interface: Search
      Query string search. This is the basic search method. Refer to the Lucene query string syntax.
      Specified by:
      findQuery in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      query - the query string
      pager - a Pager
      Returns:
      a list of objects found
    • findQuery

      public <P extends ParaObject> List<P> findQuery(String appid, String type, String query, Pager... pager)
      Description copied from interface: Search
      Query string search. This is the basic search method. Refer to the Lucene query string syntax.
      Specified by:
      findQuery in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      query - the query string
      pager - a Pager
      Returns:
      a list of objects found
    • findNestedQuery

      public <P extends ParaObject> List<P> findNestedQuery(String type, String field, String query, Pager... pager)
      Description copied from interface: Search
      Searches within a nested field. The objects of the given type must contain a nested field "nstd".
      Specified by:
      findNestedQuery in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      field - the name of the field to target (within a nested field "nstd")
      query - query string
      pager - a Pager
      Returns:
      list of objects found
    • findNestedQuery

      public <P extends ParaObject> List<P> findNestedQuery(String appid, String type, String field, String query, Pager... pager)
      Description copied from interface: Search
      Searches within a nested field. The objects of the given type must contain a nested field "nstd".
      Specified by:
      findNestedQuery in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      field - the name of the field to target (within a nested field "nstd")
      query - query string
      pager - a Pager
      Returns:
      list of objects found
    • findSimilar

      public <P extends ParaObject> List<P> findSimilar(String type, String filterKey, String[] fields, String liketext, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have similar property values to a given text. A "find like this" query.
      Specified by:
      findSimilar in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      filterKey - exclude an object with this key from the results (optional)
      fields - a list of property names
      liketext - text to compare to
      pager - a Pager
      Returns:
      a list of objects found
    • findSimilar

      public <P extends ParaObject> List<P> findSimilar(String appid, String type, String filterKey, String[] fields, String liketext, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have similar property values to a given text. A "find like this" query.
      Specified by:
      findSimilar in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      filterKey - exclude an object with this key from the results (optional)
      fields - a list of property names
      liketext - text to compare to
      pager - a Pager
      Returns:
      a list of objects found
    • findTagged

      public <P extends ParaObject> List<P> findTagged(String type, String[] tags, Pager... pager)
      Description copied from interface: Search
      Searches for objects tagged with one or more tags.
      Specified by:
      findTagged in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      tags - the list of tags
      pager - a Pager
      Returns:
      a list of objects found
    • findTagged

      public <P extends ParaObject> List<P> findTagged(String appid, String type, String[] tags, Pager... pager)
      Description copied from interface: Search
      Searches for objects tagged with one or more tags.
      Specified by:
      findTagged in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      tags - the list of tags
      pager - a Pager
      Returns:
      a list of objects found
    • findTags

      public <P extends ParaObject> List<P> findTags(String keyword, Pager... pager)
      Description copied from interface: Search
      Searches for Tag objects. This method might be deprecated in the future.
      Specified by:
      findTags in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      keyword - the tag keyword to search for
      pager - a Pager
      Returns:
      a list of objects found
    • findTags

      public <P extends ParaObject> List<P> findTags(String appid, String keyword, Pager... pager)
      Description copied from interface: Search
      Searches for Tag objects. This method might be deprecated in the future.
      Specified by:
      findTags in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      keyword - the tag keyword to search for
      pager - a Pager
      Returns:
      a list of objects found
    • findTermInList

      public <P extends ParaObject> List<P> findTermInList(String type, String field, List<?> terms, Pager... pager)
      Description copied from interface: Search
      Searches for objects having a property value that is in list of possible values.
      Specified by:
      findTermInList in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      field - the property name of an object
      terms - a list of terms (property values)
      pager - a Pager
      Returns:
      a list of objects found
    • findTermInList

      public <P extends ParaObject> List<P> findTermInList(String appid, String type, String field, List<?> terms, Pager... pager)
      Description copied from interface: Search
      Searches for objects having a property value that is in list of possible values.
      Specified by:
      findTermInList in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      field - the property name of an object
      terms - a list of terms (property values)
      pager - a Pager
      Returns:
      a list of objects found
    • findTerms

      public <P extends ParaObject> List<P> findTerms(String type, Map<String,?> terms, boolean matchAll, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have properties matching some given values. A terms query.
      Specified by:
      findTerms in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      terms - a map of fields (property names) to terms (property values)
      matchAll - match all terms. If true - AND search, if false - OR search
      pager - a Pager
      Returns:
      a list of objects found
    • findTerms

      public <P extends ParaObject> List<P> findTerms(String appid, String type, Map<String,?> terms, boolean matchAll, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have properties matching some given values. A terms query.
      Specified by:
      findTerms in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      terms - a map of fields (property names) to terms (property values)
      matchAll - match all terms. If true - AND search, if false - OR search
      pager - a Pager
      Returns:
      a list of objects found
    • findWildcard

      public <P extends ParaObject> List<P> findWildcard(String type, String field, String wildcard, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have a property with a value matching a wildcard query.
      Specified by:
      findWildcard in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      field - the property name of an object
      wildcard - wildcard query string. For example "cat*".
      pager - a Pager
      Returns:
      a list of objects found
    • findWildcard

      public <P extends ParaObject> List<P> findWildcard(String appid, String type, String field, String wildcard, Pager... pager)
      Description copied from interface: Search
      Searches for objects that have a property with a value matching a wildcard query.
      Specified by:
      findWildcard in interface Search
      Type Parameters:
      P - type of the object
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      field - the property name of an object
      wildcard - wildcard query string. For example "cat*".
      pager - a Pager
      Returns:
      a list of objects found
    • getCount

      public Long getCount(String type)
      Description copied from interface: Search
      Counts indexed objects.
      Specified by:
      getCount in interface Search
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      Returns:
      the number of results found
    • getCount

      public Long getCount(String appid, String type)
      Description copied from interface: Search
      Counts indexed objects.
      Specified by:
      getCount in interface Search
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      Returns:
      the number of results found
    • getCount

      public Long getCount(String type, Map<String,?> terms)
      Description copied from interface: Search
      Counts indexed objects matching a set of terms/values.
      Specified by:
      getCount in interface Search
      Parameters:
      type - the type of object to search for. See ParaObject.getType()
      terms - a list of terms (property values)
      Returns:
      the number of results found
    • getCount

      public Long getCount(String appid, String type, Map<String,?> terms)
      Description copied from interface: Search
      Counts indexed objects matching a set of terms/values.
      Specified by:
      getCount in interface Search
      Parameters:
      appid - name of the App
      type - the type of object to search for. See ParaObject.getType()
      terms - a map of fields (property names) to terms (property values)
      Returns:
      the number of results found
    • rebuildIndex

      public boolean rebuildIndex(DAO dao, App app, Pager... pager)
      Description copied from interface: Search
      Reads all objects from the database and indexes them into a new index. Old index is usually deleted.
      Specified by:
      rebuildIndex in interface Search
      Parameters:
      dao - a DAO implementation
      app - an App object
      pager - a Pager object
      Returns:
      true if operation was successful
    • rebuildIndex

      public boolean rebuildIndex(DAO dao, App app, String destinationIndex, Pager... pager)
      Description copied from interface: Search
      Reads all objects from the database and indexes them into a new index. Old index is usually deleted.
      Specified by:
      rebuildIndex in interface Search
      Parameters:
      dao - a DAO implementation
      app - an App object
      destinationIndex - the name of an existing index where data will be reindexed to
      pager - a Pager object
      Returns:
      true if operation was successful
    • isValidQueryString

      public boolean isValidQueryString(String queryString)
      Description copied from interface: Search
      Validates a query string.
      Specified by:
      isValidQueryString in interface Search
      Parameters:
      queryString - a query string
      Returns:
      true if query is valid