Coverage Report - org.crosswire.jsword.index.lucene.LuceneQueryDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
LuceneQueryDecorator
0%
0/31
N/A
1
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2005 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.index.lucene;
 21  
 
 22  
 import org.crosswire.common.util.StringUtil;
 23  
 import org.crosswire.jsword.index.query.QueryDecorator;
 24  
 
 25  
 /**
 26  
  * LuceneQueryDecorator represents the extension of stock Lucene syntax with
 27  
  * passage ranges and with blurring (searching in nearby verses).
 28  
  * 
 29  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 30  
  * @author DM Smith
 31  
  */
 32  0
 public class LuceneQueryDecorator implements QueryDecorator {
 33  
     /*
 34  
      * (non-Javadoc)
 35  
      * 
 36  
      * @see
 37  
      * org.crosswire.jsword.index.search.SearchSyntax#decorateAllWords(java.
 38  
      * lang.String)
 39  
      */
 40  
     public String decorateAllWords(String queryWords) {
 41  0
         String[] words = queryWords.split(SPACE);
 42  0
         StringBuilder search = new StringBuilder();
 43  0
         search.append(PLUS);
 44  0
         search.append(StringUtil.join(words, SPACE_PLUS));
 45  0
         return search.toString();
 46  
     }
 47  
 
 48  
     /*
 49  
      * (non-Javadoc)
 50  
      * 
 51  
      * @see
 52  
      * org.crosswire.jsword.index.search.SearchSyntax#decorateAnyWords(java.
 53  
      * lang.String)
 54  
      */
 55  
     public String decorateAnyWords(String queryWords) {
 56  
         // Don't need to do anything, this is the default behavior
 57  0
         return queryWords;
 58  
     }
 59  
 
 60  
     /*
 61  
      * (non-Javadoc)
 62  
      * 
 63  
      * @see
 64  
      * org.crosswire.jsword.index.search.SearchSyntax#decoratePhrase(java.lang
 65  
      * .String)
 66  
      */
 67  
     public String decoratePhrase(String queryWords) {
 68  
         // This performs a best match
 69  0
         StringBuilder search = new StringBuilder();
 70  0
         search.append(QUOTE);
 71  0
         search.append(queryWords);
 72  0
         search.append(QUOTE);
 73  0
         return search.toString();
 74  
     }
 75  
 
 76  
     /*
 77  
      * (non-Javadoc)
 78  
      * 
 79  
      * @see
 80  
      * org.crosswire.jsword.index.search.SearchSyntax#decorateNotWords(java.
 81  
      * lang.String)
 82  
      */
 83  
     public String decorateNotWords(String queryWords) {
 84  0
         String[] words = queryWords.split(SPACE);
 85  0
         StringBuilder search = new StringBuilder();
 86  0
         search.append(MINUS);
 87  0
         search.append(StringUtil.join(words, SPACE_MINUS));
 88  0
         return search.toString();
 89  
     }
 90  
 
 91  
     /*
 92  
      * (non-Javadoc)
 93  
      * 
 94  
      * @see
 95  
      * org.crosswire.jsword.index.search.SearchSyntax#decorateRange(java.lang
 96  
      * .String)
 97  
      */
 98  
     public String decorateRange(String queryWords) {
 99  0
         StringBuilder search = new StringBuilder();
 100  0
         search.append(PLUS);
 101  0
         search.append(OPEN);
 102  0
         search.append(queryWords);
 103  0
         search.append(CLOSE);
 104  0
         return search.toString();
 105  
     }
 106  
 
 107  
     /*
 108  
      * (non-Javadoc)
 109  
      * 
 110  
      * @see
 111  
      * org.crosswire.jsword.index.search.SearchSyntax#decorateSpellWords(java
 112  
      * .lang.String)
 113  
      */
 114  
     public String decorateSpellWords(String queryWords) {
 115  0
         String[] words = queryWords.split(SPACE);
 116  0
         StringBuilder search = new StringBuilder(StringUtil.join(words, FUZZY_SPACE));
 117  0
         search.append(FUZZY);
 118  0
         return search.toString();
 119  
     }
 120  
 
 121  
     /*
 122  
      * (non-Javadoc)
 123  
      * 
 124  
      * @see
 125  
      * org.crosswire.jsword.index.search.SearchSyntax#decorateStartWords(java
 126  
      * .lang.String)
 127  
      */
 128  
     public String decorateStartWords(String queryWords) {
 129  0
         String[] words = queryWords.split(SPACE);
 130  0
         StringBuilder search = new StringBuilder(StringUtil.join(words, WILD_SPACE));
 131  0
         search.append(WILD);
 132  0
         return search.toString();
 133  
     }
 134  
 
 135  
     /**
 136  
      * In our parsing we use space quite a lot and this ensures there is only one.
 137  
      */
 138  
     private static final String SPACE = " ";
 139  
     private static final char QUOTE = '"';
 140  
     private static final char PLUS = '+';
 141  
     private static final String SPACE_PLUS = " +";
 142  
 
 143  
     private static final char MINUS = '-';
 144  
     private static final String SPACE_MINUS = " -";
 145  
 
 146  
     private static final char OPEN = '[';
 147  
     private static final char CLOSE = ']';
 148  
 
 149  
     private static final char FUZZY = '~';
 150  
     private static final String FUZZY_SPACE = "~ ";
 151  
 
 152  
     private static final char WILD = '*';
 153  
     private static final String WILD_SPACE = "* ";
 154  
 
 155  
 }