Coverage Report - org.apache.maven.index.IndexerField
 
Classes in this File Line Coverage Branch Coverage Complexity
IndexerField
91 %
22/24
60 %
6/10
1,167
 
 1  
 package org.apache.maven.index;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0    
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.lucene.document.Field;
 23  
 import org.apache.lucene.document.Field.Index;
 24  
 import org.apache.lucene.document.Field.Store;
 25  
 import org.apache.lucene.document.Field.TermVector;
 26  
 
 27  
 /**
 28  
  * Holds basic information about Indexer field, how it is stored. To keep this centralized, and not spread across code.
 29  
  * Since Lucene 2.x, the field names are encoded, so please use real chatty names instead of cryptic chars!
 30  
  * 
 31  
  * @author cstamas
 32  
  */
 33  
 public class IndexerField
 34  
 {
 35  
     private final org.apache.maven.index.Field ontology;
 36  
 
 37  
     private final IndexerFieldVersion version;
 38  
 
 39  
     private final String key;
 40  
 
 41  
     private final Store storeMethod;
 42  
 
 43  
     private final Index indexMethod;
 44  
 
 45  
     private final TermVector termVector;
 46  
 
 47  
     public IndexerField( final org.apache.maven.index.Field ontology, final IndexerFieldVersion version,
 48  
                          final String key, final String description, final Store storeMethod, final Index indexMethod )
 49  
     {
 50  29
         this( ontology, version, key, description, storeMethod, indexMethod, null );
 51  29
     }
 52  
 
 53  
     public IndexerField( final org.apache.maven.index.Field ontology, final IndexerFieldVersion version,
 54  
                          final String key, final String description, final Store storeMethod, final Index indexMethod,
 55  
                          final TermVector termVector )
 56  29
     {
 57  29
         this.ontology = ontology;
 58  
 
 59  29
         this.version = version;
 60  
 
 61  29
         this.key = key;
 62  
 
 63  29
         this.storeMethod = storeMethod;
 64  
 
 65  29
         this.indexMethod = indexMethod;
 66  
 
 67  29
         this.termVector = termVector;
 68  
 
 69  29
         ontology.addIndexerField( this );
 70  29
     }
 71  
 
 72  
     public org.apache.maven.index.Field getOntology()
 73  
     {
 74  4611
         return ontology;
 75  
     }
 76  
 
 77  
     public IndexerFieldVersion getVersion()
 78  
     {
 79  0
         return version;
 80  
     }
 81  
 
 82  
     public String getKey()
 83  
     {
 84  361116
         return key;
 85  
     }
 86  
 
 87  
     public Field.Store getStoreMethod()
 88  
     {
 89  288696
         return storeMethod;
 90  
     }
 91  
 
 92  
     public Field.Index getIndexMethod()
 93  
     {
 94  288696
         return indexMethod;
 95  
     }
 96  
 
 97  
     public Field.TermVector getTermVector()
 98  
     {
 99  288696
         return termVector;
 100  
     }
 101  
 
 102  
     public boolean isIndexed()
 103  
     {
 104  19123
         return !Index.NO.equals( indexMethod );
 105  
     }
 106  
 
 107  
     public boolean isKeyword()
 108  
     {
 109  14290
         return isIndexed() && !Index.ANALYZED.equals( indexMethod );
 110  
     }
 111  
 
 112  
     public boolean isStored()
 113  
     {
 114  2
         return !( Store.NO.equals( storeMethod ) );
 115  
     }
 116  
 
 117  
     public Field toField( String value )
 118  
     {
 119  
         Field result;
 120  
 
 121  288696
         if ( getTermVector() != null )
 122  
         {
 123  0
             result = new Field( getKey(), value, getStoreMethod(), getIndexMethod(), getTermVector() );
 124  
         }
 125  
         else
 126  
         {
 127  288696
             result = new Field( getKey(), value, getStoreMethod(), getIndexMethod() );
 128  
         }
 129  
 
 130  
         // if ( isKeyword() )
 131  
         // {
 132  
         // result.setOmitNorms( true );
 133  
         // result.setOmitTf( true );
 134  
         // }
 135  
 
 136  288696
         return result;
 137  
     }
 138  
 }