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


Java FieldType.setStoreTermVectorOffsets方法代码示例

本文整理汇总了Java中org.apache.lucene.document.FieldType.setStoreTermVectorOffsets方法的典型用法代码示例。如果您正苦于以下问题:Java FieldType.setStoreTermVectorOffsets方法的具体用法?Java FieldType.setStoreTermVectorOffsets怎么用?Java FieldType.setStoreTermVectorOffsets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.document.FieldType的用法示例。


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

示例1: testVectorHighlighter

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void testVectorHighlighter() throws Exception {
    Directory dir = new RAMDirectory();
    IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER));

    Document document = new Document();
    document.add(new TextField("_id", "1", Field.Store.YES));
    FieldType vectorsType = new FieldType(TextField.TYPE_STORED);
    vectorsType.setStoreTermVectors(true);
    vectorsType.setStoreTermVectorPositions(true);
    vectorsType.setStoreTermVectorOffsets(true);
    document.add(new Field("content", "the big bad dog", vectorsType));
    indexWriter.addDocument(document);

    IndexReader reader = DirectoryReader.open(indexWriter);
    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new TermQuery(new Term("_id", "1")), 1);

    assertThat(topDocs.totalHits, equalTo(1));

    FastVectorHighlighter highlighter = new FastVectorHighlighter();
    String fragment = highlighter.getBestFragment(highlighter.getFieldQuery(new TermQuery(new Term("content", "bad"))),
            reader, topDocs.scoreDocs[0].doc, "content", 30);
    assertThat(fragment, notNullValue());
    assertThat(fragment, equalTo("the big <b>bad</b> dog"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:VectorHighlighterTests.java

示例2: testVectorHighlighterNoStore

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void testVectorHighlighterNoStore() throws Exception {
    Directory dir = new RAMDirectory();
    IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER));

    Document document = new Document();
    document.add(new TextField("_id", "1", Field.Store.YES));
    FieldType vectorsType = new FieldType(TextField.TYPE_NOT_STORED);
    vectorsType.setStoreTermVectors(true);
    vectorsType.setStoreTermVectorPositions(true);
    vectorsType.setStoreTermVectorOffsets(true);
    document.add(new Field("content", "the big bad dog", vectorsType));
    indexWriter.addDocument(document);

    IndexReader reader = DirectoryReader.open(indexWriter);
    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new TermQuery(new Term("_id", "1")), 1);

    assertThat(topDocs.totalHits, equalTo(1));

    FastVectorHighlighter highlighter = new FastVectorHighlighter();
    String fragment = highlighter.getBestFragment(highlighter.getFieldQuery(new TermQuery(new Term("content", "bad"))),
            reader, topDocs.scoreDocs[0].doc, "content", 30);
    assertThat(fragment, nullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:VectorHighlighterTests.java

示例3: testFieldTypeToTermVectorString

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void testFieldTypeToTermVectorString() throws Exception {
    FieldType ft = new FieldType();
    ft.setStoreTermVectorOffsets(false);
    ft.setStoreTermVectorPayloads(true);
    ft.setStoreTermVectors(true);
    ft.setStoreTermVectorPositions(true);
    String ftOpts = FieldMapper.termVectorOptionsToString(ft);
    assertThat("with_positions_payloads", equalTo(ftOpts));
    AllFieldMapper.Builder builder = new AllFieldMapper.Builder(null);
    boolean exceptiontrown = false;
    try {
        TypeParsers.parseTermVector("", ftOpts, builder);
    } catch (MapperParsingException e) {
        exceptiontrown = true;
    }
    assertThat("TypeParsers.parseTermVector should accept string with_positions_payloads but does not.", exceptiontrown, equalTo(false));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:TermVectorsUnitTests.java

示例4: LuceneUtil

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public LuceneUtil(JasperReportsContext jasperReportsContext, boolean isCaseSensitive, boolean isWholeWordsOnly, boolean removeAccents) {
	this.isCaseSensitive = isCaseSensitive;
	this.isWholeWordsOnly = isWholeWordsOnly;
	this.removeAccents = removeAccents;

	this.noneSelector = JRStyledTextAttributeSelector.getNoneSelector(jasperReportsContext);
	this.styledTextUtil = JRStyledTextUtil.getInstance(jasperReportsContext);
	
	fieldType = new FieldType();
	fieldType.setIndexed(true);
	fieldType.setTokenized(true);
	fieldType.setStored(true);
	fieldType.setStoreTermVectors(true);
	fieldType.setStoreTermVectorPositions(true);
	fieldType.setStoreTermVectorOffsets(true);
	fieldType.freeze();
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:18,代码来源:LuceneUtil.java

示例5: populatePerformanceIndex

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private void populatePerformanceIndex(Analyzer analyzer) throws IOException {
  indexWriter.deleteAll();
  indexWriter.commit();

  FieldType ft = new FieldType(TextField.TYPE_STORED);
  ft.setStoreTermVectors(true);
  ft.setStoreTermVectorOffsets(true);
  ft.setStoreTermVectorPositions(true);
  int docs = 1000;
  Random random = random();
  for (int i = 0; i < docs; i++) {
    boolean b = random.nextBoolean();
    Document doc = new Document();
    doc.add(new Field(textFieldName, createRandomString(random), ft));
    doc.add(new Field(categoryFieldName, b ? "technology" : "politics", ft));
    doc.add(new Field(booleanFieldName, String.valueOf(b), ft));
    indexWriter.addDocument(doc, analyzer);
  }
  indexWriter.commit();
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:ClassificationTestBase.java

示例6: testPayloadsWithoutPositions

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void testPayloadsWithoutPositions() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
  customType.setStoreTermVectors(true);
  customType.setStoreTermVectorPositions(false);
  customType.setStoreTermVectorPayloads(true);
  customType.setStoreTermVectorOffsets(random().nextBoolean());
  doc.add(new Field("field", "foo", customType));
  try {
    writer.addDocument(doc);
    fail();
  } catch (IllegalArgumentException expected) {
    // expected
  }
  writer.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestPayloadsOnVectors.java

示例7: testBogusTermVectors

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void testBogusTermVectors() throws IOException {
  Directory dir = newDirectory();
  IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null));
  Document doc = new Document();
  FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
  ft.setStoreTermVectors(true);
  ft.setStoreTermVectorOffsets(true);
  Field field = new Field("foo", "", ft);
  field.setTokenStream(new CannedTokenStream(
      new Token("bar", 5, 10), new Token("bar", 1, 4)
  ));
  doc.add(field);
  iw.addDocument(doc);
  iw.close();
  dir.close(); // checkindex
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestCheckIndex.java

示例8: checkTokens

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private void checkTokens(Token[] tokens) throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter riw = new RandomIndexWriter(random(), dir, iwc);
  boolean success = false;
  try {
    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
    // store some term vectors for the checkindex cross-check
    ft.setStoreTermVectors(true);
    ft.setStoreTermVectorPositions(true);
    ft.setStoreTermVectorOffsets(true);
   
    Document doc = new Document();
    doc.add(new Field("body", new CannedTokenStream(tokens), ft));
    riw.addDocument(doc);
    success = true;
  } finally {
    if (success) {
      IOUtils.close(riw, dir);
    } else {
      IOUtils.closeWhileHandlingException(riw, dir);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestPostingsOffsets.java

示例9: writeEmptyTermVector

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private void writeEmptyTermVector(TermVectorsResponse outResponse) throws IOException {

        Directory dir = newDirectory();
        IndexWriterConfig conf = new IndexWriterConfig(new StandardAnalyzer());
        conf.setOpenMode(OpenMode.CREATE);
        IndexWriter writer = new IndexWriter(dir, conf);
        FieldType type = new FieldType(TextField.TYPE_STORED);
        type.setStoreTermVectorOffsets(true);
        type.setStoreTermVectorPayloads(false);
        type.setStoreTermVectorPositions(true);
        type.setStoreTermVectors(true);
        type.freeze();
        Document d = new Document();
        d.add(new Field("id", "abc", StringField.TYPE_STORED));

        writer.updateDocument(new Term("id", "abc"), d);
        writer.commit();
        writer.close();
        DirectoryReader dr = DirectoryReader.open(dir);
        IndexSearcher s = new IndexSearcher(dr);
        TopDocs search = s.search(new TermQuery(new Term("id", "abc")), 1);
        ScoreDoc[] scoreDocs = search.scoreDocs;
        int doc = scoreDocs[0].doc;
        Fields fields = dr.getTermVectors(doc);
        EnumSet<Flag> flags = EnumSet.of(Flag.Positions, Flag.Offsets);
        outResponse.setFields(fields, null, flags, fields);
        outResponse.setExists(true);
        dr.close();
        dir.close();

    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:TermVectorsUnitTests.java

示例10: writeStandardTermVector

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private void writeStandardTermVector(TermVectorsResponse outResponse) throws IOException {

        Directory dir = newDirectory();
        IndexWriterConfig conf = new IndexWriterConfig(new StandardAnalyzer());

        conf.setOpenMode(OpenMode.CREATE);
        IndexWriter writer = new IndexWriter(dir, conf);
        FieldType type = new FieldType(TextField.TYPE_STORED);
        type.setStoreTermVectorOffsets(true);
        type.setStoreTermVectorPayloads(false);
        type.setStoreTermVectorPositions(true);
        type.setStoreTermVectors(true);
        type.freeze();
        Document d = new Document();
        d.add(new Field("id", "abc", StringField.TYPE_STORED));
        d.add(new Field("title", "the1 quick brown fox jumps over  the1 lazy dog", type));
        d.add(new Field("desc", "the1 quick brown fox jumps over  the1 lazy dog", type));

        writer.updateDocument(new Term("id", "abc"), d);
        writer.commit();
        writer.close();
        DirectoryReader dr = DirectoryReader.open(dir);
        IndexSearcher s = new IndexSearcher(dr);
        TopDocs search = s.search(new TermQuery(new Term("id", "abc")), 1);
        ScoreDoc[] scoreDocs = search.scoreDocs;
        int doc = scoreDocs[0].doc;
        Fields termVectors = dr.getTermVectors(doc);
        EnumSet<Flag> flags = EnumSet.of(Flag.Positions, Flag.Offsets);
        outResponse.setFields(termVectors, null, flags, termVectors);
        dr.close();
        dir.close();

    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:TermVectorsUnitTests.java

示例11: testTermVectorStringGenerationWithoutPositions

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void testTermVectorStringGenerationWithoutPositions() throws Exception {
    FieldType ft = new FieldType();
    ft.setStoreTermVectorOffsets(true);
    ft.setStoreTermVectorPayloads(true);
    ft.setStoreTermVectors(true);
    ft.setStoreTermVectorPositions(false);
    String ftOpts = FieldMapper.termVectorOptionsToString(ft);
    assertThat(ftOpts, equalTo("with_offsets"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:TermVectorsUnitTests.java

示例12: writeStandardTermVector

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private void writeStandardTermVector(TermVectorsResponse outResponse) throws IOException {

        Directory dir = LuceneTestCase.newDirectory();
        IndexWriterConfig conf = new IndexWriterConfig(new StandardAnalyzer());

        conf.setOpenMode(OpenMode.CREATE);
        IndexWriter writer = new IndexWriter(dir, conf);
        FieldType type = new FieldType(TextField.TYPE_STORED);
        type.setStoreTermVectorOffsets(true);
        type.setStoreTermVectorPayloads(false);
        type.setStoreTermVectorPositions(true);
        type.setStoreTermVectors(true);
        type.freeze();
        Document d = new Document();
        d.add(new Field("id", "abc", StringField.TYPE_STORED));
        d.add(new Field("plaintext", "the1 quick brown fox jumps over  the1 lazy dog comment", type));
        d.add(new Field("desc", "the1 quick brown fox jumps over  the1 lazy dog comment", type));

        writer.updateDocument(new Term("id", "abc"), d);
        writer.commit();
        writer.close();
        DirectoryReader dr = DirectoryReader.open(dir);
        IndexSearcher s = new IndexSearcher(dr);
        TopDocs search = s.search(new TermQuery(new Term("id", "abc")), 1);
        ScoreDoc[] scoreDocs = search.scoreDocs;
        int doc = scoreDocs[0].doc;
        Fields termVectors = dr.getTermVectors(doc);
        EnumSet<Flag> flags = EnumSet.of(Flag.Positions, Flag.Offsets);
        outResponse.setFields(termVectors, null, flags, termVectors);
        dr.close();
        dir.close();

    }
 
开发者ID:dlcs,项目名称:the-mathmos-server,代码行数:34,代码来源:TextSearchServiceImplTest.java

示例13: testDeadlock

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void testDeadlock() throws Exception {
  Directory dir = newDirectory();
  IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))
                                              .setMaxBufferedDocs(2));
  Document doc = new Document();

  FieldType customType = new FieldType(TextField.TYPE_STORED);
  customType.setStoreTermVectors(true);
  customType.setStoreTermVectorPositions(true);
  customType.setStoreTermVectorOffsets(true);
  
  doc.add(newField("content", "aaa bbb ccc ddd eee fff ggg hhh iii", customType));
  writer.addDocument(doc);
  writer.addDocument(doc);
  writer.addDocument(doc);
  writer.commit();
  // index has 2 segments

  Directory dir2 = newDirectory();
  IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig(new MockAnalyzer(random())));
  writer2.addDocument(doc);
  writer2.close();

  IndexReader r1 = DirectoryReader.open(dir2);
  writer.addIndexes(r1, r1);
  writer.close();

  IndexReader r3 = DirectoryReader.open(dir);
  assertEquals(5, r3.numDocs());
  r3.close();

  r1.close();

  dir2.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:37,代码来源:TestIndexWriter.java

示例14: setUp

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
  super.setUp();
  dir = newDirectory();
  indexWriter = new RandomIndexWriter(random(), dir);
  textFieldName = "text";
  categoryFieldName = "cat";
  booleanFieldName = "bool";
  ft = new FieldType(TextField.TYPE_STORED);
  ft.setStoreTermVectors(true);
  ft.setStoreTermVectorOffsets(true);
  ft.setStoreTermVectorPositions(true);
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:ClassificationTestBase.java

示例15: DocState

import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public DocState(boolean useDocValues) {
  doc = new Document();
  
  title = new StringField("title", "", Field.Store.NO);
  doc.add(title);

  FieldType ft = new FieldType(TextField.TYPE_STORED);
  ft.setStoreTermVectors(true);
  ft.setStoreTermVectorOffsets(true);
  ft.setStoreTermVectorPositions(true);
  
  titleTokenized = new Field("titleTokenized", "", ft);
  doc.add(titleTokenized);

  body = new Field("body", "", ft);
  doc.add(body);

  id = new StringField("docid", "", Field.Store.YES);
  doc.add(id);

  date = new StringField("date", "", Field.Store.YES);
  doc.add(date);

  if (useDocValues) {
    titleDV = new SortedDocValuesField("titleDV", new BytesRef());
    doc.add(titleDV);
  } else {
    titleDV = null;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:LineFileDocs.java


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