Like %, string search

Hi all,
I am making a application in which there is string search but i dont know how to find a solution.
For example in sql, there is (like %) expression to find similar words. But in java how can I do that.
For instance word1 = mehmet, word2 = mehemet.
How can i do it?
Thanks...

regerybets wrote:
Hi all,
I am making a application in which there is string search but i dont know how to find a solution.
For example in sql, there is (like %) expression to find similar words. But in java how can I do that.
For instance word1 = mehmet, word2 = mehemet.
How can i do it?
Thanks...Sounds like a job for Levenshtein. Apache has an implementation in their Commons-Lang API:
import org.apache.commons.lang.StringUtils;
public class LevenshteinDemo {
    public static final int MINIMUM_LIKE_DISTANCE = 4;
    public static boolean like(String wordA, String wordB) {
        return like(wordA, wordB, MINIMUM_LIKE_DISTANCE);
    public static boolean like(String wordA, String wordB, int permittedDistance) {
        return StringUtils.getLevenshteinDistance(wordA, wordB) <= permittedDistance;
    public static void main(String[] args) {
        String a = "mehmet";
        String b = "mehemet";
        String c = "ambulance";
        String d = "meehemeet";
        String e = "mhmt";
        System.out.println(like(a, b));
        System.out.println(like(a, c));
        System.out.println(like(a, d));
        System.out.println(like(a, e));
/* output:
                true
                false
                true
                true
*/Download it here: [http://commons.apache.org/downloads/download_lang.cgi], stick the file commons-lang-2.4.jar in your classpath and the snippet above will compile. Of course, you may want to make permittedDistance variable depending on the size of the input words. Now it will only work for small strings/words, not larger chunks of text.

Similar Messages

  • Help me in writing ajax string search from database

    {noformat}*hi everybody,
    please send me a ajax with jsp application
    suppose i enter a word in text area ajax will populate/suggest all string from database ,who started
    from that entering character(s).like a google string search.
    please send full source code
    *{noformat}

    shadab_think_globally wrote:
    {noformat}*hi everybody,
    please send me a ajax with jsp application
    suppose i enter a word in text area ajax will populate/suggest all string from database ,who started
    from that entering character(s).like a google string search.
    please send full source code
    *{noformat}how about you do it yourself?

  • Faster string search options

    Hi
    I am an intern at a mobile technology firm assigned the job of enhancing the search performance of a tool, which is coded completely in java. This tool, along with other features basically searches for the substring in a string array by using the string.indexof() method which is very slow, since i am dealing with vast amount of data..
    Now the last two weeks all I did was try and understand the massive code. These are the alternatives I came up with. I could do with suggestions about the feasibilities of these ideas.. or any new suggestions are welcome..
    1. are there any faster ways instead of string.indexof() that i can use to do my string search?
    2. How about replacing this indexof() method with a faster search algorithm? something like boyer-moore for example??
    3. will using a the .nio package instead of .io package work???
    4. how about completely scrapping this string search and taking in the data from input stream as integer format.. and then doing the comparisons??
    thanks
    mahima

    yumjay wrote:
    1. are there any faster ways instead of string.indexof() that i can use to do my string search?You seem to have found one in section 2.
    2. How about replacing this indexof() method with a faster search algorithm? something like boyer-moore for example?? Well obviously you can't override or replace String's indexOf, but you could certainly change the code to use a different algorithm. What's stopping you?
    3. will using a the .nio package instead of .io package work??? Not sure, there may be virtue in some of the memory mapping additions, but I don't really know your requirements or situation.
    4. how about completely scrapping this string search and taking in the data from input stream as integer format.. and then doing the comparisons?? The string search is essentially doing integer comparisons on data 16 bits at a time (that's the width of a char). So first, remember that the int returned by InputStream.read() isn't really an int but a byte stuffed into an int (so they can return -1 on EOS). That said, you might experience a performance gain if you put the data into ints or longs (depending on your computer architecture) and then use something like boyer-moore, because your computer can likely do comparisons of two bytes, chars, shorts, ints (and perhaps even longs on a 64-bit architecture) in the exact same amount of time. They're probably even the same machine instruction. You also wouldn't therefore have to decode the input data into a string either. But you'd have to encode your search string into integers. So yeah you could potentially squeeze a bit more speed, not likely more than 50% though.

  • Generic String Search

    Hi Friends ,
    I want a generic function via which i can search the data just like google-search, for example the
    following query will return a set of records, the query is written as follows:
    with t as
    select 'internal production order' a from dual
    union all
    select 'internal sale order' a from dual
    union all
    select 'sale order' a from dual
    union all
    select 'production order' a from dual
    union all
    select 'internal jobwork' a from dual
    union all
    select 'internal order' a from dual
    select * from t
    case 1 :- i/p search string->'internal order' or 'order internal'
    then
    o/p like --
    internal production order
    internal order
    internal sale order
    don't come sale order,production order,internal jobwork
    case 2 :- i/p search string->'internal order' or 'order internal'
    then
    o/p like --
    internal production order
    internal order
    internal sale order
    I have given you the two cases as is written above, in simple language  all i want is to search
    like google, suppose i type in any order ( for example i type "ankit", then 
    it should return those records from consisting of "ankit"  BUT suppose i want to search "ankit
    bhatt", then the query should be like that even if i type "bhatt ankit", it should return those
    records which consists of "ankit" and "bhatt" IN ANY ORDER.
    please run the above query and provide me that query in which i should be capable of searching the
    records ( irrespective of the order of input i make in ).
    Thanks

    It looks like I already gave you the answer in a prior thread.
    Generic search for string
    MK

  • Problem in String Search using OKAPI in 9i Lite

    We are creating an Symbian EPOC application using Oracle 9iLite in stand-alone mode. We have managed to create a C++ program that creates an Oracle database on the Nokia Communicator 9210.
    The problem is that a string search returns either null or all of the searched records, ie. it does not work.
    The code below should do the string search and return the strings that match the given keyword. Any idea why this is not working? We are using OKAPI.
    TempCond[0].Operator = OK_GT;
    TempCond[0].AttrPos = KEYWORDREFERENCE_INDEX_FOR_KEYWORD;
    TempCond[0].AttrVal.BufPtr = (unsigned char*) szGivenKeyword;
    TempCond[0].AttrVal.BufSize = OK_NEW_ARRAY | strlen szGivenKeyword);
    TempCond[0].AttrVal.Indicator=1;
    TempCond[0].Collate=0;
    TempCond[0].Connective=OK_AND;
    // Iterate through the entire group, extracting the key data
    //(whatever the key may be) and the object reference, and
    // append to the end of the array.
    e = okCreateIterator( iEnv,
    iEbmgKeywordReferenceGroupRef,
    iEbmgKeywordReferenceClassRef,
    FALSE,
    1,
    TempCond,
    20,
    0,
    NULL,
    &iter
    Thanks for any help you may provide.

    I am sorry, this is not an answer to your question but a little help from you is well appeciated.
    I have just started exploring oracle 9i Lite to develop apps. on Palm and WinCE using OKAPI but the documentation does not seem enough. Is there some book or sample programs available that demonstrate OKAPI to develop form based apps ? CodeWarrior and Satellite Forms are not good when someone wants to try writing demp app.
    Thanks,
    Ashish

  • String search

    i hI have a string "1234, abcdef, bbbbb"
    How do one get/search for the "abcdef" or "bbbb" out of the string using substring?
    If anyone has source code or references (for similar code) searching for "abcdef�(normally text enter in a text field that will be used to search through a string) It would be appreciated

    // This might help!
    String search = "test";
    Pattern pattern = Pattern.compile(".*" +search +".*");
    boolean test = pattern.matcher(testString).matches();

  • I cant connect to my wi fi even sitting right in front of it, next to my wifi network, it just keeps spinning around, like its searching

    I can't connect to my wi fi even sitting right in front of it, it just keeps spinning around and around, like its searching and can't find it. My husbands iphine picks it up, but mine doesn't, it's using up all my data plan

    Try restarting the phone and your router that may work.

  • I do not like inbox search and want to use google but i cannot find any way to remove inbox--in fact when i search for it to remove you would think it is not there--but it is and i cant get it off. anyone know how?

    Question
    i do not like inbox search and want to use google but i cannot find any way to remove inbox--in fact when i search for it to remove you would think it is not there--but it is and i cant get it off. anyone know how? edit
    Details

    What you should see on a restart is a black screen followed by a screen with the Apple (at which point you let go of the two buttons). There is no progress bar, just the Apple. The Apple will stay there for 15 seconds or so, then the "Slide to Unlock" screen will redisplay.
    But, I don't think the reset will fix it for you. I just tested it, and it comes back on with the zoom still on. The only way to get it to zoom out is the tapping with the 3 fingers.
    I said to double-tap....MY BAD! You need to triple-tap with three fingers!
    Try that and see if it will display the zoom menu for you, or if it will zoom back out.
    Cheers,
    GB

  • Firefox does not open site when i type just site name like "yahoo search"...my earlier version did it

    I downloaded latest beta version of firefox. It does not open sites when i type just the site name like "yahoo search" or "youtube" etc...
    I have to type the complete address like"youtube.com" or "facebook.com"
    While earlier version of firefox did it. Please help...

    Firefox 12 does not open yahoo which is my home page and e-mail. All I get is a grey screen with small icons on the left which do not open. I also have same problem with Safari.

  • Exact string search

    i was wondering if there was a way to do an exact string search in a document.
    If i have a document that has punctuation i want to be able to find the document only if i query whith an exact string match, including stopwords and punctuations.
    if the query is
    select *
    from documents1
    where contains(OBJECT_VALUE,'{hello, world}') > 0
    I want only to return the documents that have exactly "hello, world" whith the comma included.
    If i add the comma to printjoins, it would work, But when i query for only "hello" it wont match "hello, world"
    basicaly im looking for something that does a normal search but then check if the exact string is in the match area.

    Try this
    select substr(&P, (INSTR(&P, CHR('32'), 1))+1, (INSTR(&P, CHR('32'), 1)))
    from dual
    &p is a variable
    I am sure this will help you in any of case
    chr(32) will return space, If you have any other thing except space then you just replace 32 with that ascii code. Such as for
    1(we)2 then query will be
    select substr(&P, (INSTR(&P, CHR('40'), 1))+1, (INSTR(&P, CHR('41'), 1)))
    from dual
    Try it and tell is it working fine

  • Approximate string search

    Hi everyone,
    If anyone here is interested in approximate string search algorithms, take a look at this prototype: http://scientechs.com/servlet/smartsearch.test.ApproxiMatchServlet . Keyword DB was compiled from the list of canadian business names and has right now ~200K of words, so don't expect to find every english word there.
    Source code would be uploaded to sourceforge soon (smartsearch.sourceforge.net). If anyone wants to participate in improving the project, drop a note. All feedback is welcome.

    From the description:
    "Approximate string search algorithm implementation (the algorithm was developed from the scratch, so it is NOT an implementation of existing algorithms), written in Java and runs under any OS that supports Java2 platform."
    I know there are a number of approximate string matching out there. My question is how does your algorithm relate to the other ones?
    I tried keyword apple, so it seems there is more work to do, but at least it worked.

  • Is there any API available to do string search and replace?

    as above?

    For simple string searching have a look at java.util.StringTokenizer.
    Regular Expressions are included in v1.4.
    Have there a look at the String class itself and the new java.util.regex package.
    Greets
    Puce

  • Ios 6 have some bugs on ipod touch 4g like appstore search bug and accessibility which i cant go out from and crashes every where and imassages that the massge i send goes up and stick to the other messages plz help or do ios 6.1

    Ios 6 have some bugs on ipod touch 4g like appstore search bug and accessibility which i cant go out from and crashes every where and imassages that the massge i send goes up and stick to the other messages plz help or do ios 6.1 can i change my a4 chip plz i swear when i pressed done to submite this safari crashed

    Try to do a hard reboot (no data is lost) by holding down the home and power buttons at the same time untilyou see the Apple logo. Then, let go of both buttons. If that doesn't work, try restoring your iPod and do NOT restore from a backup. This will erase your data, but you can sync back everything except app data and settings from iTunes.

  • I have scanned about 1600 pages of 100-year old documents and saved them as pdf files.  I would like to search them for keywords and phrases.  Can anyone recommend software that can be used as an index for these documents?

    I have scanned about 1600 pages of 100-year old documents and saved them as pdf files.  I would like to search them for keywords and phrases.  Can anyone recommend software that can be used as an index or search engine for these documents?

    If you have Adobe Acrobat (not Adobe Reader) the program can perform an OCR on the document you acquired.
    In the past I used ABBYY FineReader

  • I'm having trouble texting from my IPAD. Sometimes it looks like its searching and other times I get a red exclamation point.

    I'm having trouble texting from my IPAD 2. Most of the time it looks like its searching or I get a red exclamation point.
    I was only able to send 2 texts. Help!

    iPads cant send regular texts - only through iMessage meaning that the other device will need to have iMessage too.
    If you can't send a text that means the other person does not have iMessage and iMessage is only installed on iOS devices or OSX Lion

Maybe you are looking for

  • I want to create a contact sheet in Bridge CC and there isn't an output module..

    I don't seem to have the Output Module for Bridge CC. I read how to copy and paste it into the Bridge Extensions folder. It did copy it, and it did add "output" to my menu bar but the content area is blank, so I cannot pick my PDF output options for

  • Is there any time frame for when all apps have to be updated to be full screen on the iPhone 5?

    A lot of my apps still dont open in full screen, as Im sure most of you have noticed. Is there any word as to when/if developers are forced to make this update to use the full screen? Its pretty lame that some apps are still the same size as they wer

  • ORA-00933, remote db, dashes, Portal?! [moved]

    I have a database link setup from an Oracle Portal database to a remote Oracle database. Everything works from SQLPlus, but not from Portal. From Portal and from DB Console I receive the following error: From Portal; ORA-00933: SQL command not proper

  • NI-DMM vs. IVI-DMM - Soft Front Panel

    Hello All,   I have been developing a testing application that will eventually use a PXI-4070 DMM (currently simulating it in NI MAX).  I had been using the IVI DMM functions, but ran into a problem when I couldn't do a diode test (diode test is appa

  • How to become a good ABAPER

    Hi Friends , i want to become a String and very good ABAPER.. 1) how to improve my ABAP SKILLS . 2) First how to analyze the Issue when issue comes  from Functional Consultant? 3) how do improve to writting ABAP coding?? pls advice. Rgeards, Sreenu