Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:31:21+00:00 2026-06-05T09:31:21+00:00

I am trying to implement searching a set of multiple words which include multiple

  • 0

I am trying to implement searching a set of multiple words which include multiple parts.
For example, we have these medical terminologies.

R Deep Transverse Metatarsal Ligament 4 GEODE
R Distal JointCapsule 1 GEODE
R Dorsal Calcaneocuboid Ligament GEODE
R Dorsal Carpometacarpal Ligament 2 GEODE
R Dorsal Cuboideavicular Ligament GEODE
R Dorsal Tarsometatarsal Ligament 5 GEODE
R Elbow Capsule GEODE
R F Distal JointCapsule 1 GEODE
R Fibular Collateral Bursa GEODE
R Fibular Collateral Ligament GEODE
R Fibular Ligament GEODE

User can enter search terms like this:

e.g., “R De Me Li” then this should find “R Deep Transverse Metatarsal Ligament 4 GEODE”

e.g., “Fi Colla” ==> “R Fibular Collateral Bursa GEODE”, “R Fibular Collateral Ligament GEODE”

e.g., “bow ODE” ==> “R Elbow Capsule GEODE”

That is, even when user enters some portions of a word, it should find the answers.
If there are multiple answers, it should show all.
I appreciate your help in advance.

Added) Oh.. I forgot something.

e.g., “ral lar” ==> It shouldn’t show “R Fibular Collateral Bursa GEODE” or “R Fibular Collateral Ligament GEODE” since the order of query words should be considered.

In addition, the spaces among the query words mean different words of each line (database).

The order of query words should be the same as the words of each line (database),
but the query words could be shorter than the database words.

e.g., “R De Me 4” ==> “R Deep Transverse Metatarsal Ligament 4 GEODE”
Where we can see that ‘Metatarsal’ and ‘Ligament’ include ‘me’, but the first match with ‘Metatarsal’ is fine, and 4 will be searched.

In addition, different combinations of query words can return the same result.

e,g.,

‘Car’ ==> ‘R Dorsal Carpometacarpal Ligament 2 GEODE’

‘Do Car’ ==> ‘R Dorsal Carpometacarpal Ligament 2 GEODE’

‘R Do Carp’ ==> ‘R Dorsal Carpometacarpal Ligament 2 GEODE’

Note: no case-sensitive.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:31:24+00:00Added an answer on June 5, 2026 at 9:31 am

    You can do this with difflib in the standard distribution:

    import difflib
    
    s="""R Deep Transverse Metatarsal Ligament 4 GEODE
    R Distal JointCapsule 1 GEODE
    R Dorsal Calcaneocuboid Ligament GEODE
    R Dorsal Carpometacarpal Ligament 2 GEODE
    R Dorsal Cuboideavicular Ligament GEODE
    R Dorsal Tarsometatarsal Ligament 5 GEODE
    R Elbow Capsule GEODE
    R F Distal JointCapsule 1 GEODE
    R Fibular Collateral Bursa GEODE
    R Fibular Collateral Ligament GEODE
    R Fibular Ligament GEODE""".split('\n')
    
    qs="""R De Me Li
    Fi Colla
    bow ODE""".split('\n')
    
    for q in qs:
        print "results for '{}':".format(q)
        matches=difflib.get_close_matches(q,s,3,0.3)
        for i,e in enumerate(matches,1):
            print "\t{}. {}".format(i,e)
    

    Prints:

    results for 'R De Me Li':
        1. R Deep Transverse Metatarsal Ligament 4 GEODE
        2. R Dorsal Calcaneocuboid Ligament GEODE
        3. R Dorsal Cuboideavicular Ligament GEODE
    results for 'Fi Colla':
        1. R Fibular Collateral Bursa GEODE
        2. R Fibular Collateral Ligament GEODE
    results for 'bow ODE':
        1. R Elbow Capsule GEODE
    

    Combining with cblab’s answer on combining regex’s with difflib, you can get this:

    s="""R Deep Transverse Metatarsal Ligament 4 GEODE
    R Distal JointCapsule 1 GEODE
    R Dorsal Calcaneocuboid Ligament GEODE
    R Dorsal Carpometacarpal Ligament 2 GEODE
    R Dorsal Cuboideavicular Ligament GEODE
    R Dorsal Tarsometatarsal Ligament 5 GEODE
    R Elbow Capsule GEODE
    R F Distal JointCapsule 1 GEODE
    R Fibular Collateral Bursa GEODE
    R Fibular Collateral Ligament GEODE
    R Fibular Ligament GEODE""".split('\n')
    s=set(s)
    qs="""R De Me Li
    Fi Colla
    bow ODE
    Car
    Do Car
    ral lar
    R De Me 4
    R Do Carp""".split('\n')
    
    for q in sorted(qs):
        print "results for '{}':".format(q)
        pattern = r'.*' + re.sub(r'\W', '.*', q.strip()) + '.*'
        matches=[item for item in s if re.match(pattern, item, re.I)]
        for e in difflib.get_close_matches(q,s,3,0.33):
            if e not in matches: 
                matches.append(e)
    
        for i,e in enumerate(matches,1):
            print "\t{}. {}".format(i,e)
        else:
            if len(matches)==0:
                print "\tNo matches"    
    

    Prints:

    results for 'Car':
        1. R Dorsal Carpometacarpal Ligament 2 GEODE
    results for 'Do Car':
        1. R Dorsal Carpometacarpal Ligament 2 GEODE
    results for 'Fi Colla':
        1. R Fibular Collateral Bursa GEODE
        2. R Fibular Collateral Ligament GEODE
    results for 'R De Me 4':
        1. R Deep Transverse Metatarsal Ligament 4 GEODE
    results for 'R De Me Li':
        1. R Deep Transverse Metatarsal Ligament 4 GEODE
        2. R Dorsal Calcaneocuboid Ligament GEODE
    results for 'R Do Carp':
        1. R Dorsal Carpometacarpal Ligament 2 GEODE
        2. R Elbow Capsule GEODE
        3. R Distal JointCapsule 1 GEODE
    results for 'bow ODE':
        1. R Elbow Capsule GEODE
    results for 'ral lar':
        No matches
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
I am trying to implement a djapian based full text search for searching user
I have this weird kind of error. I am trying implement basic Euclidean algorithm
While trying to implement an MVC file upload example on Scott Hanselman's blog. I
I'm trying to implement method chaining in C++, which turns out to be quite
I am trying to implement a fulltext search on two columns which I created
I'm trying to implement an updatepanel animation with jquery, I was searching in the
I have a rails app in which I am trying to do some full
I have been searching everywhere on the web and trying everything that I can
Maybe I am searching the wrong thing or trying to implement this the wrong

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.