Search in sources :

Example 1 with SimilarityProvider

use of org.elasticsearch.index.similarity.SimilarityProvider in project elasticsearch-skywalker by jprante.

the class Skywalker method getFieldInfo.

public Map<String, Object> getFieldInfo(MapperService mapperService, FieldInfo fi) {
    Map<String, Object> m = new HashMap();
    m.put("name", fi.name);
    m.put("number", fi.number);
    m.put("isIndexed", fi.isIndexed());
    m.put("hasDocValues", fi.hasDocValues());
    m.put("hasNorms", fi.hasNorms());
    m.put("hasPayloads", fi.hasPayloads());
    m.put("hasVectors", fi.hasVectors());
    if (fi.getDocValuesType() != null) {
        m.put("docValuesType", fi.getDocValuesType().name());
    }
    if (fi.getNormType() != null) {
        m.put("normType", fi.getNormType().name());
    }
    if (fi.getIndexOptions() != null) {
        m.put("options", fi.getIndexOptions().name());
    }
    m.put("attributes", fi.attributes());
    FieldMapper fieldMapper = mapperService.smartNameFieldMapper(fi.name);
    if (fieldMapper != null) {
        Map<String, Object> mapper = new HashMap();
        mapper.put("fullName", fieldMapper.names().fullName());
        mapper.put("indexName", fieldMapper.names().indexName());
        mapper.put("indexNameClean", fieldMapper.names().indexNameClean());
        mapper.put("boost", fieldMapper.boost());
        if (fieldMapper.indexAnalyzer() != null) {
            mapper.put("indexAnalyzer", fieldMapper.indexAnalyzer().toString());
        }
        if (fieldMapper.searchAnalyzer() != null) {
            mapper.put("searchAnalyzer", fieldMapper.searchAnalyzer().toString());
        }
        if (fieldMapper.searchQuoteAnalyzer() != null) {
            mapper.put("searchQuoteAnalyzer", fieldMapper.searchQuoteAnalyzer().toString());
        }
        FieldDataType dataType = fieldMapper.fieldDataType();
        if (dataType != null) {
            mapper.put("fieldDataType", dataType.getType());
        }
        FieldType type = fieldMapper.fieldType();
        if (type != null) {
            mapper.put("indexed", type.indexed());
            mapper.put("stored", type.stored());
            mapper.put("tokenized", type.tokenized());
            mapper.put("omitNorms", type.omitNorms());
            mapper.put("storeTermVectors", type.storeTermVectors());
            mapper.put("storeTermVectorOffsets", type.storeTermVectorOffsets());
            mapper.put("storeTermVectorPayloads", type.storeTermVectorPayloads());
            mapper.put("storeTermVectorPositions", type.storeTermVectorPositions());
            if (type.numericType() != null) {
                mapper.put("numericType", type.numericType().name());
                mapper.put("numericPrecisionStep", type.numericPrecisionStep());
            }
            if (type.docValueType() != null) {
                mapper.put("docValueType", type.docValueType().name());
            }
        }
        SimilarityProvider similarityProvider = fieldMapper.similarity();
        if (similarityProvider != null) {
            mapper.put("similarityPovider", similarityProvider.name());
            mapper.put("similarity", similarityProvider.get().getClass().getName());
        }
        PostingsFormatProvider postingsFormatProvider = fieldMapper.postingsFormatProvider();
        if (postingsFormatProvider != null) {
            mapper.put("postingsFormatProvider", postingsFormatProvider.name());
            mapper.put("postingsFormat", postingsFormatProvider.get().getName());
        }
        m.put("mapper", mapper);
    }
    return m;
}
Also used : FieldDataType(org.elasticsearch.index.fielddata.FieldDataType) SimilarityProvider(org.elasticsearch.index.similarity.SimilarityProvider) PostingsFormatProvider(org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider) FieldMapper(org.elasticsearch.index.mapper.FieldMapper) FieldType(org.apache.lucene.document.FieldType)

Example 2 with SimilarityProvider

use of org.elasticsearch.index.similarity.SimilarityProvider in project elasticsearch by elastic.

the class IndexModuleTests method testAddSimilarity.

public void testAddSimilarity() throws IOException {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.similarity.my_similarity.type", "test_similarity").put("index.similarity.my_similarity.key", "there is a key").put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.addSimilarity("test_similarity", (string, providerSettings, indexLevelSettings) -> new SimilarityProvider() {

        @Override
        public String name() {
            return string;
        }

        @Override
        public Similarity get() {
            return new TestSimilarity(providerSettings.get("key"));
        }
    });
    IndexService indexService = newIndexService(module);
    SimilarityService similarityService = indexService.similarityService();
    assertNotNull(similarityService.getSimilarity("my_similarity"));
    assertTrue(similarityService.getSimilarity("my_similarity").get() instanceof TestSimilarity);
    assertEquals("my_similarity", similarityService.getSimilarity("my_similarity").name());
    assertEquals("there is a key", ((TestSimilarity) similarityService.getSimilarity("my_similarity").get()).key);
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) SimilarityProvider(org.elasticsearch.index.similarity.SimilarityProvider) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) Similarity(org.apache.lucene.search.similarities.Similarity) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings)

Aggregations

SimilarityProvider (org.elasticsearch.index.similarity.SimilarityProvider)2 FieldType (org.apache.lucene.document.FieldType)1 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)1 Similarity (org.apache.lucene.search.similarities.Similarity)1 Settings (org.elasticsearch.common.settings.Settings)1 AnalysisRegistry (org.elasticsearch.index.analysis.AnalysisRegistry)1 PostingsFormatProvider (org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider)1 FieldDataType (org.elasticsearch.index.fielddata.FieldDataType)1 FieldMapper (org.elasticsearch.index.mapper.FieldMapper)1 SimilarityService (org.elasticsearch.index.similarity.SimilarityService)1 ScriptSettings (org.elasticsearch.script.ScriptSettings)1