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; }
/** * 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(); }
.setPhraseQuery(new TextFieldElements().addTitle(), phrase) .setNumHits(maxPages * DOC_MULTIPLIER) .search(); .setPhraseQuery(new TextFieldElements().addPlainText(), phrase) .setNumHits(maxPages * DOC_MULTIPLIER) .search();
/** * Returns the name of the text field representing only the title, once. * * @return */ public static String getTitleFieldName() { return new TextFieldElements().addTitle().getTextFieldName(); }
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); } }
private TextField buildTextField(LocalPage localPage, RawPage rawPage, TextFieldElements elements) throws DaoException { StringBuilder sb = new StringBuilder(); String title = rawPage.getTitle().getCanonicalTitle(); for (int i=0; i<elements.usesTitle(); i++) { sb.append(title); sb.append(" "); } if (elements.usesRedirects()) { TIntIterator iterator = redirectDao.getRedirects(localPage).iterator(); while (iterator.hasNext()) { sb.append(localPageDao .getById(localPage.getLanguage(), iterator.next()) .getTitle() .getCanonicalTitle()); sb.append(" "); } } if (elements.usesPlainText()) { String plainText = rawPage.getPlainText(); sb.append(plainText); } return new TextField(elements.getTextFieldName(), sb.toString().trim(), Field.Store.YES); }
/** * Builds a phrase query over the text field specified by elements. * * @param elements specifies the text field in which to search * @param searchString * @return */ public QueryBuilder setPhraseQuery(TextFieldElements elements, String searchString) { return setPhraseQuery(elements.getTextFieldName(), searchString); }
@Override public boolean equals(Object o) { if (!(o instanceof LuceneOptions)) return false; LuceneOptions opts = (LuceneOptions) o; return (this.name.equalsIgnoreCase(opts.name) && this.matchVersion == opts.matchVersion && this.luceneRoot.equals(opts.luceneRoot) && CollectionUtils.isEqualCollection(this.namespaces, opts.namespaces) && this.options.equals(opts.options) && this.elements.equals(opts.elements)); }
/** * Builds a MoreLikeThis query for the specified luceneId over the * text field specified by the TextFieldElements. * * @param elements * @param luceneId * @return * @throws DaoException */ public QueryBuilder setMoreLikeThisQuery(TextFieldElements elements, int luceneId) throws DaoException { return setMoreLikeThisQuery(elements.getTextFieldName(), luceneId); }