Subversion Repositories SmartDukaan

Rev

Rev 285 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
278 ashish 1
'''
2
Created on 17-Jun-2010
3
 
4
@author: gaurav
5
'''
6
 
7
import os
8
import lucene
9
from datastore.DataAccessor import *
10
 
11
lucene.initVM(classpath=lucene.CLASSPATH)
12
ps = os.pathsep
13
ds = os.sep
14
 
15
#analyzer = lucene.
16
analyzer = lucene.StandardAnalyzer()
17
#analyzer = lucene.SimpleAnalyzer()
18
# Creating the Index
19
path_index1 = ds+"home"+ds+"gaurav"+ds+"code" + ds + "index1"
20
#Create the Index Writer
21
writer = lucene.IndexWriter(path_index1,analyzer,True) 
22
 
23
da = DataHelper()
24
da.initxy()
25
 
26
phones = da.get_all_infibeam_data()
27
for p in phones:
28
    doc = lucene.Document()
29
    id = p.id
30
    #print id
31
    doc.add(lucene.Field("ID",str(id),lucene.Field.Store.YES,lucene.Field.Index.NO))
32
    name = p.name
33
    #print name
34
    doc.add(lucene.Field("name",name,lucene.Field.Store.YES,lucene.Field.Index.TOKENIZED))
35
    price = p.final_price 
36
    #print price
37
    doc.add(lucene.Field("price",str(price),lucene.Field.Store.YES,lucene.Field.Index.NO))
38
    print "id " + str(doc.getField("ID")) + " name " + str(doc.getField("name")) + " price " + str(doc.getField("price"))
39
    writer.addDocument(doc)
40
    print str(writer.docCount())
41
 
42
 
43
writer.close()