Search bars

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Whytey
Posts: 31
Joined: Fri Jan 10, 2014 6:40 pm

Search bars

Post by Whytey » Fri Jan 10, 2014 6:44 pm

Hi I'm new to livecode and would like to add a search bar to a card that will allow me to search a specific online database, is this possible and if so how would I go about this?

Look forward to hearing your responses! Thanks!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Search bars

Post by Mark » Sat Jan 11, 2014 2:06 am

Hi,

For now, I would forget about "search bar" and concentrate on writing a script that connects to the database and retrieves the required data.

What can you tell us about the database? Do you have a link? Do you own the server where the database is located? What types of access to the database are available?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Contact:

Re: Search bars

Post by splash21 » Sat Jan 11, 2014 12:54 pm

Hi, Whytey. Do you want to search an existing online database? Here's an example that searches these forums. Simply create a new stack and add a text entry field (the single line field) and a scrolling field (the multiline field). Change the names of the fields to "Search" and "Results" respectively.

Now put the following code into the "Search" field;

Code: Select all

on enterinField
   searchForums
end enterinField

on returnInField
   searchForums
end returnInField

command searchForums
   set the htmlText of field "Results" to URL ("http://forums.runrev.com/search.php?keywords=" & urlEncode(the text of me))
end searchForums
Now type something into the search field, press 'enter' or 'return' and the results are put into the results field. Just a simple example of how to start building a search bar, but hopefully this will help ;)
LiveCode Development & Training : http://splash21.com

Whytey
Posts: 31
Joined: Fri Jan 10, 2014 6:40 pm

Re: Search bars

Post by Whytey » Sat Jan 11, 2014 7:39 pm

Wow thank you so much for these really helpful answers I will definitely give this a go I have just generated a simple app that works really well but I really have zero coding ability so just stumbling through livecode as I go! For this new idea, the database I want to link to is pubmed, a database where all scientific papers are stored. Each paper published has summaries/abstracts, I would like to retrieve the abstracts from the first five entries and put them into five text boxes. Does that make sense?

Whytey
Posts: 31
Joined: Fri Jan 10, 2014 6:40 pm

Re: Search bars

Post by Whytey » Sat Jan 11, 2014 8:29 pm

Hi Splash21, I've just tried your suggestion, the code works brilliantly but with the pubmed url I get an error. On pubmed the first page is a search engine like google where you enter text to search the database do I need something in the code that says copy the text into pubmed's search engine first then bring down the results?

Thanks for your help, this is brilliant!

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Contact:

Re: Search bars

Post by splash21 » Sat Jan 11, 2014 9:13 pm

You need to do a little research. For this forum, I right clicked on the search box and selected 'Inspect element' (I'm using Chrome) to find the name of the search box. Some sites are fussy as to whether GET or POST is used (http://www.w3schools.com/tags/ref_httpmethods.asp), but these forums don't seem to mind.

Check out the entries for 'URL' and the 'urlEncode' function in the LiveCode dictionary...
LiveCode Development & Training : http://splash21.com

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Contact:

Re: Search bars

Post by splash21 » Sat Jan 11, 2014 9:18 pm

I just had a little look at pubmed... the search 'term' is passed in the URL (GET method) ....

So if you change the relevant line in the field script to

Code: Select all

set the htmlText of field "Results" to URL ("http://www.ncbi.nlm.nih.gov/pubmed/?term=" & urlEncode(the text of me))
then you get what I think you're after.

You just have to do a bit more work to pick out the pieces you are interested in.

8)
LiveCode Development & Training : http://splash21.com

Whytey
Posts: 31
Joined: Fri Jan 10, 2014 6:40 pm

Re: Search bars

Post by Whytey » Sat Jan 11, 2014 9:28 pm

Hi Splash, works a dream now thank you! What is the code I would need to use for picking out various parts?

Thanks this is brilliantly helpful!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Search bars

Post by FourthWorld » Sat Jan 11, 2014 10:23 pm

PubMed provides an API, which IIRC uses XML so it may simplify some aspects of parsing returned values:

http://www.ncbi.nlm.nih.gov/books/NBK25500/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Whytey
Posts: 31
Joined: Fri Jan 10, 2014 6:40 pm

Re: Search bars

Post by Whytey » Sun Jan 12, 2014 12:04 pm

Hi, I'm still not sure how quite to parse the results. It seems the titles have a 244 number in front of them could we use this to sort through the junk text? What is the code that would allow me to grab each title starting with 244 and put them into a separate box?

here's an example of what I mean.

Select item 244068682.
p53-Dependent Suppression of Genome Instability in Germ Cells.
Otozai S, Ishikawa-Fujiwara T, Oda S, Kamei Y, Ryo H, Sato A, Nomura T, Mitani H, Tsujimura T, Inohara H, Todo T.
Mutat Res. 2014 Jan 6. pii: S0027-5107(13)00215-7. doi: 10.1016/j.mrfmmm.2013.12.004. [Epub ahead of print]
PMID:

ideally I would like to grab everything from this up until [Epub ahead of print].

I hope you can help! I look forward to hearing from you!

Post Reply