Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 27, 2012, 06:53 PM   #1
iVikD
macrumors regular
 
Join Date: Sep 2011
Need help with indexing (Java or Obj-C)

Hello all, I'm trying to build a small app in either Java or Obj-C that will keep a list of movies in a .txt file to which I can add to (by means of the app) and then search that list using an index. The part I'm having trouble is with the index, as the adding and deleting methods are pretty straightforward. I was thinking of giving each movie a numeric code (0001, 0002, etc) that would just increase by 1 with each movie and use that code for searching, but I also want to be able to search by typing one or more words from the title.
For example, if I type 'war' in the search field, it should show me 'War of the worlds' and 'World at War' along with their information.
I'm really stumped on this, and while I know how to handle files in Obj-C and Java, I'm not sure how to go about this...
__________________
15" 2011 MacBook Pro, 2.3 GHz i7, 16GB RAM, 120GB SSD + 500GB HD @ 7200 rpm.
16GB iPad Air
~ 16GB + 32GB Samsung Galaxy SIV
iVikD is offline   0 Reply With Quote
Old Jun 27, 2012, 08:02 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
1. Simple way:
Read a line. Does it contain the substring (e.g. "war")? If so, add to results (e.g. an NSMutableArray or a Java List). Repeat until EOF.

2. Faster but still simple-minded way:
Read a line. Add to collection of lines. Repeat until EOF.
To search, search the collection of lines (faster than reading a file every search).

3. Complex way:
Read a line. Break into words. Add words to set (NSSet or Java Set). Add set to collection of sets, e.g. an array or list where the index of the set is its number, e.g. 001.
To search, search the sets (faster than scanning a string every time, because a set can more quickly determine presence/absence). For anything less than 10,000 movies, I doubt the speed difference would be significant.

4. More complex way:
Read a line. Break into words. Add word to dictionary, with word as key and array of indexes as value. If word is already in dictionary, append index to array of values.
To search, use the word as key to dictionary. Value is array of indexes. Each index is the number of the movie whose title contains the word.


Notice how each approach is built from simpler pieces. So it's really just a question of Breaking It Down and figuring out what each individual piece is. If an individual piece is still too complex, then break it down, too.
chown33 is offline   5 Reply With Quote
Old Jun 27, 2012, 09:09 PM   #3
iVikD
Thread Starter
macrumors regular
 
Join Date: Sep 2011
Wow, I never thought about it like that... Here I was complicating everything... Thanks a lot, I think I can get on the right track now =]
__________________
15" 2011 MacBook Pro, 2.3 GHz i7, 16GB RAM, 120GB SSD + 500GB HD @ 7200 rpm.
16GB iPad Air
~ 16GB + 32GB Samsung Galaxy SIV
iVikD is offline   0 Reply With Quote
Old Jun 27, 2012, 09:40 PM   #4
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Sounds like a job for SQL!!
jared_kipe is offline   2 Reply With Quote
Old Jun 28, 2012, 05:17 PM   #5
iVikD
Thread Starter
macrumors regular
 
Join Date: Sep 2011
Quote:
Originally Posted by jared_kipe View Post
Sounds like a job for SQL!!
Sadly, I'm not allowed to use a real database for this exercise
__________________
15" 2011 MacBook Pro, 2.3 GHz i7, 16GB RAM, 120GB SSD + 500GB HD @ 7200 rpm.
16GB iPad Air
~ 16GB + 32GB Samsung Galaxy SIV
iVikD is offline   0 Reply With Quote
Old Jul 5, 2012, 05:43 PM   #6
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Since you are doing this in Java anyway, do you want to use Lucerne/Solr?
jared_kipe is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Java 6 or Java 7 for OSX Mavericks for your Macbook Pro? Starfyre MacBook Pro 3 Dec 22, 2013 03:49 PM
Java 6.x security risk (?) vs Java 7.x and broken apps w/ v7.x installs? mgiamo Mac Basics and Help 1 Dec 15, 2013 03:48 PM
Spotlight shows as "indexing" in Mountain Lion - NOT the initial indexing c-t OS X 7 Jun 14, 2013 10:07 AM
Chrome on OS X -- Java plugin / Java 7 vs Java 6 Issue booyahbooyah Mac Applications and Mac App Store 4 May 31, 2013 09:13 AM
Installed Java 7.07 but doesn't show up in Java preferences? -mattias- OS X 10.8 Mountain Lion 21 Aug 31, 2012 04:49 PM

Forum Jump

All times are GMT -5. The time now is 12:56 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC