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


Java AnalyzeRequestBuilder类代码示例

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

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

示例1: testAnalyzerWithFieldOrTypeTests

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
public void testAnalyzerWithFieldOrTypeTests() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
    ensureGreen();

    client().admin().indices().preparePutMapping("test")
            .setType("document").setSource("simple", "type=text,analyzer=simple").get();

    for (int i = 0; i < 10; i++) {
        final AnalyzeRequestBuilder requestBuilder = client().admin().indices().prepareAnalyze("THIS IS A TEST");
        requestBuilder.setIndex(indexOrAlias());
        requestBuilder.setField("document.simple");
        AnalyzeResponse analyzeResponse = requestBuilder.get();
        assertThat(analyzeResponse.getTokens().size(), equalTo(4));
        AnalyzeResponse.AnalyzeToken token = analyzeResponse.getTokens().get(3);
        assertThat(token.getTerm(), equalTo("test"));
        assertThat(token.getStartOffset(), equalTo(10));
        assertThat(token.getEndOffset(), equalTo(14));
        assertThat(token.getPositionLength(), equalTo(1));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AnalyzeActionIT.java


示例2: testAnalyzerWithMultiValues

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
public void testAnalyzerWithMultiValues() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
    ensureGreen();

    client().admin().indices().preparePutMapping("test")
        .setType("document").setSource("simple", "type=text,analyzer=simple,position_increment_gap=100").get();

    String[] texts = new String[]{"THIS IS A TEST", "THE SECOND TEXT"};

    final AnalyzeRequestBuilder requestBuilder = client().admin().indices().prepareAnalyze();
    requestBuilder.setText(texts);
    requestBuilder.setIndex(indexOrAlias());
    requestBuilder.setField("simple");
    AnalyzeResponse analyzeResponse = requestBuilder.get();
    assertThat(analyzeResponse.getTokens().size(), equalTo(7));
    AnalyzeResponse.AnalyzeToken token = analyzeResponse.getTokens().get(3);
    assertThat(token.getTerm(), equalTo("test"));
    assertThat(token.getPosition(), equalTo(3));
    assertThat(token.getStartOffset(), equalTo(10));
    assertThat(token.getEndOffset(), equalTo(14));
    assertThat(token.getPositionLength(), equalTo(1));

    token = analyzeResponse.getTokens().get(5);
    assertThat(token.getTerm(), equalTo("second"));
    assertThat(token.getPosition(), equalTo(105));
    assertThat(token.getStartOffset(), equalTo(19));
    assertThat(token.getEndOffset(), equalTo(25));
    assertThat(token.getPositionLength(), equalTo(1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:AnalyzeActionIT.java


示例3: analyzeText

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
@Override
public List<String> analyzeText(final String indexAliasName, final String analyzer, final String[] tokenFilters, final String text)
{
    final List<String> tokens = new ArrayList<String>();
    final AnalyzeRequestBuilder analyzeRequestBuilder = searchClientService.getClient().admin().indices().prepareAnalyze(text);
    if (analyzer != null)
    {
        analyzeRequestBuilder.setIndex(indexAliasName);
    }
    if (analyzer != null)
    {
        analyzeRequestBuilder.setAnalyzer(analyzer);
    }
    if (tokenFilters != null)
    {
        analyzeRequestBuilder.setTokenFilters(tokenFilters);
    }
    logger.debug("Analyze request is text: {}, analyzer: {}, tokenfilters: {}", new Object[] { analyzeRequestBuilder.request().text(),
            analyzeRequestBuilder.request().analyzer(), analyzeRequestBuilder.request().tokenFilters() });
    final AnalyzeResponse analyzeResponse = analyzeRequestBuilder.get();
    try
    {
        if (analyzeResponse != null)
        {
            logger.debug("Analyze response is : {}", analyzeResponse.toXContent(jsonBuilder().startObject(), ToXContent.EMPTY_PARAMS)
                    .prettyPrint().string());
        }
    }
    catch (final IOException e)
    {
        logger.error("Error printing response.", e);
    }
    for (final AnalyzeToken analyzeToken : analyzeResponse.getTokens())
    {
        tokens.add(analyzeToken.getTerm());
    }
    return tokens;
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-akka,代码行数:39,代码来源:SetupIndexServiceImpl.java


示例4: analyzeText

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
@Override
public List<String> analyzeText(final String indexAliasName,
		final String analyzer, final String[] tokenFilters,
		final String text) {
	final List<String> tokens = new ArrayList<String>();
	final AnalyzeRequestBuilder analyzeRequestBuilder = searchClientService
			.getClient().admin().indices().prepareAnalyze(text);
	if (analyzer != null) {
		analyzeRequestBuilder.setIndex(indexAliasName);
	}
	if (analyzer != null) {
		analyzeRequestBuilder.setAnalyzer(analyzer);
	}
	if (tokenFilters != null) {
		analyzeRequestBuilder.setTokenFilters(tokenFilters);
	}
	logger.debug(
			"Analyze request is text: {}, analyzer: {}, tokenfilters: {}",
			new Object[] { analyzeRequestBuilder.request().text(),
					analyzeRequestBuilder.request().analyzer(),
					analyzeRequestBuilder.request().tokenFilters() });
	final AnalyzeResponse analyzeResponse = analyzeRequestBuilder.get();
	try {
		if (analyzeResponse != null) {
			logger.debug(
					"Analyze response is : {}",
					analyzeResponse
							.toXContent(jsonBuilder().startObject(),
									ToXContent.EMPTY_PARAMS).prettyPrint()
							.string());
		}
	} catch (final IOException e) {
		logger.error("Error printing response.", e);
	}
	for (final AnalyzeToken analyzeToken : analyzeResponse.getTokens()) {
		tokens.add(analyzeToken.getTerm());
	}
	return tokens;
}
 
开发者ID:jaibeermalik,项目名称:searchanalytics-bigdata,代码行数:40,代码来源:SetupIndexServiceImpl.java


示例5: prepareAnalyze

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
@Override
public AnalyzeRequestBuilder prepareAnalyze(@Nullable String index, String text) {
    return new AnalyzeRequestBuilder(this, AnalyzeAction.INSTANCE, index, text);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AbstractClient.java


示例6: prepareAnalyze

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
default AnalyzeRequestBuilder prepareAnalyze(@NonNull final String text) {
	return getClient().admin().indices().prepareAnalyze(getName(), text);
}
 
开发者ID:thunken,项目名称:sandow,代码行数:4,代码来源:Index.java


示例7: analyzeText

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
@Override
public List<String> analyzeText(String indexAliasName, String analyzer, String[] tokenFilters, String text)
{
    List<String> tokens = new ArrayList<String>();
    
    AnalyzeRequestBuilder analyzeRequestBuilder = searchClientService.getClient().admin().indices().prepareAnalyze(text);
    
    if(analyzer !=null)
    {
        analyzeRequestBuilder.setIndex(indexAliasName);
    }
    if(analyzer !=null)
    {
        analyzeRequestBuilder.setAnalyzer(analyzer);
    }
    
    if(tokenFilters !=null)
    {
        analyzeRequestBuilder.setTokenFilters(tokenFilters);
    }
    
    logger.debug("Analyze request is text: {}, analyzer: {}, tokenfilters: {}", new Object[]{analyzeRequestBuilder.request().text(), 
                                                                                analyzeRequestBuilder.request().analyzer(),
                                                                                analyzeRequestBuilder.request().tokenFilters()});
                                                                                        
    AnalyzeResponse analyzeResponse = analyzeRequestBuilder.get();
    
    try
    {
        if(analyzeResponse != null)
        {
            logger.debug("Analyze response is : {}", analyzeResponse.toXContent(jsonBuilder().startObject(), ToXContent.EMPTY_PARAMS).prettyPrint().string());
        }
    } catch (IOException e)
    {
        logger.error("Error printing response.", e);
    }
    
    for (AnalyzeToken analyzeToken : analyzeResponse.getTokens())
    {
        tokens.add(analyzeToken.getTerm());
    }
    return tokens;
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-tutorial,代码行数:45,代码来源:SetupIndexServiceImpl.java


示例8: prepareAnalyze

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; //导入依赖的package包/类
/**
 * Analyze text under the provided index.
 *
 * @param index The index name
 * @param text  The text to analyze
 */
AnalyzeRequestBuilder prepareAnalyze(@Nullable String index, String text);
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:IndicesAdminClient.java



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