private void addPatterns(String id, Map<Integer, Set<E>> p, boolean commit) { try{ setIndexWriter(); Document doc = new Document(); doc.add(new StringField("sentid", id, Field.Store.YES)); doc.add(new Field("patterns", getBytes(p), LuceneFieldType.NOT_INDEXED)); indexWriter.addDocument(doc); if(commit){ indexWriter.commit(); //closeIndexWriter(); } }catch(IOException e){ throw new RuntimeException(e); } }
iwriter = new IndexWriter(directory, iwConfig); Document doc = new Document(); doc.add(new StringField("ID", "10000", Field.Store.YES)); doc.add(new TextField(fieldName, text, Field.Store.YES)); iwriter.addDocument(doc); iwriter.close(); ireader = DirectoryReader.open(directory); isearcher = new IndexSearcher(ireader); directory.close(); } catch (IOException e) { e.printStackTrace();
try (InputStream stream = Files.newInputStream(file)) { Document doc = new Document(); Field pathField = new StringField("path", file.toString(), Field.Store.YES); doc.add(pathField); doc.add(new LongPoint("modified", lastModified)); doc.add(new TextField("contents", new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)))); if (writer.getConfig().getOpenMode() == OpenMode.CREATE) { writer.addDocument(doc); } else { writer.updateDocument(new Term("path", file.toString()), doc);
writer.deleteDocuments(docTerm); continue; doc = new Document(); Field docidField = new StringField(DOCID, docid, Field.Store.YES); doc.add(docidField); } else if (hits.scoreDocs.length > 1) { throw new IllegalArgumentException("More than one document found for document id: " + docid); for (IndexableField field : doc.getFields()) { if (field.stringValue().startsWith(GEOID)) { geofields.put(field.name(), ctx.readShape(field.stringValue().substring(GEOID.length()))); case DEFAULT: case TEXT: field = new TextField(add.key, str, Field.Store.YES); break; case STRING: field = new StringField(add.key, str, Field.Store.YES); break; default: throw new IllegalArgumentException("Illegal mapping specified: " + mapping); writer.updateDocument(new Term(DOCID, docid), doc); writer.commit();
public static int writeFeaturesToIndex(InputStream in, IndexWriter iw) throws IOException { int count = 0; GenericDoubleLireFeature f = new GenericDoubleLireFeature(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; while ((line = br.readLine()) != null) { Document d = new Document(); if (line.startsWith("#")) continue; String[] split = line.split("\\s"); // split at white space ... String filename = split[0]; double[] data = new double[split.length-1]; for (int i = 1; i < split.length; i++) { data[i-1] = Double.parseDouble(split[i]); } f.setData(data); d.add(new StoredField(f.getFieldName(), new BytesRef(f.getByteArrayRepresentation()))); d.add(new StringField(DocumentBuilder.FIELD_NAME_IDENTIFIER, filename, Field.Store.YES)); iw.addDocument(d); count++; } iw.close(); return count; }
@Override public void addFields(final String name, final Object value, final ViewSettings settings, final Document to) { to.add(boost(new StringField(name, value.toString(), settings.getStore()), settings)); to.add(new SortedDocValuesField(name, new BytesRef(value.toString()))); }
IndexWriter writer = null; try { writer = new IndexWriter(dir, iwc); Document doc = new Document(); Field pathField = new StringField(FIELD_LOCATION, location, Field.Store.YES); doc.add(pathField); doc.add(new LongPoint(FIELD_MODIFIED, lastModified)); if (parameters != null) { for (String key : parameters.keySet()) { doc.add(new StringField(key, parameters.get(key), Field.Store.YES)); doc.add(new TextField(FIELD_CONTENTS, new BufferedReader(new InputStreamReader(new ByteArrayInputStream(contents), StandardCharsets.UTF_8)))); writer.updateDocument(new Term(FIELD_LOCATION, location), doc); } finally { if (writer != null) { writer.close();
/** * Used in test to add a new Document to an Index; two fields are created: id and body * * @param dir The Directory containing the Index to modify * @param id a sequential number to identify this document (id field) * @param text Some text to add to the body field * @throws IOException */ public static void writeTextToIndex(Directory dir, int id, String text) throws IOException { IndexWriterConfig indexWriterConfig = new IndexWriterConfig(LuceneSettings.analyzer); IndexWriter iw = new IndexWriter(dir, indexWriterConfig); Document doc = new Document(); doc.add(new StringField("id", String.valueOf(id), Field.Store.YES)); doc.add(new TextField("body", text, Field.Store.NO)); iw.addDocument(doc); iw.commit(); iw.close(); }
Document doc = new Document(); log.debug(subject + " " + predicate + " " + object); doc.add(new StringField(FIELD_NAME_URI, subject, Store.YES)); doc.add(new TextField(FIELD_NAME_SURFACE_FORM, object, Store.YES)); doc.add(new TextField(FIELD_NAME_URI_COUNT, "1", Store.YES)); doc.add(new TextField(FIELD_NAME_CONTEXT, object, Store.YES)); iwriter.addDocument(doc); } else { String docID = triples.get(0).subject; Document hitDoc = isearcher.doc(Integer.parseInt(docID)); Document newDoc = new Document(); newDoc.add(new StringField(FIELD_NAME_URI, triples.get(0).predicate, Store.YES)); newDoc.add(new TextField(FIELD_NAME_SURFACE_FORM, hitDoc.get(FIELD_NAME_SURFACE_FORM), Store.YES)); newDoc.add(new TextField(FIELD_NAME_URI_COUNT, "1", Store.YES)); newDoc.add(new TextField(FIELD_NAME_CONTEXT, remainContext, Store.YES)); iwriter.updateDocument(new Term(FIELD_NAME_URI, subject), newDoc);
private DocWithId() { idField = new StringField( NODE_ID_KEY, "", YES ); idValueField = new NumericDocValuesField( NODE_ID_KEY, 0L ); document = new Document(); document.add( idField ); document.add( idValueField ); }
Field idField = new StringField(FLD_ID, entityId.toString(), Field.Store.YES); Field entityField = new StringField(FLD_ENTITY, entityName, Field.Store.YES); Field allField = new TextField( FLD_ALL, allContent, ); Field morphologyAllField = new TextField( FLD_MORPHOLOGY_ALL, allContent, ); Field linksField = new TextField( FLD_LINKS, createLinksFieldContent(entity, entityDescr), ); writer.updateDocument(new Term(FLD_ID, entityId.toString()), doc); } else { log.debug("Adding document {}-{}", entityName, entityId); writer.addDocument(doc);
/** * Writes a document to contain the serialized version of {@code settings}, * with a {@link QueryBuilder#OBJUID} value set to * {@link #INDEX_ANALYSIS_SETTINGS_OBJUID}. An existing version of the * document is first deleted. * @param writer a defined, target instance * @param settings a defined instance * @throws IOException if I/O error occurs while writing Lucene */ public void write(IndexWriter writer, IndexAnalysisSettings settings) throws IOException { byte[] objser = settings.serialize(); writer.deleteDocuments(new Term(QueryBuilder.OBJUID, INDEX_ANALYSIS_SETTINGS_OBJUID)); Document doc = new Document(); StringField uidfield = new StringField(QueryBuilder.OBJUID, INDEX_ANALYSIS_SETTINGS_OBJUID, Field.Store.NO); doc.add(uidfield); doc.add(new StoredField(QueryBuilder.OBJSER, objser)); doc.add(new StoredField(QueryBuilder.OBJVER, INDEX_ANALYSIS_SETTINGS_OBJVER)); writer.addDocument(doc); }
IndexWriter iw = LuceneUtils.createIndexWriter(((DirectoryReader) reader).directory(), false, LuceneUtils.AnalyzerType.WhitespaceAnalyzer); for (int i = 0; i < reader.maxDoc(); i++) { if (d.getValues(visualWordsFieldName) == null || d.getValues(visualWordsFieldName).length == 0) { IndexableField[] fields = d.getFields(localFeatureFieldName); d.add(new TextField(visualWordsFieldName, arrayToVisualWordString(tmpHist), Field.Store.YES)); d.add(new StringField(localFeatureHistFieldName, SerializationUtils.arrayToString(tmpHist), Field.Store.YES)); iw.updateDocument(new Term(DocumentBuilder.FIELD_NAME_IDENTIFIER, d.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]), d); iw.commit(); iw.forceMerge(1); iw.close(); System.out.println("Finished.");
@Override public void enhance( Document document ) { document.add( new StringField( LuceneExplicitIndex.KEY_START_NODE_ID, "" + startNode, Store.YES ) ); document.add( new StringField( LuceneExplicitIndex.KEY_END_NODE_ID, "" + endNode, Store.YES ) ); } }
IndexableField[] fields = d.getFields(localFeatureFieldName); d.removeField(visualWordsFieldName); d.removeField(localFeatureHistFieldName); d.add(new TextField(visualWordsFieldName, arrayToVisualWordString(tmpHist), Field.Store.YES)); d.add(new StringField(localFeatureHistFieldName, SerializationUtils.arrayToString(tmpHist), Field.Store.YES)); iw.updateDocument(new Term(DocumentBuilder.FIELD_NAME_IDENTIFIER, d.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]), d); if (pm != null) { double len = (double) (end - start);
String fieldName = iterator.next(); if (fieldName.startsWith("id") || fieldName.startsWith("title") || fieldName.startsWith(DocumentBuilder.FIELD_NAME_IDENTIFIER) ) { fields.add(new StringField(fieldName, (String) document.get(fieldName), Field.Store.YES)); } else if (fieldName.endsWith(DocumentBuilder.HASH_FIELD_SUFFIX)) { fields.add(new TextField(fieldName, (String) document.get(fieldName), Field.Store.NO)); } else { if (!useDocValues) { } else { fields.add(new BinaryDocValuesField(fieldName, new BytesRef((byte[]) document.get(fieldName)))); iw.addDocument(fields);
document.add( new StoredField( TX_STATE_KEY, TX_STATE_VALUE ) ); cachedDocuments.put( id, document ); add = true; document.add( new StringField( ORPHANS_KEY, ORPHANS_VALUE, Store.NO ) ); addOrphan( null ); document.add( new StringField( ORPHANS_KEY, key, Store.NO ) ); addOrphan( key ); writer.addDocument( document ); writer.updateDocument( index.type.idTerm( id ), document );
private Document buildDocument(BytesRef text, Set<BytesRef> contexts, long weight, BytesRef payload) throws IOException { String textString = text.utf8ToString(); Document doc = new Document(); FieldType ft = getTextFieldType(); doc.add(new Field(TEXT_FIELD_NAME, textString, ft)); doc.add(new Field("textgrams", textString, ft)); doc.add(new StringField(EXACT_TEXT_FIELD_NAME, textString, Field.Store.NO)); doc.add(new BinaryDocValuesField(TEXT_FIELD_NAME, text)); doc.add(new NumericDocValuesField("weight", weight)); if (payload != null) { doc.add(new BinaryDocValuesField("payloads", payload)); } if (contexts != null) { for(BytesRef context : contexts) { doc.add(new StringField(CONTEXTS_FIELD_NAME, context, Field.Store.NO)); doc.add(new SortedSetDocValuesField(CONTEXTS_FIELD_NAME, context)); } } return doc; }
void addAuthPrincipalLinkField(String authLink) { this.authPrincipalLinkField.stringField.setStringValue(authLink); this.doc.add(this.authPrincipalLinkField.stringField); }
void addSelfLinkField(String selfLink) { StringFieldContext ctx = this.selfLinkField; ctx.stringField.setStringValue(selfLink); ctx.sortedField.setBytesValue(new BytesRef(selfLink)); this.doc.add(ctx.stringField); this.doc.add(ctx.sortedField); }