/** * Returns the Lucene document with the given root path from the index.<p> * * @param rootPath the root path of the document to get * * @return the Lucene document with the given root path from the index */ public Document getDocument(String rootPath) { Document result = null; IndexSearcher searcher = getSearcher(); if (searcher != null) { // search for an exact match on the document root path Term pathTerm = new Term(CmsSearchField.FIELD_PATH, rootPath); try { TopDocs hits = searcher.search(new TermQuery(pathTerm), 1); if (hits.scoreDocs.length > 0) { result = searcher.doc(hits.scoreDocs[0].doc); } } catch (IOException e) { // ignore, return null and assume document was not found } } return result; }
/** * Returns a document by document ID.<p> * * @param docId the id to get the document for * * @return the CMS specific document */ public I_CmsSearchDocument getDocument(int docId) { try { IndexSearcher searcher = getSearcher(); return new CmsLuceneDocument(searcher.doc(docId)); } catch (IOException e) { // ignore, return null and assume document was not found } return null; }
/** * Returns the first document where the given term matches the selected index field.<p> * * Use this method to search for documents which have unique field values, like a unique id.<p> * * @param field the field to search in * @param term the term to search for * * @return the first document where the given term matches the selected index field */ public I_CmsSearchDocument getDocument(String field, String term) { Document result = null; IndexSearcher searcher = getSearcher(); if (searcher != null) { // search for an exact match on the selected field Term resultTerm = new Term(field, term); try { TopDocs hits = searcher.search(new TermQuery(resultTerm), 1); if (hits.scoreDocs.length > 0) { result = searcher.doc(hits.scoreDocs[0].doc); } } catch (IOException e) { // ignore, return null and assume document was not found } } if (result != null) { return new CmsLuceneDocument(result); } return null; }
booleanFieldsQuery.add(shouldOccur, BooleanClause.Occur.MUST); fieldsQuery = getSearcher().rewrite(booleanFieldsQuery); } else if ((params.getFields() != null) && (params.getFields().size() > 0)) { booleanFieldsQuery.add(p.parse(params.getQuery()), BooleanClause.Occur.SHOULD); fieldsQuery = getSearcher().rewrite(booleanFieldsQuery); } else { fieldsQuery = getSearcher().rewrite(p.parse(params.getQuery())); categoryCollector = new CmsSearchCategoryCollector(getSearcher()); getSearcher().search(query, filter, categoryCollector); hits = getSearcher().search(query, filter, m_maxHits); } else { hits = getSearcher().search(query, filter, m_maxHits, params.getSort()); for (int i = 0, cnt = 0; (i < hitCount) && (cnt < end); i++) { try { doc = getSearcher().doc(hits.scoreDocs[i].doc); if ((isInTimeRange(doc, params)) && (hasReadPermission(searchCms, doc))) {
IndexSearcher searcher = getSearcher();