Interface Search

  • All Known Implementing Classes:
    MockSearch

    public interface Search
    The core search interface. Does indexing and searching for all domain objects.
    Author:
    Alex Bogdanovski [alex@erudika.com]
    • Method Detail

      • index

        void index​(ParaObject po)
        Indexes an object. Only fields marked with Stored are indexed.
        Parameters:
        po - the domain object the object to index
      • index

        void index​(String appid,
                   ParaObject po)
        Indexes an object. Only fields marked with Stored are indexed.
        Parameters:
        appid - name of the App
        po - the domain object
      • unindex

        void unindex​(ParaObject po)
        Removes an object from the index.
        Parameters:
        po - the domain object
      • unindex

        void unindex​(String appid,
                     ParaObject po)
        Removes an object from the index.
        Parameters:
        appid - name of the App
        po - the domain object
      • indexAll

        <P extends ParaObject> void indexAll​(List<P> objects)
        Indexes multiple objects in a batch operation.
        Type Parameters:
        P - type of the object
        Parameters:
        objects - a list of objects
      • indexAll

        <P extends ParaObject> void indexAll​(String appid,
                                             List<P> objects)
        Indexes multiple objects in a batch operation.
        Type Parameters:
        P - type of the object
        Parameters:
        appid - name of the App
        objects - a list of objects
      • unindexAll

        <P extends ParaObject> void unindexAll​(List<P> objects)
        Removes multiple objects from the index in a batch operation.
        Type Parameters:
        P - type of the object
        Parameters:
        objects - a list of objects
      • unindexAll

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

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

        void unindexAll​(String appid,
                        Map<String,​?> terms,
                        boolean matchAll)
        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.
        Parameters:
        appid - name of the App
        matchAll - if true all terms must match ('AND' operation)
        terms - a list of terms
      • findById

        <P extends ParaObject> P findById​(String id)
        Simple id search.
        Type Parameters:
        P - type of the object
        Parameters:
        id - the id
        Returns:
        the object if found or null
      • findById

        <P extends ParaObject> P findById​(String appid,
                                          String id)
        Simple id 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

        <P extends ParaObjectList<P> findByIds​(List<String> ids)
        Simple multi id 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

        <P extends ParaObjectList<P> findByIds​(String appid,
                                                 List<String> ids)
        Simple multi id 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

        <P extends ParaObjectList<P> findNearby​(String type,
                                                  String query,
                                                  int radius,
                                                  double lat,
                                                  double lng,
                                                  Pager... pager)
        Search for Address objects in a radius of X km from a given point.
        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

        <P extends ParaObjectList<P> findNearby​(String appid,
                                                  String type,
                                                  String query,
                                                  int radius,
                                                  double lat,
                                                  double lng,
                                                  Pager... pager)
        Search for Address objects in a radius of X km from a given point.
        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

        <P extends ParaObjectList<P> findPrefix​(String type,
                                                  String field,
                                                  String prefix,
                                                  Pager... pager)
        Searches for objects that have a property which value starts with a given prefix.
        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

        <P extends ParaObjectList<P> findPrefix​(String appid,
                                                  String type,
                                                  String field,
                                                  String prefix,
                                                  Pager... pager)
        Searches for objects that have a property which value starts with a given prefix.
        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

        <P extends ParaObjectList<P> findQuery​(String type,
                                                 String query,
                                                 Pager... pager)
        Query string search. This is the basic search method. Refer to the Lucene query string syntax.
        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

        <P extends ParaObjectList<P> findQuery​(String appid,
                                                 String type,
                                                 String query,
                                                 Pager... pager)
        Query string search. This is the basic search method. Refer to the Lucene query string syntax.
        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

        <P extends ParaObjectList<P> findNestedQuery​(String type,
                                                       String field,
                                                       String query,
                                                       Pager... pager)
        Searches within a nested field. The objects of the given type must contain a nested field "nstd".
        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

        <P extends ParaObjectList<P> findNestedQuery​(String appid,
                                                       String type,
                                                       String field,
                                                       String query,
                                                       Pager... pager)
        Searches within a nested field. The objects of the given type must contain a nested field "nstd".
        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

        <P extends ParaObjectList<P> findSimilar​(String type,
                                                   String filterKey,
                                                   String[] fields,
                                                   String liketext,
                                                   Pager... pager)
        Searches for objects that have similar property values to a given text. A "find like this" query.
        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

        <P extends ParaObjectList<P> findSimilar​(String appid,
                                                   String type,
                                                   String filterKey,
                                                   String[] fields,
                                                   String liketext,
                                                   Pager... pager)
        Searches for objects that have similar property values to a given text. A "find like this" query.
        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

        <P extends ParaObjectList<P> findTagged​(String type,
                                                  String[] tags,
                                                  Pager... pager)
        Searches for objects tagged with one or more tags.
        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

        <P extends ParaObjectList<P> findTagged​(String appid,
                                                  String type,
                                                  String[] tags,
                                                  Pager... pager)
        Searches for objects tagged with one or more tags.
        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

        <P extends ParaObjectList<P> findTags​(String keyword,
                                                Pager... pager)
        Searches for Tag objects. This method might be deprecated in the future.
        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

        <P extends ParaObjectList<P> findTags​(String appid,
                                                String keyword,
                                                Pager... pager)
        Searches for Tag objects. This method might be deprecated in the future.
        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

        <P extends ParaObjectList<P> findTermInList​(String type,
                                                      String field,
                                                      List<?> terms,
                                                      Pager... pager)
        Searches for objects having a property value that is in list of possible values.
        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

        <P extends ParaObjectList<P> findTermInList​(String appid,
                                                      String type,
                                                      String field,
                                                      List<?> terms,
                                                      Pager... pager)
        Searches for objects having a property value that is in list of possible values.
        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

        <P extends ParaObjectList<P> findTerms​(String type,
                                                 Map<String,​?> terms,
                                                 boolean matchAll,
                                                 Pager... pager)
        Searches for objects that have properties matching some given values. A terms query.
        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

        <P extends ParaObjectList<P> findTerms​(String appid,
                                                 String type,
                                                 Map<String,​?> terms,
                                                 boolean matchAll,
                                                 Pager... pager)
        Searches for objects that have properties matching some given values. A terms query.
        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

        <P extends ParaObjectList<P> findWildcard​(String type,
                                                    String field,
                                                    String wildcard,
                                                    Pager... pager)
        Searches for objects that have a property with a value matching a wildcard query.
        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

        <P extends ParaObjectList<P> findWildcard​(String appid,
                                                    String type,
                                                    String field,
                                                    String wildcard,
                                                    Pager... pager)
        Searches for objects that have a property with a value matching a wildcard query.
        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

        Long getCount​(String type)
        Counts indexed objects.
        Parameters:
        type - the type of object to search for. See ParaObject.getType()
        Returns:
        the number of results found
      • getCount

        Long getCount​(String appid,
                      String type)
        Counts indexed objects.
        Parameters:
        appid - name of the App
        type - the type of object to search for. See ParaObject.getType()
        Returns:
        the number of results found
      • getCount

        Long getCount​(String type,
                      Map<String,​?> terms)
        Counts indexed objects matching a set of terms/values.
        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

        Long getCount​(String appid,
                      String type,
                      Map<String,​?> terms)
        Counts indexed objects matching a set of terms/values.
        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

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

        boolean rebuildIndex​(DAO dao,
                             App app,
                             String destinationIndex,
                             Pager... pager)
        Reads all objects from the database and indexes them into a new index. Old index is usually deleted.
        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

        boolean isValidQueryString​(String queryString)
        Validates a query string.
        Parameters:
        queryString - a query string
        Returns:
        true if query is valid
      • createIndex

        default void createIndex​(App app)
        Creates a new search index for the given app.
        Parameters:
        app - an App object
      • deleteIndex

        default void deleteIndex​(App app)
        Deletes the search index for a given app.
        Parameters:
        app - an App object