当前位置: 首页>>代码示例>>Java>>正文


Java StringField类代码示例

本文整理汇总了Java中org.apache.lucene.document.StringField的典型用法代码示例。如果您正苦于以下问题:Java StringField类的具体用法?Java StringField怎么用?Java StringField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringField类属于org.apache.lucene.document包,在下文中一共展示了StringField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: indexDoc

import org.apache.lucene.document.StringField; //导入依赖的package包/类
static void indexDoc(IndexWriter writer, Path file, long lastModified) throws IOException {
	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) {
			System.out.println("adding " + file);
			writer.addDocument(doc);
		} else {
			System.out.println("updating " + file);
			writer.updateDocument(new Term("path", file.toString()), doc);
		}
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:18,代码来源:IndexFiles.java

示例2: setup

import org.apache.lucene.document.StringField; //导入依赖的package包/类
@BeforeClass
public static void setup() throws IOException {
    dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    final int numDocs = TestUtil.nextInt(random(), 1, 20);
    for (int i = 0; i < numDocs; ++i) {
        final int numHoles = random().nextInt(5);
        for (int j = 0; j < numHoles; ++j) {
            w.addDocument(new Document());
        }
        Document doc = new Document();
        doc.add(new StringField("foo", "bar", Store.NO));
        w.addDocument(doc);
    }
    reader = w.getReader();
    w.close();
    Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader));
    searcher = new ContextIndexSearcher(engineSearcher, IndexSearcher.getDefaultQueryCache(), MAYBE_CACHE_POLICY);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:QueryProfilerTests.java

示例3: testEmpty

import org.apache.lucene.document.StringField; //导入依赖的package包/类
public void testEmpty() throws Exception {
    Document d = new Document();
    d.add(new StringField("field", "value", Field.Store.NO));
    writer.addDocument(d);
    refreshReader();

    IndexFieldData fieldData = getForField("non_existing_field");
    int max = randomInt(7);
    for (LeafReaderContext readerContext : readerContexts) {
        AtomicFieldData previous = null;
        for (int i = 0; i < max; i++) {
            AtomicFieldData current = fieldData.load(readerContext);
            assertThat(current.ramBytesUsed(), equalTo(0L));
            if (previous != null) {
                assertThat(current, not(sameInstance(previous)));
            }
            previous = current;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractFieldDataTestCase.java

示例4: testCanOpenIndex

import org.apache.lucene.document.StringField; //导入依赖的package包/类
public void testCanOpenIndex() throws IOException {
    final ShardId shardId = new ShardId("index", "_na_", 1);
    IndexWriterConfig iwc = newIndexWriterConfig();
    Path tempDir = createTempDir();
    final BaseDirectoryWrapper dir = newFSDirectory(tempDir);
    assertFalse(Store.canOpenIndex(logger, tempDir, shardId, (id, l) -> new DummyShardLock(id)));
    IndexWriter writer = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new StringField("id", "1", random().nextBoolean() ? Field.Store.YES : Field.Store.NO));
    writer.addDocument(doc);
    writer.commit();
    writer.close();
    assertTrue(Store.canOpenIndex(logger, tempDir, shardId, (id, l) -> new DummyShardLock(id)));

    DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) {

        @Override
        public Directory newDirectory() throws IOException {
            return dir;
        }
    };
    Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId));
    store.markStoreCorrupted(new CorruptIndexException("foo", "bar"));
    assertFalse(Store.canOpenIndex(logger, tempDir, shardId, (id, l) -> new DummyShardLock(id)));
    store.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:StoreTests.java

示例5: createIndex

import org.apache.lucene.document.StringField; //导入依赖的package包/类
@Override
public void createIndex(NitriteId id, String field, String text) {
    try {
        Document document = new Document();
        String jsonId = keySerializer.writeValueAsString(id);
        Field contentField = new TextField(field, text, Field.Store.NO);
        Field idField = new StringField(CONTENT_ID, jsonId, Field.Store.YES);

        document.add(idField);
        document.add(contentField);

        synchronized (this) {
            indexWriter.addDocument(document);
            commit();
        }
    } catch (IOException ioe) {
        throw new IndexingException(errorMessage(
                "could not write full-text index data for " + text, 0), ioe);
    } catch (VirtualMachineError vme) {
        handleVirtualMachineError(vme);
    }
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:23,代码来源:LuceneService.java

示例6: updateIndex

import org.apache.lucene.document.StringField; //导入依赖的package包/类
@Override
public void updateIndex(NitriteId id, String field, String text) {
    try {
        Document document = new Document();
        String jsonId = keySerializer.writeValueAsString(id);
        Field contentField = new TextField(field, text, Field.Store.NO);
        Field idField = new StringField(CONTENT_ID, jsonId, Field.Store.YES);

        document.add(idField);
        document.add(contentField);

        synchronized (this) {
            indexWriter.updateDocument(new Term(CONTENT_ID, jsonId), document);
            commit();
        }
    } catch (IOException ioe) {
        throw new IndexingException(errorMessage(
                "could not update full-text index for " + text, 0), ioe);
    } catch (VirtualMachineError vme) {
        handleVirtualMachineError(vme);
    }
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:23,代码来源:LuceneService.java

示例7: startElement

import org.apache.lucene.document.StringField; //导入依赖的package包/类
@Override
public void startElement(String u, String l, String qName, Attributes attributes) throws SAXException {
    if (qName.equals("GGS:SpanAnnotation") || qName.equals("GGS:Annotation")) {
        Document doc = new Document();
        for (int i = 0; i < attributes.getLength(); i++) {
            doc.add(new StringField(attributes.getLocalName(i), attributes.getValue(i), Field.Store.YES));
        }
        try {
            annotationsWriter.addDocument(doc);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return;
    }

    if (qName.equals(sent) || nodesStack.size() > 0) {
        nodesStack.push(qName);
        segmentStartsStack.push(totalWords);
        if (attributes != null && attributes.getLength() > 0) {
            attributesStack.push(new AttributesImpl(attributes));
        } else {
            attributesStack.push(new AttributesImpl());
        }
        sb = new StringBuilder();
    }
}
 
开发者ID:radsimu,项目名称:UaicNlpToolkit,代码行数:27,代码来源:IndexedLuceneCorpus.java

示例8: noteToDocument

import org.apache.lucene.document.StringField; //导入依赖的package包/类
private Document noteToDocument(Note note, String noteHtmlContents) {
	Document d = new Document ();
	
	String id = note.getId ();
	
	Project project = note.getProject();
	
	String projectId = project.getID();
	String projectName = project.getTitle();
	String title = note.getTitle ();		
	String date = note.getDate() != null ? new SimpleDateFormat ("yyyy-MM-dd").format(note.getDate().getDate()) : null;
	
	d.add (new StringField ("id", id, Field.Store.YES));
	d.add (new StringField ("project_id", projectId, Field.Store.YES));
	d.add (new StoredField ("project_name", projectName));
	d.add (new TextField ("title", title, Field.Store.YES));
	d.add (new TextField ("title_cs", title, Field.Store.YES));
	d.add (new TextField ("date", date != null ? date : "", Field.Store.YES));
	d.add (new TextField ("body", noteHtmlContents, Field.Store.YES));
			
	return d;
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:23,代码来源:NoteIndexer.java

示例9: eventToDocument

import org.apache.lucene.document.StringField; //导入依赖的package包/类
private Document eventToDocument(Event newEvent) {
	Document d = new Document ();
	
	String eventId = newEvent.getId ();
	String eventText = newEvent.getText();
	
	String eventStartDate = newEvent.getStartDate() != null ? new SimpleDateFormat ("yyyy-MM-dd").format(newEvent.getStartDate().getDate()) : null;
	
	String eventStartTime = newEvent.getTimeString();
	
	if (eventStartDate != null) eventStartTime = eventStartDate + " @ " + eventStartTime;

	d.add (new StringField ("id", eventId, Field.Store.YES));
	d.add (new TextField ("text", eventText, Field.Store.YES));
	d.add (new TextField ("text_cs", eventText, Field.Store.YES));
	d.add (new StoredField ("original_start_date", eventStartTime != null ? eventStartTime : ""));
	return d;
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:19,代码来源:EventIndexer.java

示例10: addToDoc

import org.apache.lucene.document.StringField; //导入依赖的package包/类
void addToDoc(Document doc, String... values){
  Preconditions.checkArgument(valueType == String.class);
  if (isSorted()) {
    Preconditions.checkArgument(values.length < 2, "sorted fields cannot have multiple values");
  }

  // add distinct elements to doc
  final Iterable<String> nonNull = FluentIterable.from(Arrays.asList(values))
      .filter(new Predicate<String>() {
        @Override
        public boolean apply(@Nullable final String input) {
          return input != null;
        }
      });

  for (final String value : ImmutableSet.copyOf(nonNull)) {
    final String truncatedValue = StringUtils.abbreviate(value, MAX_STRING_LENGTH);
    doc.add(new StringField(indexFieldName, truncatedValue, stored ? Store.YES : Store.NO));
  }

  if (isSorted() && values.length == 1) {
    Preconditions.checkArgument(sortedValueType == SearchFieldSorting.FieldType.STRING);
    doc.add(new SortedDocValuesField(indexFieldName, new BytesRef(values[0])));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:IndexKey.java

示例11: run

import org.apache.lucene.document.StringField; //导入依赖的package包/类
@Override
public void run() {
  try {
    for (int i = 0; i < 10000; ++i) {
      final Document document = new Document();
      final String key = "key" + i;
      final String val = "value" + i;
      document.add(new StringField(key, val, Field.Store.YES));
      document.add(new SortedDocValuesField(key, new BytesRef(val.getBytes())));
      index.add(document);
      data.put(key, val);
      sleep(1);
    }
  } catch (InterruptedException e) {
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:TestLuceneIndexer.java

示例12: addIndex

import org.apache.lucene.document.StringField; //导入依赖的package包/类
public void addIndex(UUser user) throws Exception {
  IndexWriter writer = getWriter();
  Document doc = new Document();
  /*
 * yes是会将数据存进索引,如果查询结果中需要将记录显示出来就要存进去,如果查询结果
 * 只是显示标题之类的就可以不用存,而且内容过长不建议存进去
 * 使用TextField类是可以用于查询的。
 */
  try {
    doc.add(new StringField("userid", String.valueOf(user.getId()), Field.Store.YES));
    doc.add(new TextField("username", user.getUsername(), Field.Store.YES));

    writer.addDocument(doc);
  } catch (Exception e) {
    e.printStackTrace();
    throw e;
  } finally {
    writer.close();
  }
}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:21,代码来源:LuceneIndex.java

示例13: initializeProfanitySet

import org.apache.lucene.document.StringField; //导入依赖的package包/类
/**
 * Initializes profanity set.
 * 
 * @param dictFilePath
 *          dictionary file path
 */
private void initializeProfanitySet(String dictFilePath) {
  if (dictFilePath != null) {
    File file = new File(dictFilePath);
    if (file.exists() && file.isFile()) {
      try {
        IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, analyzer);
        IndexWriter indexWriter = new IndexWriter(directory, config);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        Set<String> bannedWords = new HashSet<String>();
        String line = null;
        while ((line = reader.readLine()) != null) {
          bannedWords.add(line.trim());
          Document doc = new Document();
          doc.add(new StringField(LUCENE_FIELD_NAME, line, Store.NO));
          indexWriter.addDocument(doc);
        }
        this.bannedWords = bannedWords;
        indexWriter.close();
        reader.close();
      } catch (Exception ex) {
        LOG.error("Error reading file", ex);
      }
    }
  }
}
 
开发者ID:sematext,项目名称:related-searches,代码行数:32,代码来源:AbstractProfanityRemovingOutputWriter.java

示例14: InMemoryIndex

import org.apache.lucene.document.StringField; //导入依赖的package包/类
public InMemoryIndex(Map<String,String> id2Text){
    Analyzer analyzer = new EnglishAnalyzer();
    IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    try {
        IndexWriter writer = new IndexWriter(directory, iwc);
        for (String id:id2Text.keySet()) {
            Document doc=new Document();
            doc.add(new StringField("id", id, Field.Store.YES));
            doc.add(new TextField("content", id2Text.get(id), Field.Store.YES));
            writer.addDocument(doc);
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:18,代码来源:InMemoryIndex.java

示例15: transform

import org.apache.lucene.document.StringField; //导入依赖的package包/类
@Override
public Document transform(final Example input) throws TransformException {
    final Document doc = new Document();

    doc.add(new Field(ExampleField.ID.getName(), input.getId(), StringField.TYPE_STORED));
    doc.add(new SortedDocValuesField(ExampleField.ID.getName(), new BytesRef(input.getId())));

    doc.add(new Field(ExampleField.TITLE.getName(), input.getTitle(), TextField.TYPE_STORED));
    doc.add(new Field(ExampleField.BODY.getName(), input.getBody(), TextField.TYPE_STORED));

    doc.add(new Field(ExampleField.COLOR.getName(), input.getColor(), StringField.TYPE_STORED));
    doc.add(new SortedSetDocValuesFacetField(ExampleField.COLOR.getName(), input.getColor()));

    final Date createDate = input.getCreateDate();
    doc.add(new NumericDocValuesField(ExampleField.CREATE_DATE.getName(), createDate.getTime()));
    doc.add(new StoredField(ExampleField.CREATE_DATE.getName(), createDate.getTime()));

    return doc;
}
 
开发者ID:bbende,项目名称:tripod,代码行数:20,代码来源:ExampleIndexTransformer.java


注:本文中的org.apache.lucene.document.StringField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。