1 4 package com.openedit.store.customer; 5 6 import java.io.File ; 7 import java.io.FilenameFilter ; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.apache.lucene.analysis.Analyzer; 12 import org.apache.lucene.document.Document; 13 import org.apache.lucene.document.Field; 14 import org.apache.lucene.document.Field.Index; 15 import org.apache.lucene.document.Field.Store; 16 import org.apache.lucene.index.IndexWriter; 17 18 import com.openedit.modules.search.BaseLuceneSearch; 19 import com.openedit.modules.search.RecordLookUpAnalyzer; 20 import com.openedit.store.CustomerArchive; 21 import com.openedit.users.User; 22 import com.openedit.util.FileUtils; 23 import com.openedit.util.PathUtilities; 24 25 29 public class CustomerSearch extends BaseLuceneSearch 30 { 31 private static final Log log = LogFactory.getLog(CustomerSearch.class); 32 protected CustomerArchive fieldCustomerArchive; 33 34 37 public void reIndexAll() throws Exception 38 { 39 log.info("Reindex of customer users directory"); 40 42 File indexDir = buildLiveIndexDir(); 44 new FileUtils().deleteAll(indexDir); 45 indexDir.mkdirs(); 46 IndexWriter writer = new IndexWriter(indexDir, getAnalyzer(), true); 47 writer.setMergeFactor(50); 48 File [] usersxml = getSearchDirectory().listFiles(new FilenameFilter () 50 { 51 public boolean accept(File inDir, String inName) 52 { 53 if (inName.endsWith(".xml") ) 54 { 55 return true; 56 } 57 return false; 58 } 59 }); 60 61 for (int i = 0; i < usersxml.length; i++) 62 { 63 Document doc = new Document(); 64 File xconf = usersxml[i]; 65 String username = PathUtilities.extractPageName(xconf.getPath()); 66 doc.add( new Field( User.USERNAME_PROPERTY, username, Store.YES, Index.TOKENIZED ) ); 67 Customer customer = getCustomerArchive().getCustomer(username); 68 customer.getUser().getPassword(); 70 71 String phone = customer.cleanPhoneNumber(); 72 if( phone != null) 73 { 74 doc.add( new Field( "Phone1",phone , Store.YES, Index.TOKENIZED) ); } 76 77 String last = customer.getUser().getLastName(); 78 if( last != null) 79 { 80 doc.add( new Field( "lastName",last, Store.YES, Index.TOKENIZED) ); 82 } 83 84 writer.addDocument(doc); 102 103 } 104 writer.optimize(); 105 writer.close(); 106 107 } 108 109 public Analyzer getAnalyzer() 110 { 111 if (fieldAnalyzer == null) { 112 fieldAnalyzer = new RecordLookUpAnalyzer(); 113 } 114 return fieldAnalyzer; 115 } 116 117 public CustomerArchive getCustomerArchive() 118 { 119 return fieldCustomerArchive; 120 } 121 122 public void setCustomerArchive(CustomerArchive inCustomerArchive) 123 { 124 fieldCustomerArchive = inCustomerArchive; 125 } 126 } 127 | Popular Tags |