Java Code Examples for org.apache.lucene.document.FieldType#storeTermVectorPayloads()
The following examples show how to use
org.apache.lucene.document.FieldType#storeTermVectorPayloads() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
public static String termVectorOptionsToString(FieldType fieldType) { if (!fieldType.storeTermVectors()) { return "no"; } else if (!fieldType.storeTermVectorOffsets() && !fieldType.storeTermVectorPositions()) { return "yes"; } else if (fieldType.storeTermVectorOffsets() && !fieldType.storeTermVectorPositions()) { return "with_offsets"; } else { StringBuilder builder = new StringBuilder("with"); if (fieldType.storeTermVectorPositions()) { builder.append("_positions"); } if (fieldType.storeTermVectorOffsets()) { builder.append("_offsets"); } if (fieldType.storeTermVectorPayloads()) { builder.append("_payloads"); } return builder.toString(); } }
Example 2
Source File: FieldMapper.java From crate with Apache License 2.0 | 6 votes |
public static String termVectorOptionsToString(FieldType fieldType) { if (!fieldType.storeTermVectors()) { return "no"; } else if (!fieldType.storeTermVectorOffsets() && !fieldType.storeTermVectorPositions()) { return "yes"; } else if (fieldType.storeTermVectorOffsets() && !fieldType.storeTermVectorPositions()) { return "with_offsets"; } else { StringBuilder builder = new StringBuilder("with"); if (fieldType.storeTermVectorPositions()) { builder.append("_positions"); } if (fieldType.storeTermVectorOffsets()) { builder.append("_offsets"); } if (fieldType.storeTermVectorPayloads()) { builder.append("_payloads"); } return builder.toString(); } }
Example 3
Source File: TokenSourcesTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Repeat(iterations = 10) //@Seed("947083AB20AB2D4F") public void testRandomizedRoundTrip() throws Exception { final int distinct = TestUtil.nextInt(random(), 1, 10); String[] terms = new String[distinct]; BytesRef[] termBytes = new BytesRef[distinct]; for (int i = 0; i < distinct; ++i) { terms[i] = TestUtil.randomRealisticUnicodeString(random()); termBytes[i] = new BytesRef(terms[i]); } final BaseTermVectorsFormatTestCase.RandomTokenStream rTokenStream = new BaseTermVectorsFormatTestCase.RandomTokenStream(TestUtil.nextInt(random(), 1, 10), terms, termBytes); //check to see if the token streams might have non-deterministic testable result final boolean storeTermVectorPositions = random().nextBoolean(); final int[] startOffsets = rTokenStream.getStartOffsets(); final int[] positionsIncrements = rTokenStream.getPositionsIncrements(); for (int i = 1; i < positionsIncrements.length; i++) { if (storeTermVectorPositions && positionsIncrements[i] != 0) { continue; } //TODO should RandomTokenStream ensure endOffsets for tokens at same position and same startOffset are greater // than previous token's endOffset? That would increase the testable possibilities. if (startOffsets[i] == startOffsets[i-1]) { if (VERBOSE) System.out.println("Skipping test because can't easily validate random token-stream is correct."); rTokenStream.close(); return; } } //sanity check itself assertTokenStreamContents(rTokenStream, rTokenStream.getTerms(), rTokenStream.getStartOffsets(), rTokenStream.getEndOffsets(), rTokenStream.getPositionsIncrements()); Directory dir = newDirectory(); RandomIndexWriter writer = new RandomIndexWriter(random(), dir); FieldType myFieldType = new FieldType(TextField.TYPE_NOT_STORED); myFieldType.setStoreTermVectors(true); myFieldType.setStoreTermVectorOffsets(true); myFieldType.setStoreTermVectorPositions(storeTermVectorPositions); //payloads require positions; it will throw an error otherwise myFieldType.setStoreTermVectorPayloads(storeTermVectorPositions && random().nextBoolean()); Document doc = new Document(); doc.add(new Field("field", rTokenStream, myFieldType)); writer.addDocument(doc); IndexReader reader = writer.getReader(); writer.close(); assertEquals(1, reader.numDocs()); TokenStream vectorTokenStream = TokenSources.getTermVectorTokenStreamOrNull("field", reader.getTermVectors(0), -1); //sometimes check payloads PayloadAttribute payloadAttribute = null; if (myFieldType.storeTermVectorPayloads() && usually()) { payloadAttribute = vectorTokenStream.addAttribute(PayloadAttribute.class); } assertTokenStreamContents(vectorTokenStream, rTokenStream.getTerms(), rTokenStream.getStartOffsets(), rTokenStream.getEndOffsets(), myFieldType.storeTermVectorPositions() ? rTokenStream.getPositionsIncrements() : null); //test payloads if (payloadAttribute != null) { vectorTokenStream.reset(); for (int i = 0; vectorTokenStream.incrementToken(); i++) { assertEquals(rTokenStream.getPayloads()[i], payloadAttribute.getPayload()); } } reader.close(); dir.close(); rTokenStream.close(); }
Example 4
Source File: LuceneTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
public synchronized static Field newField(Random random, String name, Object value, FieldType type) { // Defeat any consumers that illegally rely on intern'd // strings (we removed this from Lucene a while back): name = new String(name); FieldType prevType = fieldToType.get(name); if (usually(random) || type.indexOptions() == IndexOptions.NONE || prevType != null) { // most of the time, don't modify the params if (prevType == null) { fieldToType.put(name, new FieldType(type)); } else { type = mergeTermVectorOptions(type, prevType); } return createField(name, value, type); } // TODO: once all core & test codecs can index // offsets, sometimes randomly turn on offsets if we are // already indexing positions... FieldType newType = new FieldType(type); if (!newType.stored() && random.nextBoolean()) { newType.setStored(true); // randomly store it } // Randomly turn on term vector options, but always do // so consistently for the same field name: if (!newType.storeTermVectors() && random.nextBoolean()) { newType.setStoreTermVectors(true); if (!newType.storeTermVectorPositions()) { newType.setStoreTermVectorPositions(random.nextBoolean()); if (newType.storeTermVectorPositions()) { if (!newType.storeTermVectorPayloads()) { newType.setStoreTermVectorPayloads(random.nextBoolean()); } } } if (!newType.storeTermVectorOffsets()) { newType.setStoreTermVectorOffsets(random.nextBoolean()); } if (VERBOSE) { System.out.println("NOTE: LuceneTestCase: upgrade name=" + name + " type=" + newType); } } newType.freeze(); fieldToType.put(name, newType); // TODO: we need to do this, but smarter, ie, most of // the time we set the same value for a given field but // sometimes (rarely) we change it up: /* if (newType.omitNorms()) { newType.setOmitNorms(random.nextBoolean()); } */ return createField(name, value, newType); }