I need to study Markdown some.
This commit is contained in:
parent
59f61fcbab
commit
5b1e2c3d33
42
README.md
42
README.md
|
@ -30,39 +30,39 @@ Standard Usage:
|
||||||
|
|
||||||
Create the index. For the model "book" in the app "Books":
|
Create the index. For the model "book" in the app "Books":
|
||||||
|
|
||||||
./manage dbshell
|
./manage dbshell
|
||||||
> CREATE FULLTEXT INDEX book_title on books_book (title, summary)
|
> CREATE FULLTEXT INDEX book_title on books_book (title, summary)
|
||||||
|
|
||||||
Or via South:
|
Or via South:
|
||||||
|
|
||||||
def forwards(self, orm):
|
def forwards(self, orm):
|
||||||
db.execute('CREATE FULLTEXT INDEX book_text_index ON books_book (title, summary)')
|
db.execute('CREATE FULLTEXT INDEX book_text_index ON books_book (title, summary)')
|
||||||
|
|
||||||
Using the index:
|
Using the index:
|
||||||
|
|
||||||
from mysqlfulltextsearch import SearchManager
|
from mysqlfulltextsearch import SearchManager
|
||||||
class Books:
|
class Books:
|
||||||
...
|
...
|
||||||
objects = SearchManager()
|
objects = SearchManager()
|
||||||
|
|
||||||
|
books = Book.objects.search('The Metamorphosis', ('title', 'summary')).order_by('-relevance')
|
||||||
|
|
||||||
books = Book.objects.search('The Metamorphosis', ('title', 'summary')).order_by('-relevance')
|
> books[0].title
|
||||||
|
"The Metamorphosis"
|
||||||
> books[0].title
|
> books[0].author
|
||||||
"The Metamorphosis"
|
"Franz Kafka"
|
||||||
> books[0].author
|
> books[0].relevance
|
||||||
"Franz Kafka"
|
9.4
|
||||||
> books[0].relevance
|
|
||||||
9.4
|
|
||||||
|
|
||||||
If there is only one index for the table, the fields do not need to be
|
If there is only one index for the table, the fields do not need to be
|
||||||
specified, the SearchQuerySet object can find it automatically:
|
specified, the SearchQuerySet object can find it automatically:
|
||||||
|
|
||||||
from mysqlfulltextsearch import SearchManager
|
from mysqlfulltextsearch import SearchManager
|
||||||
class Books:
|
class Books:
|
||||||
...
|
...
|
||||||
objects = SearchManager()
|
objects = SearchManager()
|
||||||
|
|
||||||
books = Book.objects.search('The Metamorphosis').order_by('-relevance')
|
books = Book.objects.search('The Metamorphosis').order_by('-relevance')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue