List of usage examples for org.apache.lucene.document StoredField StoredField
public StoredField(String name, double value)
From source file:com.flycode.CRIBSearch.SearchEngine.IndexDB.java
public static void updateOwnerDoc(Owner data) { try {/*from w ww .j a va2 s . com*/ Document doc = new Document(); doc.add(new StoredField("id", data.getId())); doc.add(new TextField("firstName", data.getFirst(), null)); doc.add(new TextField("secondName", data.getSecond(), null)); doc.add(new TextField("surname", data.getSurname(), null)); doc.add(new IntPoint("tell", data.getTell())); doc.add(new IntPoint("nationalID", data.getNational_id())); doc.add(new TextField("bio", data.getBio(), null)); doc.add(new IntPoint("Owner Id", data.getOwner_id())); new Build().create().updateDoc(doc, "id", String.valueOf(data.getId())); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.flycode.CRIBSearch.SearchEngine.SearchDocument.java
public void addBuildingDocs() { try {//from w w w . j a v a 2 s . c o m ResultSet rs = p.selectTable("building"); while (rs.next()) { Document doc = new Document(); doc.add(new StoredField("id", rs.getString(1))); doc.add(new TextField("name", rs.getString(2), null)); doc.add(new TextField("ownerName", rs.getString(3), null)); doc.add(new StringField("license", rs.getString(4), null)); doc.add(new TextField("location", rs.getString(5), null)); doc.add(new IntPoint("NoOfRooms", Integer.parseInt(rs.getString(6)))); w.addDocument(doc); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.flycode.CRIBSearch.SearchEngine.SearchDocument.java
public void addOwnerDocs() { try {// ww w. j av a 2 s . c o m ResultSet rs = p.selectTable("owner"); while (rs.next()) { Document doc = new Document(); doc.add(new StoredField("id", rs.getString(1))); doc.add(new TextField("firstName", rs.getString(2), null)); doc.add(new TextField("secondName", rs.getString(3), null)); doc.add(new TextField("surname", rs.getString(4), null)); doc.add(new IntPoint("nationalID", Integer.parseInt(rs.getString(5)))); doc.add(new TextField("bio", rs.getString(6), null)); doc.add(new IntPoint("tell", Integer.parseInt(rs.getString(7)))); doc.add(new IntPoint("ownerID", Integer.parseInt(rs.getString(8)))); w.addDocument(doc); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.flycode.CRIBSearch.SearchEngine.SearchDocument.java
public void addTenantDocs() { try {/*from w ww .jav a 2 s . com*/ ResultSet rs = p.selectTable("tenant"); while (rs.next()) { Document doc = new Document(); doc.add(new StoredField("id", rs.getString(1))); doc.add(new TextField("firstName", rs.getString(2), null)); doc.add(new TextField("secondName", rs.getString(3), null)); doc.add(new TextField("surname", rs.getString(4), null)); doc.add(new IntPoint("tell", Integer.parseInt(rs.getString(5)))); doc.add(new IntPoint("nationalID", Integer.parseInt(rs.getString(6)))); doc.add(new TextField("bio", rs.getString(7), null)); w.addDocument(doc); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.github.wxiaoqi.search.lucene.util.DocumentUtil.java
License:Open Source License
public static Document IndexObject2Document(IndexObject indexObject) { Document doc = new Document(); doc.add(new StoredField("id", indexObject.getId())); doc.add(new TextField("title", indexObject.getTitle(), Field.Store.YES)); doc.add(new TextField("summary", indexObject.getKeywords(), Field.Store.YES)); doc.add(new TextField("descripton", indexObject.getDescripton(), Field.Store.YES)); doc.add(new StoredField("postDate", indexObject.getPostDate())); doc.add(new StoredField("url", indexObject.getUrl())); return doc;/*from w ww . j a v a2 s .c o m*/ }
From source file:com.google.gerrit.lucene.AbstractLuceneIndex.java
License:Apache License
void add(Document doc, Values<V> values) { String name = values.getField().getName(); FieldType<?> type = values.getField().getType(); Store store = store(values.getField()); if (type == FieldType.INTEGER || type == FieldType.INTEGER_RANGE) { for (Object value : values.getValues()) { doc.add(new IntField(name, (Integer) value, store)); }// w ww.j a v a2s. com } else if (type == FieldType.LONG) { for (Object value : values.getValues()) { doc.add(new LongField(name, (Long) value, store)); } } else if (type == FieldType.TIMESTAMP) { for (Object value : values.getValues()) { doc.add(new LongField(name, ((Timestamp) value).getTime(), store)); } } else if (type == FieldType.EXACT || type == FieldType.PREFIX) { for (Object value : values.getValues()) { doc.add(new StringField(name, (String) value, store)); } } else if (type == FieldType.FULL_TEXT) { for (Object value : values.getValues()) { doc.add(new TextField(name, (String) value, store)); } } else if (type == FieldType.STORED_ONLY) { for (Object value : values.getValues()) { doc.add(new StoredField(name, (byte[]) value)); } } else { throw FieldType.badFieldType(type); } }
From source file:com.google.gerrit.lucene.LuceneChangeIndex.java
License:Apache License
@SuppressWarnings("deprecation") private void add(Document doc, Values<ChangeData> values) { String name = values.getField().getName(); FieldType<?> type = values.getField().getType(); Store store = store(values.getField()); if (useDocValuesForSorting) { FieldDef<ChangeData, ?> f = values.getField(); if (f == ChangeField.LEGACY_ID || f == ChangeField.LEGACY_ID2) { int v = (Integer) getOnlyElement(values.getValues()); doc.add(new NumericDocValuesField(sortFieldName(f), v)); } else if (f == ChangeField.UPDATED) { long t = ((Timestamp) getOnlyElement(values.getValues())).getTime(); doc.add(new NumericDocValuesField(UPDATED_SORT_FIELD, t)); }//from w ww. j a v a 2 s . c o m } if (type == FieldType.INTEGER || type == FieldType.INTEGER_RANGE) { for (Object value : values.getValues()) { doc.add(new IntField(name, (Integer) value, store)); } } else if (type == FieldType.LONG) { for (Object value : values.getValues()) { doc.add(new LongField(name, (Long) value, store)); } } else if (type == FieldType.TIMESTAMP) { for (Object value : values.getValues()) { doc.add(new LongField(name, ((Timestamp) value).getTime(), store)); } } else if (type == FieldType.EXACT || type == FieldType.PREFIX) { for (Object value : values.getValues()) { doc.add(new StringField(name, (String) value, store)); } } else if (type == FieldType.FULL_TEXT) { for (Object value : values.getValues()) { doc.add(new TextField(name, (String) value, store)); } } else if (type == FieldType.STORED_ONLY) { for (Object value : values.getValues()) { doc.add(new StoredField(name, (byte[]) value)); } } else { throw FieldType.badFieldType(type); } }
From source file:com.helger.pd.indexer.storage.PDStorageManager.java
License:Apache License
@Nonnull public ESuccess createOrUpdateEntry(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final PDExtendedBusinessCard aExtBI, @Nonnull final PDDocumentMetaData aMetaData) throws IOException { ValueEnforcer.notNull(aParticipantID, "ParticipantID"); ValueEnforcer.notNull(aExtBI, "ExtBI"); ValueEnforcer.notNull(aMetaData, "MetaData"); return m_aLucene.runAtomic(() -> { final ICommonsList<Document> aDocs = new CommonsArrayList<>(); final PDBusinessCardType aBI = aExtBI.getBusinessCard(); for (final PDBusinessEntityType aBusinessEntity : aBI.getBusinessEntity()) { // Convert entity to Lucene document final Document aDoc = new Document(); final StringBuilder aSBAllFields = new StringBuilder(); aDoc.add(// ww w . j a v a2s. c om new StringField(CPDStorage.FIELD_PARTICIPANTID, aParticipantID.getURIEncoded(), Store.YES)); aSBAllFields.append(aParticipantID.getURIEncoded()).append(' '); if (aBusinessEntity.getName() != null) { aDoc.add(new TextField(CPDStorage.FIELD_NAME, aBusinessEntity.getName(), Store.YES)); aSBAllFields.append(aBusinessEntity.getName()).append(' '); } if (aBusinessEntity.getCountryCode() != null) { aDoc.add(new StringField(CPDStorage.FIELD_COUNTRY_CODE, aBusinessEntity.getCountryCode(), Store.YES)); aSBAllFields.append(aBusinessEntity.getCountryCode()).append(' '); } // Add all document types to all documents for (final IDocumentTypeIdentifier aDocTypeID : aExtBI.getAllDocumentTypeIDs()) { final String sDocTypeID = aDocTypeID.getURIEncoded(); aDoc.add(new StringField(CPDStorage.FIELD_DOCUMENT_TYPE_ID, sDocTypeID, Store.YES)); aSBAllFields.append(sDocTypeID).append(' '); } if (aBusinessEntity.getGeographicalInformation() != null) { aDoc.add(new TextField(CPDStorage.FIELD_GEOGRAPHICAL_INFORMATION, aBusinessEntity.getGeographicalInformation(), Store.YES)); aSBAllFields.append(aBusinessEntity.getGeographicalInformation()).append(' '); } for (final PDIdentifierType aIdentifier : aBusinessEntity.getIdentifier()) { aDoc.add(new TextField(CPDStorage.FIELD_IDENTIFIER_SCHEME, aIdentifier.getScheme(), Store.YES)); aSBAllFields.append(aIdentifier.getScheme()).append(' '); aDoc.add(new TextField(CPDStorage.FIELD_IDENTIFIER, aIdentifier.getValue(), Store.YES)); aSBAllFields.append(aIdentifier.getValue()).append(' '); } for (final String sWebSite : aBusinessEntity.getWebsiteURI()) { aDoc.add(new TextField(CPDStorage.FIELD_WEBSITEURI, sWebSite, Store.YES)); aSBAllFields.append(sWebSite).append(' '); } for (final PDContactType aContact : aBusinessEntity.getContact()) { final String sType = StringHelper.getNotNull(aContact.getType()); aDoc.add(new TextField(CPDStorage.FIELD_CONTACT_TYPE, sType, Store.YES)); aSBAllFields.append(sType).append(' '); final String sName = StringHelper.getNotNull(aContact.getName()); aDoc.add(new TextField(CPDStorage.FIELD_CONTACT_NAME, sName, Store.YES)); aSBAllFields.append(sName).append(' '); final String sPhone = StringHelper.getNotNull(aContact.getPhoneNumber()); aDoc.add(new TextField(CPDStorage.FIELD_CONTACT_PHONE, sPhone, Store.YES)); aSBAllFields.append(sPhone).append(' '); final String sEmail = StringHelper.getNotNull(aContact.getEmail()); aDoc.add(new TextField(CPDStorage.FIELD_CONTACT_EMAIL, sEmail, Store.YES)); aSBAllFields.append(sEmail).append(' '); } if (aBusinessEntity.getAdditionalInformation() != null) { aDoc.add(new TextField(CPDStorage.FIELD_ADDITIONAL_INFORMATION, aBusinessEntity.getAdditionalInformation(), Store.YES)); aSBAllFields.append(aBusinessEntity.getAdditionalInformation()).append(' '); } if (aBusinessEntity.getRegistrationDate() != null) { final String sDate = PDTWebDateHelper.getAsStringXSD(aBusinessEntity.getRegistrationDate()); aDoc.add(new StringField(CPDStorage.FIELD_REGISTRATION_DATE, sDate, Store.YES)); aSBAllFields.append(sDate).append(' '); } // Add the "all" field - no need to store aDoc.add(new TextField(CPDStorage.FIELD_ALL_FIELDS, aSBAllFields.toString(), Store.NO)); // Add meta data (not part of the "all field" field!) // Lucene6: cannot yet use a LongPoint because it has no way to create a // stored one aDoc.add(new StoredField(CPDStorage.FIELD_METADATA_CREATIONDT, aMetaData.getCreationDTMillis())); aDoc.add(new StringField(CPDStorage.FIELD_METADATA_OWNERID, aMetaData.getOwnerID(), Store.YES)); aDoc.add(new StringField(CPDStorage.FIELD_METADATA_REQUESTING_HOST, aMetaData.getRequestingHost(), Store.YES)); aDocs.add(aDoc); } if (aDocs.isNotEmpty()) { // Add "group end" marker CollectionHelper.getLastElement(aDocs) .add(new Field(CPDStorage.FIELD_GROUP_END, VALUE_GROUP_END, TYPE_GROUP_END)); } // Delete all existing documents of the participant ID // and add the new ones to the index m_aLucene.updateDocuments(_createParticipantTerm(aParticipantID), aDocs); s_aLogger.info("Added " + aDocs.size() + " Lucene documents"); AuditHelper.onAuditExecuteSuccess("pd-indexer-create", aParticipantID.getURIEncoded(), Integer.valueOf(aDocs.size()), aMetaData); }); }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.LuceneDocumentMapper.java
License:Open Source License
@Override public Document createDocument(StackExchangeThread question) throws IngestionException { Document doc = new Document(); doc.add(new IntField(IndexDocumentFieldName.THREAD_POST_ID.toString(), question.getId(), Field.Store.YES)); String questionTitle = question.getQuestion().getUnformattedTitle(); doc.add(new TextField(IndexDocumentFieldName.THREAD_TITLE.toString(), (questionTitle == null) ? "" : questionTitle, Field.Store.YES)); String questionBody = question.getQuestion().getUnformattedBody(); doc.add(new TextField(IndexDocumentFieldName.THREAD_TEXT.toString(), (questionBody == null) ? "" : questionBody, Field.Store.YES)); List<String> tags = question.getQuestion().getTags(); doc.add(new TextField(IndexDocumentFieldName.THREAD_TAGS.toString(), (tags == null) ? "" : tags.toString(), Field.Store.YES));//from w w w .j a va 2 s .c o m doc.add(new TextField(IndexDocumentFieldName.ACCEPTED_ANSWER_TEXT.toString(), question.getAcceptedAnswerText(), Field.Store.YES)); doc.add(new TextField(IndexDocumentFieldName.TOP_VOTED_ANSWER_TEXT.toString(), question.getTopVotedAnswerText(), Field.Store.YES)); doc.add(new TextField(IndexDocumentFieldName.CONCATENATED_ANSWERS_TEXT.toString(), question.getConcatenatedAnswersText(), Field.Store.YES)); byte[] serializedThread = StackExchangeThreadSerializer.serializeObjToBinArr(question); doc.add(new StoredField(IndexDocumentFieldName.SERIALIZED_THREAD.toString(), serializedThread)); return doc; }
From source file:com.liang.minisearch.domain.search.Engine.java
public int createIndex(String url, String content) throws IOException { int maxDoc = 0; Document doc = new Document(); doc.add(new StoredField(FIELD_URL, url)); doc.add(new TextField(FIELD_CONTENT, content, Field.Store.NO)); this.getWriter().addDocument(doc); this.getWriter().commit(); maxDoc = this.getWriter().maxDoc(); // Cleanup resources // this.closeWriter(); return maxDoc; }