Search in sources :

Example 16 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class MatchQueryBuilderTest method testPhrasePrefix.

@Test
public void testPhrasePrefix() throws Exception {
    MatchQueryBuilder builder = new MatchQueryBuilder(mockMapperService(), new BytesRef("phrase_prefix"), Collections.emptyMap());
    Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).map();
    Query query = builder.query(fields, new BytesRef("foo"));
    assertThat(query, instanceOf(MultiPhrasePrefixQuery.class));
}
Also used : MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) ExtendedCommonTermsQuery(org.apache.lucene.queries.ExtendedCommonTermsQuery) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 17 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class MatchQueryBuilderTest method testUnknownMatchType.

@Test
public void testUnknownMatchType() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Unknown matchType \"foo\". Possible matchTypes are: best_fields, most_fields, cross_fields, phrase, phrase_prefix");
    new MatchQueryBuilder(null, new BytesRef("foo"), Collections.emptyMap());
}
Also used : MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 18 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class MatchQueryBuilderTest method testSingleFieldWithCutFrequency.

@Test
public void testSingleFieldWithCutFrequency() throws Exception {
    MatchQueryBuilder builder = new MatchQueryBuilder(mockMapperService(), null, newMapBuilder().put("cutoff_frequency", 3).map());
    Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).map();
    Query query = builder.query(fields, new BytesRef("foo bar"));
    assertThat(query, instanceOf(ExtendedCommonTermsQuery.class));
}
Also used : MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) ExtendedCommonTermsQuery(org.apache.lucene.queries.ExtendedCommonTermsQuery) ExtendedCommonTermsQuery(org.apache.lucene.queries.ExtendedCommonTermsQuery) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 19 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class TableIdentTest method testFromIndexName.

@Test
public void testFromIndexName() throws Exception {
    assertThat(TableIdent.fromIndexName("t"), is(new TableIdent(null, "t")));
    assertThat(TableIdent.fromIndexName("s.t"), is(new TableIdent("s", "t")));
    PartitionName pn = new PartitionName("s", "t", ImmutableList.of(new BytesRef("v1")));
    assertThat(TableIdent.fromIndexName(pn.asIndexName()), is(new TableIdent("s", "t")));
    pn = new PartitionName(null, "t", ImmutableList.of(new BytesRef("v1")));
    assertThat(TableIdent.fromIndexName(pn.asIndexName()), is(new TableIdent(null, "t")));
}
Also used : BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 20 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class PartitionNameTest method testFromIndexOrTemplate.

@Test
public void testFromIndexOrTemplate() throws Exception {
    PartitionName partitionName = new PartitionName("t", Arrays.asList(new BytesRef("a"), new BytesRef("b")));
    assertThat(partitionName, equalTo(PartitionName.fromIndexOrTemplate(partitionName.asIndexName())));
    partitionName = new PartitionName(null, "t", Arrays.asList(new BytesRef("a"), new BytesRef("b")));
    assertThat(partitionName, equalTo(PartitionName.fromIndexOrTemplate(partitionName.asIndexName())));
    assertThat(partitionName.ident(), is("081620j2"));
    partitionName = new PartitionName("schema", "t", Arrays.asList(new BytesRef("a"), new BytesRef("b")));
    assertThat(partitionName, equalTo(PartitionName.fromIndexOrTemplate(partitionName.asIndexName())));
    assertThat(partitionName.ident(), is("081620j2"));
    partitionName = new PartitionName(null, "t", Collections.singletonList(new BytesRef("hoschi")));
    assertThat(partitionName, equalTo(PartitionName.fromIndexOrTemplate(partitionName.asIndexName())));
    assertThat(partitionName.ident(), is("043mgrrjcdk6i"));
    partitionName = new PartitionName(null, "t", Collections.<BytesRef>singletonList(null));
    assertThat(partitionName, equalTo(PartitionName.fromIndexOrTemplate(partitionName.asIndexName())));
    assertThat(partitionName.ident(), is("0400"));
}
Also used : BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

BytesRef (org.apache.lucene.util.BytesRef)1448 Document (org.apache.lucene.document.Document)409 Directory (org.apache.lucene.store.Directory)370 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)266 ArrayList (java.util.ArrayList)186 Test (org.junit.Test)182 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)164 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)152 Term (org.apache.lucene.index.Term)123 Analyzer (org.apache.lucene.analysis.Analyzer)121 IndexReader (org.apache.lucene.index.IndexReader)121 TermsEnum (org.apache.lucene.index.TermsEnum)116 SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)110 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)105 IOException (java.io.IOException)103 Field (org.apache.lucene.document.Field)101 StringField (org.apache.lucene.document.StringField)100 CrateUnitTest (io.crate.test.integration.CrateUnitTest)95 TextField (org.apache.lucene.document.TextField)94 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)87