Results 1 to 9 of 9

Thread: Multiple Keyword search

  1. #1
    Join Date
    Nov 2010
    Posts
    114
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default Multiple Keyword search

    Hi All,

    I am having search functionality in my website, it allows user to type multiple keywords separated by comma(ex: php,3years,bangalore).

    I am having 4 to 5 fields(skills,location,experience,title,qualification,etc.,) which user will search for. when user search for with 3 or 4 keywords(or more, similar to naukri or monster search).i want to know how that query will be.

    I don't want to run that query in foreach row for every string. Is there anyway i can do it?
    Last edited by hemi519; 01-31-2013 at 03:54 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    You must do a lot of string manipulation to create the right query. You can do this by using a foreach (or just while/for) loop and adding in more text to the string (or using the implode() function). Then you will have a single query.

    I wrote a script for this a while ago and you might find it helpful, although it's a long thread and the script is pretty complicated.

    Here's the thread, and the last page(s) have the full code:
    http://www.dynamicdrive.com/forums/s...arch-algorithm
    Whether or not you'd want to use that, it does have examples of building a dynamic query.

    (Of course, remember to be very careful about security. Escape everything carefully!)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,709
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    I tried writing some example code for what you are looking for to make it easier for you, but it ended up too long. The best starter advice I can give you is to look up the concat() function for MySQL. That should put you on the right track. concat() is used to treat multiple fields as one. There are still so many caveats to the concat() function that I'll let you play around with it and ask questions if you get stuck.

    The thread djr33 suggested is one of the best around, but it can certainly get overwhelming looking at all of that information. We are happy to help if you need any help writing a search program for your site.
    Last edited by james438; 08-24-2014 at 05:46 PM. Reason: typo
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    I might have missed something in the original post:
    1) To search multiple MySQL columns, use concat() as James said.
    2) To search with multiple input keywords, use the strategy I suggested.
    From your original description, it sounds like you may need to use both.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Nov 2010
    Posts
    114
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    Thanks to both of you, I will try those methods and will come back with result ASAP

  6. #6
    Join Date
    Nov 2010
    Posts
    114
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    I have found an alternative to do all my kind of search(multiple keywords). I am using sphinxsearch. This solved all my issues.

    But first i have to concat required fields as you mentioned. Thanks Again

  7. #7
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,709
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Thanks for getting back to us on your solution. It is hard to find good search engines and from what I have read so far it looks like you found a good one.

    I wouldn't use it, but that's just me. The problem for me is that it relies heavily on full text indexing. The problem with full text indexing is that it is not always customizable and full text indexing "helps" the user find what they are looking for. Searching for "fight" will also turn up "fought". Searching for "cats" will also pull up "cat". The searches are never in real time.

    Full text indexing is also significantly faster. For many people faster searches and searches that help the user are quite handy. I prefer a greater deal of control over my searches. sphinxsearch does look legitimate, but whenever you use third party code you need to be careful that malicious code is not in there somewhere. With sphinxsearch this looks very unlikely.
    To choose the lesser of two evils is still to choose evil. My personal site

  8. #8
    Join Date
    Nov 2010
    Posts
    114
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    Thanks For ur suggestions.

    Sphinxsearch is having its own custom rankers. It will give results according to "index weights".

    Searching for "cats" will also pull up "cat". But first results will be only which are matching exactly to "cats" and then "cat" results will be followed.

    Yes, there might be some issues while using third party tools and as u said they have to be taken care.

  9. #9
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,709
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Thanks for pointing that out. I had forgotten about weighted results with full text indexing. Overall I think you found a good and trustworthy search engine.

    I'm partly biased towards the one I made since I made it
    To choose the lesser of two evils is still to choose evil. My personal site

Similar Threads

  1. Display multiple RSS feeds based on a keyword using gAjax RSS v2
    By TennisWill in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 03-06-2013, 05:40 PM
  2. Keyword Search Box script, came across it but can't find it anymore
    By graigkarl in forum Looking for such a script or service
    Replies: 1
    Last Post: 12-09-2010, 08:12 AM
  3. Replies: 0
    Last Post: 07-17-2010, 11:34 PM
  4. search for multiple table
    By kmyousafzai in forum MySQL and other databases
    Replies: 1
    Last Post: 05-10-2008, 03:11 PM
  5. One search form with multiple options
    By sartajc in forum Looking for such a script or service
    Replies: 4
    Last Post: 12-08-2006, 07:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •