Skip to content

Commit df6a7a7

Browse files
author
Karl Seguin
committed
adding tag search
1 parent 4e3fceb commit df6a7a7

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

app/controllers/BaseController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public class BaseController extends Controller {
1818
gsonBuilder.registerTypeAdapter(PagedResult.class, new PagedResultGsonAdapter());
1919
}
2020

21+
@Before
22+
//load the user for the view
23+
private static void loadUser() {
24+
if (session.get("uid") == null) { return; }
25+
renderArgs.put("user", User.findById(session.get("uid")));
26+
}
27+
2128
@Util
2229
protected static void signin(User user) {
2330
session.put("uid", user.getId());

app/controllers/Meetups.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import utils.*;
44
import models.*;
5+
import java.util.*;
56
import play.mvc.Util;
67
import play.mvc.Before;
78
import org.bson.types.ObjectId;
@@ -60,8 +61,8 @@ public static void findRecent(int page) {
6061
renderJSON(Recent.find(page));
6162
}
6263

63-
public static void find(float x, float y) {
64-
renderJSON(Meetup.find(x, y));
64+
public static void find(float x, float y, Set<String> tags) {
65+
renderJSON(Meetup.find(x, y, tags));
6566
}
6667

6768
@Util

app/jobs/Bootstrap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class Bootstrap extends Job {
99
public void doJob() {
1010
MorphiaPlugin.ds().ensureCaps();
11-
DBObject object = BasicDBObjectBuilder.start().add("coordinates", "2d").add("date", 1).get();
11+
DBObject object = BasicDBObjectBuilder.start().add("coordinates", "2d").add("date", 1).add("tags", 1).get();
1212
MorphiaPlugin.ds().getCollection(models.Meetup.class).ensureIndex(object);
1313
}
1414
}

app/models/Meetup.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ public class Meetup extends Model {
4040
@MaxListSize(value=5, message="Can't have more than 5") @MaxListItemSize(value=15, message="A tag should be less than 15 characters")
4141
public Set<String> tags;
4242

43-
public static List<Meetup> find(float x, float y) {
43+
public static List<Meetup> find(float x, float y, Set<String> tags) {
4444
Query<Meetup> query = ds().createQuery(Meetup.class).field("coordinates").near(x, y).field("date").greaterThanOrEq(new Date()).limit(200);
45+
if (tags != null && !tags.isEmpty()) {
46+
query.field("tags").in(tags);
47+
}
4548
return query.asList();
4649
}
4750

0 commit comments

Comments
 (0)