@Override public void collect(int docId) throws IOException { Document doc = searcher.doc(docBase + docId); try { Key key = VerseFactory.fromString(v11n, doc.get(LuceneIndex.FIELD_KEY)); results.addAll(key); } catch (NoSuchVerseException e) { // Wrap the NoSuchVerseException in an IOException so it can be // gotten. IOException ioe = new IOException(); ioe.initCause(e); throw ioe; // JDK6: Change to: // throw new IOException(e); } }
public void retainAll(Key key) { Key shared = new DefaultKeyList(); shared.addAll(key); retain(this, shared); }
/** * Cast a Key to a Passage. Only those keys that are a Passage or can * be held by a Passage (i.e. Verse and VerseRange) may be cast to one. * If you pass a null key into this method, you get a null Passage out. * * @param key The key to cast * @return The key cast to a Passage * @throws ClassCastException */ public static Passage getPassage(Key key) { if (key == null) { return null; } if (key instanceof Passage) { return (Passage) key; } if (key instanceof VerseKey) { VerseKey verseKey = (VerseKey) key; Key ref = PassageKeyFactory.instance().createEmptyKeyList(verseKey.getVersification()); ref.addAll(verseKey); return (Passage) ref; } throw new ClassCastException("Expected key to be a Verse, VerseRange or Passage"); }
public Key find(Index index) throws BookException { Key left = getLeftQuery().find(index); Key right = getRightQuery().find(index); if (left.isEmpty()) { return right; } if (right.isEmpty()) { return left; } // If ranking was requested then prioritize it. if (right instanceof PassageTally) { right.addAll(left); return right; } left.addAll(right); return left; } }
public final Key getGlobalKeyList() { if (global == null) { try { global = getBackend().getGlobalKeyList(); return global; } catch (UnsupportedOperationException ex) { // fail silently, operation not supported by the backend log.debug(ex.getMessage()); } catch (BookException ex) { // failing silently, as previous behavior was to attempt to // return as much as we can using the slower method log.debug(ex.getMessage()); } Versification v11n = super.getVersification(); global = super.createEmptyKeyList(); Key all = PassageKeyFactory.instance().getGlobalKeyList(v11n); for (Key key : all) { if (contains(key)) { global.addAll(key); } } } return global; }
/** * A helper function to recursively read the entire tree. * * @param parentNode * the current node whose children are being sought * @param parentKey * @throws IOException */ private void doReadIndex(TreeNode parentNode, Key parentKey) throws IOException { TreeNode currentNode = parentNode; if (currentNode.hasChildren()) { TreeNode childNode = index.getFirstChild(currentNode); do { TreeKey childKey = new TreeKey(childNode.getName(), parentKey); parentKey.addAll(childKey); // Build the tree as deep as possible doReadIndex(childNode, childKey); if (!childNode.hasNextSibling()) { break; } childNode = index.getNextSibling(childNode); } while (true); } }
/** * A space separate string containing osisID from the reference element. * We pass book and key because the xref may not be valid and it needs to be reported. * * @param book the book to which the references refer * @param key the verse containing the cross references * @param v11n the versification * @param root the osis element in question * @return The references in the text */ public static String getReferences(Book book, Key key, Versification v11n, Element root) { PassageKeyFactory keyf = PassageKeyFactory.instance(); Key collector = keyf.createEmptyKeyList(v11n); for (Content content : getDeepContent(root, OSISUtil.OSIS_ELEMENT_REFERENCE)) { Element ele = (Element) content; String attr = ele.getAttributeValue(OSISUtil.OSIS_ATTR_REF); if (attr != null) { try { collector.addAll(keyf.getKey(v11n, attr)); } catch (NoSuchKeyException e) { DataPolice.report(book, key, "Unable to parse: " + attr + " - No such reference:" + e.getMessage()); } } } return collector.getOsisID(); }
break; key.addAll(aKey);
break; key.addAll(aKey);