Giter Club home page Giter Club logo

search's Introduction

Search (Thor)

Thor (search) is a wrapper for Google App Engine's search API that uses Django-like syntax for defining documents, and searching and filtering search indexes.

Example

Searching films

Say your app has a database of films that needs to be searched. The first step is to define a document class describing the searchable film data:

from search import indexes, fields

class FilmDocument(indexes.DocumentModel):
    title = fields.TextField()
    description = fields.TextField()
    rating = fields.FloatField()
    released = fields.DateField()

To index a film document, instantiate and populate it with data, and then add it to Thor's provided Index class. It's more likely the data would come from some other source (datastore, database, etc.) but for this example we hand-craft it:

>>> from datetime import date
>>> from search import indexes
>>> from myapp.documents import FilmDocument
>>>
>>> # This gets a search index by name or creates it if it doesn't exist
>>> i = indexes.Index(name='films')
>>> # Create a film document representing the film Die Hard
>>> doc = FilmDocument(
...     doc_id='die-hard',
...     title='Die Hard',
...     description='The most awesome film ever',
...     rating=9.7,
...     released=date(1989, 2, 3)
... )
>>> # Add the document to the index. In reality this should be done on
>>> # a taskqueue at a rate around 4 docs/sec.
>>> i.put(doc)

Now the document has been indexed and is ready to search:

>>> # You need to pass the document class (FilmDocument here) to the
>>> # index's search method so that it knows what class to instantiate
>>> # with the search results
>>> results = i.search(FilmDocument).keywords('die hard awesome')
>>> for d in results:
...     print d.title, d.description, d.rating, d.released
...
'Die Hard', 'The most awesome film ever', 9.7, datetime.date(1989, 2, 3)

From a basic standpoint, that's all there is to it. There is various filtering and ordering that can be applied to search queries, refer to the reference for the Index class for more in-depth example queries.

Reference

See here for WIP docs.

search's People

Contributors

adamalton avatar davidwtbuxton avatar kaedroho avatar kazade avatar martinallison avatar nealedj avatar owad avatar pablorecio avatar robcharlwood avatar seawolf42 avatar sleepyjames avatar tobyhammond avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.