Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. body = """This is the body of the document,
  2. with a set of words"""
  3.  
  4. my_document = search.Document(
  5. fields=[
  6. search.TextField(name='title', value='A Set Of Words'),
  7. search.TextField(name='body', value=body),
  8. ])
  9.  
  10. documents = [
  11. dict(title="Alpha", body="A"), # "Alpha"
  12. dict(title="Beta", body="B Two"), # "Beta"
  13. dict(title="Alpha Two", body="A"), # "Alpha2"
  14. ]
  15.  
  16. for doc in documents:
  17. search.Document(
  18. fields=[
  19. search.TextField(name="title", value=doc.title),
  20. search.TextField(name="body", value=doc.body),
  21. ]
  22. )
  23. index.put(doc) # for some search.Index
  24.  
  25. # Then when we search, we search the Title and Body.
  26. index.search("Alpha")
  27. # returns [Alpha, Alpha2]
  28.  
  29. # Results where the search is found in the Title are given higher weight.
  30. index.search("Two")
  31. # returns [Alpha2, Beta] -- note Alpha2 has 'Two' in the title.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement