Example usage for com.mongodb.client.model Filters text

List of usage examples for com.mongodb.client.model Filters text

Introduction

In this page you can find the example usage for com.mongodb.client.model Filters text.

Prototype

public static Bson text(final String search) 

Source Link

Document

Creates a filter that matches all documents matching the given search term.

Usage

From source file:be.nille.blog.mongo.post.MongoPostService.java

@Override
public List<Post> fullTextPostSearch(String searchValue) {
    return getPostsByIterable(collection.find(Filters.text(searchValue)));
}

From source file:codeu.chat.database.Database.java

License:Apache License

public Collection<User> findUser(String identifier) {
    try {//from ww w  . j  av a2s  .c o m
        List<User> foundUsers = new ArrayList<User>();
        Iterable<Document> foundDocs = users.find(Filters.text(identifier));

        for (Document doc : foundDocs) {
            foundUsers.add(Packer.unpackUser(doc));
        }
        return foundUsers;
    } catch (MongoQueryException e) {
        return new ArrayList<User>();
    }
}

From source file:codeu.chat.database.Database.java

License:Apache License

public Collection<Message> findMessage(String identifier) {
    try {//from   www.j  av  a2  s  .  com
        Iterable<Document> foundDocs = messages.find(Filters.text(identifier));
        List<Message> foundMessages = new ArrayList<Message>();

        for (Document doc : foundDocs) {
            foundMessages.add(Packer.unpackMessage(doc));
        }
        return foundMessages;
    } catch (MongoQueryException e) {
        return new ArrayList<Message>();
    }
}

From source file:codeu.chat.database.Database.java

License:Apache License

public Collection<Conversation> findConversation(String identifier) {
    try {/* w w  w  .  ja  va 2s  . c  o  m*/
        Iterable<Document> foundDocs = conversations.find(Filters.text(identifier));
        List<Conversation> foundConversations = new ArrayList<Conversation>();

        for (Document doc : foundDocs) {
            foundConversations.add(Packer.unpackConversation(doc));
        }
        return foundConversations;
    } catch (MongoQueryException e) {
        return new ArrayList<Conversation>();
    }
}

From source file:io.lumeer.storage.mongodb.util.MongoFilters.java

License:Open Source License

public static Bson suggestionsFilter(SuggestionQuery query) {
    return Filters.and(Filters.text(query.getText()), MongoFilters.permissionsFilter(query));
}

From source file:it.av.fac.webserver.handlers.WikiPageFetcher.java

/**
 * TODO: Add more query functionalities.
 *
 * @param query// www  .j av  a  2s.  c om
 * @return
 */
public JSONArray search(String query) {
    JSONArray ret = new JSONArray();

    FindIterable<Document> documents = this.collection.find(Filters.text(query));
    documents.forEach(new Consumer<Document>() {
        @Override
        public void accept(Document doc) {
            ret.put(new JSONObject(doc.toJson()));
        }
    });

    return ret;
}

From source file:org.opencb.cellbase.lib.impl.ClinicalMongoDBAdaptor.java

License:Apache License

private void createPhenotypeQuery(Query query, List<Bson> andBsonList) {
    if (query != null && query.getString(QueryParams.PHENOTYPE.key()) != null
            && !query.getString(QueryParams.PHENOTYPE.key()).isEmpty()) {
        andBsonList.add(Filters.text(query.getString(QueryParams.PHENOTYPE.key())));
    }/*w  w  w.java 2 s  .  c  o  m*/
}

From source file:org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.java

License:Apache License

public static <T> Bson createFilter(String mongoDbField, T queryValue, ComparisonOperator comparator) {
    Bson filter = null;/*from w  w w  .j  ava2  s  . c om*/

    if (queryValue != null) {
        if (queryValue instanceof String) {
            switch (comparator) {
            case EQUALS:
                filter = Filters.eq(mongoDbField, queryValue);
                break;
            case NOT_EQUALS:
                filter = Filters.ne(mongoDbField, queryValue);
                break;
            case EQUAL_IGNORE_CASE:
                filter = Filters.regex(mongoDbField, queryValue.toString(), "i");
                break;
            case STARTS_WITH:
                filter = Filters.regex(mongoDbField, "^" + queryValue + "*");
                break;
            case ENDS_WITH:
                filter = Filters.regex(mongoDbField, "*" + queryValue + "$");
                break;
            case REGEX:
                filter = Filters.regex(mongoDbField, queryValue.toString());
                break;
            case TEXT:
                filter = Filters.text(String.valueOf(queryValue));
                break;
            default:
                break;
            }
        } else {
            switch (comparator) {
            case EQUALS:
                filter = Filters.eq(mongoDbField, queryValue);
                break;
            case NOT_EQUALS:
                filter = Filters.ne(mongoDbField, queryValue);
                break;
            case GREATER_THAN:
                filter = Filters.gt(mongoDbField, queryValue);
                break;
            case GREATER_THAN_EQUAL:
                filter = Filters.gte(mongoDbField, queryValue);
                break;
            case LESS_THAN:
                filter = Filters.lt(mongoDbField, queryValue);
                break;
            case LESS_THAN_EQUAL:
                filter = Filters.lte(mongoDbField, queryValue);
                break;
            default:
                break;
            }
        }
    }
    return filter;
}