#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Search in Python


    Hello all. I'm hoping someone here can help us. We recently hired a few young developers to help modify a custom system we have internally. We needed to add a simple document management piece where we could easily upload documents and make then searchable.

    Here's our issue, we are now being told that although our documents are being uploaded and the text is being "ripped" from the document and inserted in the database, we can't build a proper search for this. In other words, I want to be able to enter key words in straight keywords separated by commas or even a boolean type search where we could combine AND and OR.

    We are told this is impossible as it is a limitation of python (or possibly django?).

    Now I don't want to just assume my developers don't know what they are doing but we are in a bit of a situation where this new module has now essentially become useless to us. Can someone confirm whether this is correct or if this is in fact possible?

    thanks all.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    What database are you using?
    Whichever probably accepts sql queries.
    You should be able to write sql statements similar to

    select * from table where someColumn contains 'word' and someOtherColumnPerhaps contains 'anotherWord';

    Python is a general purpose programming language. If a task can be coded, if you have access to the data, if you have sufficient resources, python can do the task.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    we are using Postgres. I guess our issue comes from from taking a string like

    this AND that AND (him OR her)

    and turning that into a proper sql query. All the searchable text is in 1 field (column). So the query wouldn't even need to search through multiple fields. Just the same field in multiple records.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    I'm unemployed, but you apparently are employed and have hired some programmers.

    "Databases" and "origin" are from the example database.

    Given a sqlite3 database
    $ sqlite3 ~/.config/chromium/Default/databases/Databases.db

    I can find its tables
    sqlite> .tables

    I can find its schema
    sqlite> .schema Databases

    I can write a select statement similar to your example:
    sqlite> select * from Databases where origin like '%lm%' and (origin like '%fl%' or origin like '%nf%');

    and I can certainly write python code to transform
    this AND that AND (him OR her)
    into
    select * from Databases where origin like '%this%' AND origin like '%that%' AND (origin like '%him%' OR origin like '%her%');
    Last edited by b49P23TIvg; October 26th, 2012 at 09:25 AM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    b49P23TIvg, how do you make that dynamic though?

    in other words, there is no predefined set of parameters I'm passing.

    For example, I could have a search that is simply

    This or That

    or even

    This AND that

    but likewise, I could have something more complex like

    this AND that AND (him OR her) AND (he OR she)


    Somehow, we need to be able to take whatever is in the search field and turn that into a proper SQL statement...

    Again, I'm not a developer... maybe I'm the wrong person to be trying to figure this out but we're in a jam and anything I can do to get this moving I'll do.
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    You can hire me, and I'll help more.

    You can search all my posts at devshed, I've solved this problem, and you might be able to find my answer.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo