本文整理汇总了Java中org.apache.lucene.document.SortedSetDocValuesField类的典型用法代码示例。如果您正苦于以下问题:Java SortedSetDocValuesField类的具体用法?Java SortedSetDocValuesField怎么用?Java SortedSetDocValuesField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SortedSetDocValuesField类属于org.apache.lucene.document包,在下文中一共展示了SortedSetDocValuesField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseCreateField
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
String value;
if (context.externalValueSet()) {
value = context.externalValue().toString();
} else {
value = context.parser().textOrNull();
}
if (value == null) {
return;
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
Field field = new Field(fieldType().name(), value, fieldType());
fields.add(field);
}
if (fieldType().hasDocValues()) {
fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(value)));
}
}
示例2: parseCreateField
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
ValueAndBoost valueAndBoost = parseCreateFieldForString(context, fieldType().nullValueAsString(), fieldType().boost());
if (valueAndBoost.value() == null) {
return;
}
if (ignoreAbove > 0 && valueAndBoost.value().length() > ignoreAbove) {
return;
}
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(fieldType().names().fullName(), valueAndBoost.value(), valueAndBoost.boost());
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
Field field = new Field(fieldType().names().indexName(), valueAndBoost.value(), fieldType());
field.setBoost(valueAndBoost.boost());
fields.add(field);
}
if (fieldType().hasDocValues()) {
fields.add(new SortedSetDocValuesField(fieldType().names().indexName(), new BytesRef(valueAndBoost.value())));
}
}
示例3: buildDocument
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
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) {
// TODO: if we had a BinaryTermField we could fix
// this "must be valid ut8f" limitation:
doc.add(new StringField(CONTEXTS_FIELD_NAME, context.utf8ToString(), Field.Store.NO));
doc.add(new SortedSetDocValuesField(CONTEXTS_FIELD_NAME, context));
}
}
return doc;
}
示例4: processSSDVFacetFields
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
private void processSSDVFacetFields(Map<String,List<SortedSetDocValuesFacetField>> byField, Document doc) throws IOException {
//System.out.println("process SSDV: " + byField);
for(Map.Entry<String,List<SortedSetDocValuesFacetField>> ent : byField.entrySet()) {
String indexFieldName = ent.getKey();
//System.out.println(" field=" + indexFieldName);
for(SortedSetDocValuesFacetField facetField : ent.getValue()) {
FacetLabel cp = new FacetLabel(facetField.dim, facetField.label);
String fullPath = pathToString(cp.components, cp.length);
//System.out.println("add " + fullPath);
// For facet counts:
doc.add(new SortedSetDocValuesField(indexFieldName, new BytesRef(fullPath)));
// For drill-down:
doc.add(new StringField(indexFieldName, fullPath, Field.Store.NO));
doc.add(new StringField(indexFieldName, facetField.dim, Field.Store.NO));
}
}
}
示例5: testSortedSetOneValue
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
public void testSortedSetOneValue() throws IOException {
assumeTrue("Codec does not support SORTED_SET", defaultCodecSupportsSortedSet());
Directory directory = newDirectory();
RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
Document doc = new Document();
doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
iwriter.addDocument(doc);
DirectoryReader ireader = iwriter.getReader();
iwriter.close();
SortedSetDocValues dv = getOnlySegmentReader(ireader).getSortedSetDocValues("field");
dv.setDocument(0);
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(new BytesRef("hello"), bytes);
ireader.close();
directory.close();
}
示例6: testMixedTypesAfterReopenAppend2
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
public void testMixedTypesAfterReopenAppend2() throws IOException {
assumeTrue("codec does not support SORTED_SET", defaultCodecSupportsSortedSet());
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))) ;
Document doc = new Document();
doc.add(new SortedSetDocValuesField("foo", new BytesRef("foo")));
w.addDocument(doc);
w.close();
doc = new Document();
w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
doc.add(new StringField("foo", "bar", Field.Store.NO));
doc.add(new BinaryDocValuesField("foo", new BytesRef("foo")));
try {
// NOTE: this case follows a different code path inside
// DefaultIndexingChain/FieldInfos, because the field (foo)
// is first added without DocValues:
w.addDocument(doc);
fail("did not get expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
w.forceMerge(1);
w.close();
dir.close();
}
示例7: createFields
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
@Override
public List<IndexableField> createFields(SchemaField field, Object value, float boost) {
if (field.hasDocValues()) {
List<IndexableField> fields = new ArrayList<>();
fields.add(createField(field, value, boost));
final BytesRef bytes = getCollationKey(field.getName(), value.toString());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
} else {
fields.add(new SortedDocValuesField(field.getName(), bytes));
}
return fields;
} else {
return Collections.singletonList(createField(field, value, boost));
}
}
示例8: createFields
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
@Override
public List<IndexableField> createFields(SchemaField field, Object value,
float boost) {
if (field.hasDocValues()) {
List<IndexableField> fields = new ArrayList<>();
fields.add(createField(field, value, boost));
final BytesRef bytes = new BytesRef(value.toString());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
} else {
fields.add(new SortedDocValuesField(field.getName(), bytes));
}
return fields;
} else {
return Collections.singletonList(createField(field, value, boost));
}
}
示例9: createFields
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
@Override
public List<IndexableField> createFields(SchemaField field, Object value, float boost) {
if (field.hasDocValues()) {
List<IndexableField> fields = new ArrayList<>();
IndexableField storedField = createField(field, value, boost);
fields.add(storedField);
ByteBuffer byteBuffer = toObject(storedField);
BytesRef bytes = new BytesRef
(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), byteBuffer.remaining());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
} else {
fields.add(new SortedDocValuesField(field.getName(), bytes));
}
return fields;
} else {
return Collections.singletonList(createField(field, value, boost));
}
}
示例10: testSortedSetOneValue
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
public void testSortedSetOneValue() throws IOException {
assumeTrue("Codec does not support SORTED_SET", defaultCodecSupportsSortedSet());
Directory directory = newDirectory();
RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
Document doc = new Document();
doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
iwriter.addDocument(doc);
DirectoryReader ireader = iwriter.getReader();
iwriter.close();
SortedSetDocValues dv = getOnlySegmentReader(ireader).getSortedSetDocValues("field");
dv.setDocument(0);
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = new BytesRef();
dv.lookupOrd(0, bytes);
assertEquals(new BytesRef("hello"), bytes);
ireader.close();
directory.close();
}
示例11: testTooLargeTermSortedSetBytes
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
public void testTooLargeTermSortedSetBytes() throws IOException {
assumeTrue("codec does not support SORTED_SET", defaultCodecSupportsSortedSet());
Analyzer analyzer = new MockAnalyzer(random());
Directory directory = newDirectory();
// we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
iwc.setMergePolicy(newLogMergePolicy());
IndexWriter iwriter = new IndexWriter(directory, iwc);
Document doc = new Document();
byte bytes[] = new byte[100000];
BytesRef b = new BytesRef(bytes);
random().nextBytes(bytes);
doc.add(new SortedSetDocValuesField("dv", b));
try {
iwriter.addDocument(doc);
fail("did not get expected exception");
} catch (IllegalArgumentException expected) {
// expected
}
iwriter.close();
directory.close();
}
示例12: createRandomIndex
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
/**
* populates a writer with random stuff. this must be fully reproducable with the seed!
*/
public static void createRandomIndex(int numdocs, RandomIndexWriter writer, long seed) throws IOException {
Random random = new Random(seed);
// primary source for our data is from linefiledocs, its realistic.
LineFileDocs lineFileDocs = new LineFileDocs(random);
// TODO: we should add other fields that use things like docs&freqs but omit positions,
// because linefiledocs doesn't cover all the possibilities.
for (int i = 0; i < numdocs; i++) {
Document document = lineFileDocs.nextDoc();
// grab the title and add some SortedSet instances for fun
String title = document.get("titleTokenized");
String split[] = title.split("\\s+");
for (String trash : split) {
document.add(new SortedSetDocValuesField("sortedset", new BytesRef(trash)));
}
writer.addDocument(document);
}
lineFileDocs.close();
}
示例13: createFields
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
@Override
public List<IndexableField> createFields(SchemaField field, Object value,
float boost) {
if (field.hasDocValues()) {
List<IndexableField> fields = new ArrayList<IndexableField>();
fields.add(createField(field, value, boost));
final BytesRef bytes = new BytesRef(value.toString());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
} else {
fields.add(new SortedDocValuesField(field.getName(), bytes));
}
return fields;
} else {
return Collections.singletonList(createField(field, value, boost));
}
}
示例14: getDoc
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
private Iterable<IndexableField> getDoc(int i) {
Document document = new Document();
document.add(new StringField("test", "test", Store.YES));
document.add(new StringField("info", "info", Store.YES));
if (i == 3) {
document.add(new StringField("shouldnotsee", "shouldnotsee", Store.YES));
}
if (i == 5) {
document.add(new StringField("termmask", "term", Store.YES));
}
document.add(new NumericDocValuesField("number", i));
document.add(new BinaryDocValuesField("bin", new BytesRef(Integer.toString(i).getBytes())));
document.add(new SortedDocValuesField("sorted", new BytesRef(Integer.toString(i).getBytes())));
document.add(new SortedSetDocValuesField("sortedset", new BytesRef(Integer.toString(i).getBytes())));
document.add(new SortedSetDocValuesField("sortedset", new BytesRef(("0" + Integer.toString(i)).getBytes())));
return document;
}
示例15: createFields
import org.apache.lucene.document.SortedSetDocValuesField; //导入依赖的package包/类
@Override
public List<IndexableField> createFields(SchemaField field, Object value, float boost) {
if (field.hasDocValues()) {
List<IndexableField> fields = new ArrayList<IndexableField>();
fields.add(createField(field, value, boost));
final BytesRef bytes = getCollationKey(field.getName(), value.toString());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
} else {
fields.add(new SortedDocValuesField(field.getName(), bytes));
}
return fields;
} else {
return Collections.singletonList(createField(field, value, boost));
}
}