Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- body = """This is the body of the document,
- with a set of words"""
- my_document = search.Document(
- fields=[
- search.TextField(name='title', value='A Set Of Words'),
- search.TextField(name='body', value=body),
- ])
- documents = [
- dict(title="Alpha", body="A"), # "Alpha"
- dict(title="Beta", body="B Two"), # "Beta"
- dict(title="Alpha Two", body="A"), # "Alpha2"
- ]
- for doc in documents:
- search.Document(
- fields=[
- search.TextField(name="title", value=doc.title),
- search.TextField(name="body", value=doc.body),
- ]
- )
- index.put(doc) # for some search.Index
- # Then when we search, we search the Title and Body.
- index.search("Alpha")
- # returns [Alpha, Alpha2]
- # Results where the search is found in the Title are given higher weight.
- index.search("Two")
- # returns [Alpha2, Beta] -- note Alpha2 has 'Two' in the title.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement