Research Log of Web Science Students

Computer Science is not simply programming

Add/Remove modules and Problems with pagination

leave a comment »

Today I was able to finish adding and removing modules in the search function.

It’s already done albeit not very aesthetically pleasing. When a user adds a module a full page load occurs sending him/her back to the top of the page. But what if the module you just added was at the bottom? Each page consists of 10 search results. I had to do away with the GWT solution in favor of just finishing the function. I remember what Sir Rom told me before, “Client side is always nice to have”.

So I moved to pagination and I am finding it really tricky. First I found myself with a seemingly impossible query.

public class Module {
  private String tags[];

I wanted to make a search function that will query all Module entities and return all instance whose tags attribute matches the search query entered by the user.

So if a user was searching for a module tagged as “Football”, how should I construct a query that would search for a module entity with a String “Football” in its tags array/attribute?

I made a hack first:

List<Module> modules = (List<Module>) pm.detachCopyAll((List<Module>) query.execute());
List<Module> search_results = new ArrayList<Module>();
for (Module module:modules){
   String module_tags[] = module.getTags();
   for (int i=0;i<module_tags.length;i++){
   if (module_tags[i].equals(tag)){

I would retrieve all modules and programmatically see if their tags array had the tag the user was searching for. Very crude eh? And not optimized. This is I think O(n^2).

Fortunately someone told me a better way!

But my pagination code still doesn’t work even if it were this easy:

Long lower_bound = pageNumber*10-10;
Long upper_bound = pageNumber*10;
query.setRange(lower_bound, upper_bound);
List<Module> modules = (List<Module>) pm.detachCopyAll((List<Module>) query.execute());

Must add more tests to my unit test for this POJO.

At the same time though I have already started on the My Bookmarked Modules function of the Modules feature and from there I can already integrate ( or redo because the code is UNMAINTABLE? 😦 ) with the
project feature I did before.


Written by Jose Asuncion

December 21, 2009 at 4:26 pm

Posted in Hardwire

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: