Changeset 3483


Ignore:
Timestamp:
09/08/10 12:46:26 (17 months ago)
Author:
antonak
Message:

Build Index altered without specific DB table names & fields.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • biobank_search/handwritten/java/plugins/DBIndexPlugin.java

    r3481 r3483  
    160160                        // You can use public StandardAnalyzer(Version matchVersion, File stopwords) throws IOException adding a STOP WORD file 
    161161                        writer = new IndexWriter( FSDirectory.open(file), analyzer, true, IndexWriter.MaxFieldLength.LIMITED); 
    162                          
     162                        String fullText = null ; 
     163 
    163164                        for(Class<Entity> aClass: db.getEntityClasses()) {       
    164165                                for(Entity e: (List<Entity>)db.find(aClass)) { 
    165166                 
    166                                         Document document1 = new Document(); 
    167                                          
    168                                         //TODO: choose the fieldnames automatically 
     167                                        Document document1 = null; 
     168                                        document1 = new Document(); // TODO : check if this works , otherwise need  to be move inside next for loop  
     169                                        fullText  = aClass.getName(); 
     170                                        //System.out.println("[DEBUG]"+fullText); 
     171                                         
     172                                        //TRICK 
     173                                        for(String fieldName: e.getFields()) { 
     174                                                 
     175                                                //System.out.println("_________Fieldname : " +  fieldName + "____"); 
     176                                         
     177                                                //document1 = new Document(); 
     178 
     179                                                Field ClassName = new Field("className", aClass.getName().toString(), Field.Store.YES, Field.Index.NOT_ANALYZED); 
     180                                                document1.add(ClassName); 
     181                                                //System.out.println(aClass.getName().toString()); 
     182                                                 
     183                                                if (e.get(fieldName) != null) { 
     184                                                        Field InsertFieldValue = new Field(fieldName, e.get(fieldName).toString(), Field.Store.YES, Field.Index.ANALYZED); 
     185                                                        document1.add(InsertFieldValue); 
     186                                                        //System.out.println("All : 1st (" + fieldName + ")as InsertFieldValue inserted in Index" + InsertFieldValue.toString()); 
     187         
     188                                                        //this is the same as InsertFieldValue. Though if you remove it , the field is not included and search does not work. 
     189                                                        //TODO : check if values of the specific field are empty .  
     190                                                        fullText = fullText + " " +  e.get(fieldName).toString(); 
     191         
     192                                                        Field fullTextField = new Field("fulltext", fullText, Field.Store.NO, Field.Index.ANALYZED); 
     193                                                        document1.add(fullTextField); 
     194                                                        //System.out.println("All : FULLTEXT ( fulltext as anotherField inserted in Index" + fullTextField.toString());          
     195                                                } 
     196                                                writer.addDocument(document1); 
     197                                        } 
     198                                        //TODO: choose the fieldnames automatically --> trick 
     199                                        //TODO : remove these fields 
     200                                        /* 
    169201                                        Field nameField = new Field("name", e.get("name").toString(), Field.Store.YES, Field.Index.NOT_ANALYZED); 
     202                                        System.out.println(e.get("name").toString()); 
    170203                                        document1.add(nameField); 
     204                                         
    171205                                        Field investigationField = new Field("investigation", e.get("investigation").toString(), Field.Store.YES, Field.Index.NOT_ANALYZED); 
    172206                                        document1.add(investigationField); 
    173207                                        Field descriptionField = new Field("description", e.get("description").toString(), Field.Store.YES, Field.Index.ANALYZED); 
    174208                                        document1.add(descriptionField); 
    175  
     209                   */ 
    176210                                        writer.addDocument(document1); 
    177211                                }                        
     
    193227   } 
    194228 
     229        /* Dasha 
     230        public void buildIndexAllTables(Database db) throws Exception { 
     231                 
     232                IndexWriter writer=null; 
     233                //StandardAnalyzer analyzer = null; 
     234                PorterStemAnalyzer analyzer = null; 
     235                File file = null;  
     236                 
     237                try{ 
     238                        System.out.println("Start indexing ... "); 
     239                        //get a reference to index directory file 
     240                        file = new File(LUCENE_INDEX_DIRECTORY); 
     241                        //analyzer = new StandardAnalyzer(Version.LUCENE_30); 
     242                        analyzer = new PorterStemAnalyzer(); 
     243                        //analyzer = new StandardAnalyzer(Version.LUCENE_30); 
     244                        // You can use public StandardAnalyzer(Version matchVersion, File stopwords) throws IOException adding a STOP WORD file 
     245                        writer = new IndexWriter( FSDirectory.open(file), analyzer, true, IndexWriter.MaxFieldLength.LIMITED); 
     246                         
     247                        for(Class<Entity> aClass: db.getEntityClasses()) {       
     248                                for(Entity e: (List<Entity>)db.find(aClass)) { 
     249                 
     250                                        Document document1 = new Document(); 
     251                                         
     252                                        //TODO: choose the fieldnames automatically 
     253                                        Field nameField = new Field("name", e.get("name").toString(), Field.Store.YES, Field.Index.NOT_ANALYZED); 
     254                                        document1.add(nameField); 
     255                                        Field investigationField = new Field("investigation", e.get("investigation").toString(), Field.Store.YES, Field.Index.NOT_ANALYZED); 
     256                                        document1.add(investigationField); 
     257                                        Field descriptionField = new Field("description", e.get("description").toString(), Field.Store.YES, Field.Index.ANALYZED); 
     258                                        document1.add(descriptionField); 
     259 
     260                                        writer.addDocument(document1); 
     261                                }                        
     262                        } 
     263                        //optimize the index 
     264                        System.out.println("Optimizing index"); 
     265                        writer.optimize(); 
     266                }catch(Exception e){ 
     267                        e.printStackTrace(); 
     268                }finally{ 
     269                        try{ 
     270                                if(writer!=null) 
     271                                        writer.close(); 
     272                                    System.out.println("Finished indexing"); 
     273                        }catch(Exception ex){ 
     274                                ex.printStackTrace(); 
     275                        } 
     276                } 
     277   }     
     278        */ 
     279         
    195280        public void CreateLuceneIndex(Database db) { 
    196281                this.setStatus("Start indexing "); 
Note: See TracChangeset for help on using the changeset viewer.