public SearchItem toResult(int documentId) throws IOException { Document document = searcher.doc(documentId); String type = document.getFieldable(FieldNames.TYPE).stringValue(); NumericField date = (NumericField)document.getFieldable(FieldNames.DATE); Fieldable path = document.getFieldable(FieldNames.PATH); NumericField version = (NumericField)document.getFieldable(FieldNames.VERSION); return new SearchItem ( Integer.parseInt(type), path.stringValue(), (version != null) ? version.getNumericValue().intValue() : -1, new Date(date.getNumericValue().longValue()) ); }
/** * The raw (field type encoded) value of the Unique Key field for * the specified Document * @return null if this schema has no unique key field * @see #printableUniqueKey */ public Fieldable getUniqueKeyField(org.apache.lucene.document.Document doc) { return doc.getFieldable(uniqueKeyFieldName); // this should return null if name is null }
@Override protected Fieldable featureValueOf(final Document actual) { return actual.getFieldable(fieldName); } }
for (ScoreDoc sd : topDocs.scoreDocs) { if (sd.doc == Integer.MAX_VALUE) break; final Document d = searcher.doc(sd.doc); final Fieldable f = d.getFieldable(name); ... }
public static String getSimpleName(final Document doc) { final Fieldable field = doc.getFieldable(FIELD_SIMPLE_NAME); return field == null ? null : field.stringValue(); }
public static String getSimpleBinaryName (final Document doc) { assert doc != null; Fieldable field = doc.getFieldable(FIELD_BINARY_NAME); if (field == null) { return null; } else { final String binName = field.stringValue(); return binName.substring(0, binName.length()-1); } }
/** * The printable value of the Unique Key field for * the specified Document * @return null if this schema has no unique key field */ public String printableUniqueKey(org.apache.lucene.document.Document doc) { Fieldable f = doc.getFieldable(uniqueKeyFieldName); return f==null ? null : uniqueKeyFieldType.toExternal(f); }
public void found(Document d) { ids.add(Integer.valueOf(d.getFieldable("ID").stringValue())); } });
public static boolean isLocal(@NonNull final Document doc) { Fieldable fld = doc.getFieldable(FIELD_BINARY_NAME); if (fld == null) { return false; } else { final String binName = fld.stringValue(); switch (binName.charAt(binName.length()-1)) { case EK_LOCAL_ANNOTATION: case EK_LOCAL_CLASS: case EK_LOCAL_ENUM: case EK_LOCAL_INTERFACE: return true; default: return false; } } }
@Override public Object get(String name, Document document) { LegacyPk id = new LegacyPk(); id.setCode(document.getFieldable(name + ".code").stringValue()); id.setDept(Integer.valueOf(document.getFieldable(name + ".dept").stringValue())); id.setName(document.getFieldable(name + ".name").stringValue()); return id; }
private InteractionOntologyTerm createOntologyTerm(Document document, Highlighter highlighter) throws IOException { String identifier = document.getFieldable("identifier").stringValue(); String label = document.getFieldable("label").stringValue(); String databaseLabel = document.getFieldable("databaseLabel").stringValue(); String fieldName = document.getFieldable("fieldName").stringValue(); int count = Integer.parseInt(document.getField("count").stringValue()); if (isHighlight()) { label = highlightText("label", label, highlighter); } InteractionOntologyTerm term = new InteractionOntologyTerm(label, identifier); term.setResults(new InteractionOntologyTermResults(databaseLabel, fieldName, count)); return term; }
@Override public void execute() { try { IndexWriter w = getIndexWriter(); for (Document document: getDocuments()){ switch(getOperation()){ case ADD: w.addDocument(document); break; case MODIFY: w.deleteDocuments(new Term("ID",document.getFieldable("ID").stringValue())); w.addDocument(document); break; case DELETE: w.deleteDocuments(new Term("ID",document.getFieldable("ID").stringValue())); break; } } w.close(false); }catch (Exception ex){ throw new RuntimeException(ex); } }
/** * Checks if the OpenCms resource referenced by the result document can be read * be the user of the given OpenCms context.<p> * * @param cms the OpenCms user context to use for permission testing * @param doc the search result document to check * @return <code>true</code> if the user has read permissions to the resource */ protected boolean hasReadPermission(CmsObject cms, Document doc) { if (!isCheckingPermissions()) { // no permission check is performed at all return true; } Fieldable typeField = doc.getFieldable(CmsSearchField.FIELD_TYPE); Fieldable pathField = doc.getFieldable(CmsSearchField.FIELD_PATH); if ((typeField == null) || (pathField == null)) { // permission check needs only to be performed for VFS documents that contain both fields return true; } return hasReadPermission(cms, typeField.stringValue(), pathField.stringValue()); }
protected String getDocClass(int doc) throws IOException { Document d = indexReader.document(doc); Fieldable f = d.getFieldable(categoryFieldName); if (f == null) return null; if (!f.isStored()) throw new IllegalArgumentException("Field " + f.name() + " is not stored."); return f.stringValue(); }
/** * {@inheritDoc} * * @see org.apache.lucene.search.Collector#collect(int) */ public void collect(final int doc) throws IOException { final org.apache.lucene.document.Document luceneDocument = searcher.doc(doc); final LuceneDocument.Builder builder = new LuceneDocument.Builder(); builder.setTitle(luceneDocument.getFieldable("title").stringValue()); builder.setPath(luceneDocument.getFieldable("path").stringValue()); builder.setScore(scorer.score()); documents.add(builder.build()); }
Person[] searchPeople(String keyword) { if (disableLucene || keyword.length() < 1) { return Pooler.EMPTY_PERSON_ARRAY; } BooleanQuery query = generateQueryTerms(keyword, nameFieldList, 0); System.out.println("People Terms: " + query); int MAX_SEARCH_RESULTS = Sage.getInt("wizard/max_search_results", 1000); try { LuceneIndex searchIndex = getPersonIndex(); IndexReader reader = searchIndex.getReader(); IndexSearcher searcher = searchIndex.getSearcher(); TopDocs search = searcher.search(query, MAX_SEARCH_RESULTS); Person[] peeps = new Person[search.scoreDocs.length]; for (int i = 0; i < search.scoreDocs.length; i++) { Document doc = searcher.doc(search.scoreDocs[i].doc); int id = Integer.parseInt(doc.getFieldable("id").stringValue()); peeps[i] = getPersonForID(id); } return peeps; } catch( Exception e) { if (Sage.DBG) System.out.println("Bad things while searching: " + e); e.printStackTrace(); } return Pooler.EMPTY_PERSON_ARRAY; } }
for (int i = 0; i < search.scoreDocs.length; i++) { Document doc = searcher.doc(search.scoreDocs[i].doc); int showID = Integer.parseInt(doc.getFieldable("id").stringValue()); shows[i] = getShowForID(showID);
/** * Checks if the document is in the time range specified in the search parameters.<p> * * The creation date and/or the last modification date are checked.<p> * * @param doc the document to check the dates against the given time range * @param params the search parameters where the time ranges are specified * * @return true if document is in time range or not time range set otherwise false */ protected boolean isInTimeRange(Document doc, CmsSearchParameters params) { if (!isCheckingTimeRange()) { // time range check disabled return true; } try { Date dateCreated = DateTools.stringToDate(doc.getFieldable(CmsSearchField.FIELD_DATE_CREATED).stringValue()); Date dateLastModified = DateTools.stringToDate(doc.getFieldable(CmsSearchField.FIELD_DATE_LASTMODIFIED).stringValue()); return isInTimeRange(dateCreated, dateLastModified, params); } catch (ParseException ex) { // date could not be parsed -> doc is in time range } return true; }
/** * {@inheritDoc} */ @Override protected Object getFieldRaw(String name) { Fieldable fieldable = this.document.getFieldable(name); if (fieldable == null) { return null; } // actually lucene will always return a regular field, but this might change if (fieldable instanceof NumericField) { return ((NumericField) fieldable).getNumericValue(); } SearchFieldConfiguration fieldConfiguration = getSearchFields().getFieldConfiguration(name); if (fieldConfiguration != null) { if (fieldConfiguration.getType() == SearchFieldType.DATE) { // we do not want to convert from string to string on higher level! return Long.valueOf(fieldable.stringValue()); } } return fieldable.stringValue(); }
public DocListAndSet getMoreLikeThis( int id, int start, int rows, List<Query> filters, List<InterestingTerm> terms, int flags ) throws IOException { Document doc = reader.document(id); mltquery = mlt.like(id); setBoosts(mltquery); if( terms != null ) { fillInterestingTermsFromMLTQuery( mltquery, terms ); } // exclude current document from results BooleanQuery mltQuery = new BooleanQuery(); mltQuery.add(mltquery, BooleanClause.Occur.MUST); mltQuery.add( new TermQuery(new Term(uniqueKeyField.getName(), uniqueKeyField.getType().storedToIndexed(doc.getFieldable(uniqueKeyField.getName())))), BooleanClause.Occur.MUST_NOT); DocListAndSet results = new DocListAndSet(); if (this.needDocSet) { results = searcher.getDocListAndSet(mltQuery, filters, null, start, rows, flags); } else { results.docList = searcher.getDocList(mltQuery, filters, null, start, rows, flags); } return results; }