Examples of ClusteringActionResponse


Examples of org.carrot2.elasticsearch.ClusteringAction.ClusteringActionResponse

            tasks.add(new Callable<ClusteringActionResponse>() {
                public ClusteringActionResponse call() throws Exception {
                    System.out.print(">");
                    System.out.flush();

                    ClusteringActionResponse result = new ClusteringActionRequestBuilder(client)
                        .setQueryHint("data mining")
                        .addFieldMapping("title", LogicalField.TITLE)
                        .addHighlightedFieldMapping("content", LogicalField.CONTENT)
                        .setSearchRequest(
                          client.prepareSearch()
                                .setIndices(INDEX_NAME)
                                .setTypes("test")
                                .setSize(100)
                                .setQuery(QueryBuilders.termQuery("_all", "data"))
                                .setHighlighterPreTags("")
                                .setHighlighterPostTags("")
                                .addField("title")
                                .addHighlightedField("content"))
                        .execute().actionGet();

                    System.out.print("<");
                    System.out.flush();
                    checkValid(result);
                    checkJsonSerialization(result);
                    return result;
                }
            });
        }

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        try {
            for (Future<ClusteringActionResponse> future : executor.invokeAll(tasks)) {
                ClusteringActionResponse response = future.get();
                Assertions.assertThat(response).isNotNull();
                Assertions.assertThat(response.getSearchResponse()).isNotNull();
            }
        } finally {
            executor.shutdown();
            System.out.println("Done.");
        }
View Full Code Here

Examples of org.carrot2.elasticsearch.ClusteringAction.ClusteringActionResponse

