0

I've been working on trying to integrate some form of full text search to a small assignment (for fun). Unfortunately, no matter the search term, it returns no results, not even when I enter exact information.

For example, when I perform a search using the Python console after importing the SQLAlchemy model, it returns information just as expected.

>>> Contact.query.whooshee_search('sch').all()
[<Contact u'Kimberley' u'Schuppe' u'cathie.schmitt@paucek.com'>, <Contact u'Kelsey' u'Schinner' u'walsh.ardyce@yahoo.com'>, <Contact u'Rella' u'Schamberger' u'abbott.feest@gmail.com'>]

However, when performing the same search through the Flask view from a POST parameter it returns with nothing.

@app.route('/', methods=['GET', 'POST'])
@app.route('/page/<int:page>', methods=['GET'])
def index(page=1):
    if request.method == 'POST':
        query = request.form['search']
        result = Contact.query.whooshee_search(query).all()
        print query, 'result:', result
    contact = Contact.query.with_entities(Contact.lname, Contact.fname, Contact.phone, Contact.addr, Contact.email).paginate(page, app.config['PAGE_MAX'], False)
    return render_template('index.html', entry=contact)

Result from search of 'sch' from form:

sch result: []

What could be causing this? I'm genuinely stumped why the same query from the console works fine, but through the view returns nothing.

Battleroid
  • 861
  • 2
  • 14
  • 30
  • Battleroid were you able to find a solution? I think I'm getting the same problem. – user805981 Mar 18 '15 at 20:46
  • Unfortunately, no. I eventually just moved from SQLite to MySQL. That seemed to fix the issue. – Battleroid Mar 19 '15 at 16:01
  • Really? how were you able to get whooshee to understand your partial search (ngram search?)? It keeps making me use a full text with no error to get it correctly. – user805981 Mar 19 '15 at 16:47
  • I honestly can't remember. I ended up dropping full text search as it wasn't needed anyway. – Battleroid Mar 19 '15 at 20:30
  • 1
    Make sure to include the `WHOOSHEE_DIR` in your app.config . I had accidentally only specified the path in my production config and not development and was having the exact same issue. – siegerts Mar 15 '16 at 14:08

1 Answers1

0

This is very old but just in case anyone is facing a similar issue:

Flask-Whooshee (and other flask whoosh variants) seem to work by adding to the index when new data is added to the db, so if you have an existing app or a db which already contains data then the index will be empty.

Only data that is added after the index is created will be indexed.

If you do have an existing app/db then Flask-Whooshee includes the Whooshee.reindex() method to index the data. Note that this needs to be called after any models have been registered, so in the case where you are defining models in a separate file, the __init__.py file would look something like this:

app = Flask(__name__)
whooshee = Whooshee(app)

from app import models

with app.app_context():
    whooshee.reindex()
pduebel
  • 1
  • 1