/** * Returns the name of the text field representing only the plain text. * * @return */ public static String getPlainTextFieldName() { return new TextFieldElements().addPlainText().getTextFieldName(); }
/** * Returns the name of the text field representing only redirected titles. * * @return */ public static String getRedirectsFieldName() { return new TextFieldElements().addRedirects().getTextFieldName(); }
/** * Returns the name of the text field representing only the title, once. * * @return */ public static String getTitleFieldName() { return new TextFieldElements().addTitle().getTextFieldName(); }
private static TextFieldElements buildElements(int title, boolean redirects, boolean plainText) { TextFieldElements elements = new TextFieldElements(); elements.addTitle(title); if (redirects) elements.addRedirects(); if (plainText) elements.addPlainText(); return elements; }
private LinkedHashMap<LocalId, Float> resolveTextual(String phrase, int n) { if (n == 0) { return new LinkedHashMap<LocalId, Float>(); } WikiBrainScoreDoc results[] = searcher.getQueryBuilderByLanguage(language) .setPhraseQuery(new TextFieldElements().addPlainText(), phrase) .setNumHits(n*2) .search(); double total = 0.0; for (WikiBrainScoreDoc doc : results) { total += doc.score; } LinkedHashMap<LocalId, Float> expanded = new LinkedHashMap<LocalId, Float>(); for (int i = 0; i < n && i < results.length; i++) { expanded.put(new LocalId(language, results[i].wpId), (float)(results[i].score / total)); } return expanded; }
/** * Indexes a specific RawPage * * @param page the page to index */ public void indexPage(RawPage page) throws DaoException { if (closed) { throw new IllegalStateException("Indexer has already been closed!"); } if (!language.equals(page.getLanguage())) { throw new IllegalStateException("Language mismatch!"); } try { Document document = new Document(); Field localIdField = new IntField(LuceneOptions.LOCAL_ID_FIELD_NAME, page.getLocalId(), Field.Store.YES); Field langIdField = new IntField(LuceneOptions.LANG_ID_FIELD_NAME, page.getLanguage().getId(), Field.Store.YES); Field canonicalTitleField = builder.buildTextField(page, new TextFieldElements().addTitle()); document.add(localIdField); document.add(langIdField); document.add(canonicalTitleField); if (!page.isRedirect()) { for (LuceneOptions option : options) { document.add(builder.buildTextField(page, option.elements)); } } writer.addDocument(document); } catch (IOException e) { throw new RuntimeException(e); } }
.setPhraseQuery(new TextFieldElements().addTitle(), phrase) .setNumHits(maxPages * DOC_MULTIPLIER) .search(); .setPhraseQuery(new TextFieldElements().addPlainText(), phrase) .setNumHits(maxPages * DOC_MULTIPLIER) .search();