This is my code:
for (String term : segment.terms) {
DBObject clause1 = new BasicDBObject("linkTitles", java.util.regex.Pattern.compile(term));
or.add(clause1);
}
DBObject mongoQuery = new BasicDBObject("$and", or);
DBCursor cursor = pageLinks.find(mongoQuery);
The problem with this is that if for example the term is "obama", it wil lgive me objects that has linkTitles like "meprobamate". I want to give a regular expression that only gives me "obama" as a whole word in any situation like " obama ", " obama." " obama, "
, etc.
In all of the cases "obama" might be between spaces or any punctuation, how can I say in java code for the mongo db regex to consider any punctuation letter or space around the term?