* Java API tests for {@link ClusteringAction}.
*/
public class ClusteringActionTests extends AbstractApiTest {
    @Test(dataProvider = "clients")
    public void testComplexQuery(Client client) throws IOException {
        ClusteringActionResponse result = new ClusteringActionRequestBuilder(client)
            .setQueryHint("data mining")
            .addFieldMapping("title", LogicalField.TITLE)
            .addHighlightedFieldMapping("content", LogicalField.CONTENT)
            .setSearchRequest(
              client.prepareSearch()
View Full Code Here

Examples of org.carrot2.elasticsearch.ClusteringAction.ClusteringActionResponse

    public void testAttributes(Client client) throws IOException {
        Map<String,Object> attrs = Maps.newHashMap();
        LingoClusteringAlgorithmDescriptor.attributeBuilder(attrs)
            .desiredClusterCountBase(5);

        ClusteringActionResponse result = new ClusteringActionRequestBuilder(client)
            .setQueryHint("data mining")
            .addFieldMapping("title", LogicalField.TITLE)
            .addFieldMapping("content", LogicalField.CONTENT)
            .addAttributes(attrs)
            .setSearchRequest(
              client.prepareSearch()
                    .setIndices(INDEX_NAME)
                    .setTypes("test")
                    .setSize(100)
                    .setQuery(QueryBuilders.termQuery("_all", "data"))
                    .addFields("title", "content"))
            .execute().actionGet();

        checkValid(result);
        checkJsonSerialization(result);
       
        Assertions.assertThat(result.getDocumentGroups())
            .hasSize(5 + /* other topics */ 1);
    }
View Full Code Here

Examples of org.carrot2.elasticsearch.ClusteringAction.ClusteringActionResponse

        // constants from the descriptor.
        attrs.put(
                MultilingualClusteringDescriptor.Keys.LANGUAGE_AGGREGATION_STRATEGY,
                LanguageAggregationStrategy.FLATTEN_NONE.name());

        ClusteringActionResponse result = new ClusteringActionRequestBuilder(client)
            .setQueryHint("data mining")
            .addFieldMapping("title", LogicalField.TITLE)
            .addFieldMapping("content", LogicalField.CONTENT)
            .addFieldMapping("rndlang", LogicalField.LANGUAGE)
            .addAttributes(attrs)
            .setSearchRequest(
              client.prepareSearch()
                    .setIndices(INDEX_NAME)
                    .setTypes("test")
                    .setSize(100)
                    .setQuery(QueryBuilders.termQuery("_all", "data"))
                    .addFields("title", "content", "rndlang"))
            .get();

        checkValid(result);
        checkJsonSerialization(result);

        // Top level groups should be input documents' languages (aggregation strategy above).
        DocumentGroup[] documentGroups = result.getDocumentGroups();
        Set<String> allLanguages = Sets.newHashSet();
        for (LanguageCode code : LanguageCode.values()) {
            allLanguages.add(code.toString());
        }
View Full Code Here

Examples of org.carrot2.elasticsearch.ClusteringAction.ClusteringActionResponse

            .contains("stc", "lingo", "kmeans");
    }

    @Test(dataProvider = "clients")
    public void testNonexistentFields(Client client) throws IOException {
        ClusteringActionResponse result = new ClusteringActionRequestBuilder(client)
            .setQueryHint("data mining")
            .addFieldMapping("_nonexistent_", LogicalField.TITLE)
            .addFieldMapping("_nonexistent_", LogicalField.CONTENT)
            .setSearchRequest(
              client.prepareSearch()
                    .setIndices(INDEX_NAME)
                    .setTypes("test")
                    .setSize(100)
                    .setQuery(QueryBuilders.termQuery("_all", "data"))
                    .addFields("title", "content"))
            .execute().actionGet();

        // There should be no clusters, but no errors.
        checkValid(result);
        checkJsonSerialization(result);

        // Top level groups should be input documents' languages (aggregation strategy above).
        DocumentGroup[] documentGroups = result.getDocumentGroups();
        for (DocumentGroup group : documentGroups) {
            if (!group.isOtherTopics()) {
                Assertions.fail("Expected no clusters for non-existent fields.");
            }
        }
View Full Code Here

Examples of org.carrot2.elasticsearch.ClusteringAction.ClusteringActionResponse

                .setSize(2)
                .setQuery(QueryBuilders.termQuery("_all", "data"))
                .addField("content");

        // with hits (default)
        ClusteringActionResponse resultWithHits = new ClusteringActionRequestBuilder(client)
            .setQueryHint("data mining")
            .setAlgorithm("stc")
            .addFieldMapping("title", LogicalField.TITLE)
            .setSearchRequest(req)
            .execute().actionGet();
        checkValid(resultWithHits);
        checkJsonSerialization(resultWithHits);
        // get JSON output
        XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
        builder.startObject();
        resultWithHits.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.endObject();
        JSONObject jsonWithHits = new JSONObject(builder.string());
        Assertions.assertThat(jsonWithHits.has("hits")).isTrue();

        // without hits
        ClusteringActionResponse resultWithoutHits = new ClusteringActionRequestBuilder(client)
            .setQueryHint("data mining")
            .setIncludeHits("false")
            .setAlgorithm("stc")
            .addFieldMapping("title", LogicalField.TITLE)
            .setSearchRequest(req)
            .execute().actionGet();
        checkValid(resultWithoutHits);
        checkJsonSerialization(resultWithoutHits);

        // get JSON output
        builder = XContentFactory.jsonBuilder().prettyPrint();
        builder.startObject();
        resultWithoutHits.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.endObject();
        JSONObject jsonWithoutHits = new JSONObject(builder.string());
        Assertions.assertThat(
                jsonWithoutHits
                    .getJSONObject("hits")
View Full Code Here

Examples of org.carrot2.elasticsearch.ClusteringAction.ClusteringActionResponse

                .setSize(2)
                .setQuery(QueryBuilders.termQuery("_all", "data"))
                .addField("content");

        // Limit the set of hits to just top 2.
        ClusteringActionResponse limitedHits = new ClusteringActionRequestBuilder(client)
            .setQueryHint("data mining")
            .setMaxHits(2)
            .setAlgorithm("stc")
            .addFieldMapping("title", LogicalField.TITLE)
            .setSearchRequest(req)
            .execute().actionGet();
        checkValid(limitedHits);
        checkJsonSerialization(limitedHits);

        Assertions.assertThat(limitedHits.getSearchResponse().getHits().hits())
            .hasSize(2);

        // get JSON output
        XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
        builder.startObject();
        limitedHits.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.endObject();
        JSONObject json = new JSONObject(builder.string());
        Assertions.assertThat(json
                    .getJSONObject("hits")
                    .getJSONArray("hits").length()).isEqualTo(2);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.