| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| LuceneSearcher |
|
| 1.0;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 | package org.crosswire.jsword.index.lucene; | |
| 20 | ||
| 21 | import org.crosswire.jsword.book.BookException; | |
| 22 | import org.crosswire.jsword.index.Index; | |
| 23 | import org.crosswire.jsword.index.query.Query; | |
| 24 | import org.crosswire.jsword.index.query.QueryBuilderFactory; | |
| 25 | import org.crosswire.jsword.index.search.DefaultSearchRequest; | |
| 26 | import org.crosswire.jsword.index.search.SearchRequest; | |
| 27 | import org.crosswire.jsword.index.search.Searcher; | |
| 28 | import org.crosswire.jsword.passage.Key; | |
| 29 | ||
| 30 | /** | |
| 31 | * The central interface to all searching. | |
| 32 | * | |
| 33 | * Functionality the I envisage includes: | |
| 34 | * <ul> | |
| 35 | * <li>A simple search syntax that goes something like this. | |
| 36 | * <ul> | |
| 37 | * <li>aaron, moses (verses containing aaron and moses. Can also use & or +) | |
| 38 | * <li>aaron/moses (verses containing aaron or moses. Can also use |) | |
| 39 | * <li>aaron - moses (verses containing aaron but not moses) | |
| 40 | * <li>aaron ~5 , moses (verses with aaron within 5 verses of moses) | |
| 41 | * <li>soundslike aaron (verses with words that sound like aaron. Can also use | |
| 42 | * sl ...) | |
| 43 | * <li>thesaurus happy (verses with words that mean happy. Can also use th ...) | |
| 44 | * <li>grammar have (words like has have had and so on. Can also use gr ...) | |
| 45 | * </ul> | |
| 46 | * <li>The ability to add soundslike type extensions. | |
| 47 | * </ul> | |
| 48 | * | |
| 49 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
| 50 | * @author Joe Walker | |
| 51 | */ | |
| 52 | 0 | public class LuceneSearcher implements Searcher { |
| 53 | /* | |
| 54 | * (non-Javadoc) | |
| 55 | * | |
| 56 | * @see | |
| 57 | * org.crosswire.jsword.index.search.Searcher#init(org.crosswire.jsword. | |
| 58 | * index.search.Index) | |
| 59 | */ | |
| 60 | public void init(Index newindex) { | |
| 61 | 0 | this.index = newindex; |
| 62 | 0 | } |
| 63 | ||
| 64 | /* | |
| 65 | * (non-Javadoc) | |
| 66 | * | |
| 67 | * @see org.crosswire.jsword.index.search.Searcher#search(java.lang.String) | |
| 68 | */ | |
| 69 | public Key search(String request) throws BookException { | |
| 70 | 0 | return search(new DefaultSearchRequest(request)); |
| 71 | } | |
| 72 | ||
| 73 | /* | |
| 74 | * (non-Javadoc) | |
| 75 | * | |
| 76 | * @see | |
| 77 | * org.crosswire.jsword.index.search.Searcher#search(org.crosswire.jsword | |
| 78 | * .index.search.SearchRequest) | |
| 79 | */ | |
| 80 | public Key search(SearchRequest request) throws BookException { | |
| 81 | 0 | index.setSearchModifier(request.getSearchModifier()); |
| 82 | 0 | Query query = QueryBuilderFactory.getQueryBuilder().parse(request.getRequest()); |
| 83 | 0 | Key results = search(query); |
| 84 | 0 | index.setSearchModifier(null); |
| 85 | 0 | return results; |
| 86 | } | |
| 87 | ||
| 88 | /* | |
| 89 | * (non-Javadoc) | |
| 90 | * | |
| 91 | * @see | |
| 92 | * org.crosswire.jsword.index.search.Searcher#search(org.crosswire.jsword | |
| 93 | * .index.query.Query) | |
| 94 | */ | |
| 95 | public Key search(Query query) throws BookException { | |
| 96 | 0 | return query.find(index); |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Accessor for the Bible to search. | |
| 101 | * | |
| 102 | * @return The current Bible | |
| 103 | */ | |
| 104 | protected Index getIndex() { | |
| 105 | 0 | return index; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * The index | |
| 110 | */ | |
| 111 | private Index index; | |
| 112 | } |