public Key search(Book bible, String searchText) throws BookException { // example of fetching Strongs ref - only works with downloaded indexes! // Book book = getDocumentByInitials("KJV"); // Key key1 = book.find("strong:h3068"); // System.out.println("h3068 result count:"+key1.getCardinality()); Log.d(TAG, "Searching:"+bible+" Search term:" + searchText); // This does a standard operator search. See the search // documentation for more examples of how to search Key key = bible.find(searchText); //$NON-NLS-1$ Log.d(TAG, "There are "+key.getCardinality()+" verses containing " + searchText); return key; }
/** ensure a book is indexed and the index contains typical Greek or Hebrew Strongs Numbers */ private boolean checkStrongs(Book bible) { try { return bible.getIndexStatus().equals(IndexStatus.DONE) && (bible.find("+[Gen 1:1] strong:h7225").getCardinality()>0 || bible.find("+[John 1:1] strong:g746").getCardinality()>0 || bible.find("+[Gen 1:1] strong:g746").getCardinality()>0); } catch (BookException be) { Log.e(TAG, "Error checking strongs numbers", be); return false; } }
/** * An example of how to search for various bits of data. * * @throws BookException */ public void search() throws BookException { Book bible = Books.installed().getBook(BIBLE_NAME); // This does a standard operator search. See the search documentation // for more examples of how to search Key key = bible.find("+moses +aaron"); System.out.println("The following verses contain both moses and aaron: " + key.getName()); // You can also trim the result to a more manageable quantity. // The test here is not necessary since we are working with a bible. It // is necessary if we don't know what it // is. if (key instanceof Passage) { Passage remaining = ((Passage) key).trimVerses(5); System.out.println("The first 5 verses containing both moses and aaron: " + key.getName()); if (remaining != null) { System.out.println("The rest of the verses are: " + remaining.getName()); } else { System.out.println("There are only 5 verses containing both moses and aaron"); } } }
/** * An example of how to do a search and then get text for each range of * verses. * * @throws BookException * @throws SAXException */ void searchAndShow() throws BookException, SAXException { Book bible = Books.installed().getBook(BIBLE_NAME); // Search for words like Melchezedik Key key = bible.find("melchesidec~"); // Here is an example of how to iterate over the ranges and get the text // for each. // The key's iterator would have iterated over verses. // The following shows how to use a stylesheet of your own choosing String path = "org/crosswire/jsword/xml/html5.xsl"; URL xslurl = ResourceUtil.getResource(path); // Make ranges break on chapter Iterator<VerseRange> rangeIter = ((Passage) key).rangeIterator(RestrictionType.CHAPTER); // boundaries. while (rangeIter.hasNext()) { Key range = rangeIter.next(); BookData data = new BookData(bible, range); SAXEventProvider osissep = data.getSAXEventProvider(); SAXEventProvider htmlsep = new TransformingSAXEventProvider(NetUtil.toURI(xslurl), osissep); String text = XMLUtil.writeToString(htmlsep); System.out.println("The html text of " + range.getName() + " is " + text); } }
/** * Get a reference list for a search result against a book. * * @param bookInitials * @param searchRequest * @return The reference for the matching. * @throws BookException */ public String search(String bookInitials, String searchRequest) throws BookException { Book book = BookInstaller.getInstalledBook(bookInitials); if (isBookIndexed(book) && searchRequest != null) { if (BookCategory.BIBLE.equals(book.getBookCategory())) { BookName.setFullBookName(false); } return book.find(searchRequest).getName(); } return ""; }
modifier.setMaxResults(max); Key results = bible.find(new DefaultSearchRequest("for god so loved the world", modifier)); int total = results.getCardinality(); int partial = total;
public void testFindAllStrongsRef() { List<Book> bibles = Books.installed().getBooks(BookFilters.getBibles()); for (Book book : bibles) { try { if (book.hasFeature(FeatureType.STRONGS_NUMBERS)) { if (!book.getIndexStatus().equals(IndexStatus.DONE)) { System.out.println("Unindexed:"+book); } else { Key resultsH = book.find("+[Gen 1:1] strong:h7225"); //beginning Key resultsG = book.find("+[John 1:1] strong:g746"); //beginning Key resultsGOT = book.find("+[Gen 1:1] strong:g746"); //beginning if (resultsH.getCardinality()==0 && resultsG.getCardinality()==0 && resultsGOT.getCardinality()==0) { System.out.println("No refs returned in"+book.getInitials()); } else { System.out.println("Ok:"+book.getInitials()+" "+resultsH.getCardinality()+"/"+resultsG.getCardinality()+ "/" + resultsGOT.getCardinality()); } // assertTrue("No refs returned in"+book.getInitials(), resultsH.getCardinality()>0 || resultsG.getCardinality()>0); } } } catch (Exception e) { System.out.println("Error:"+book.getInitials()+":"+e.getMessage()); } } }