List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.lucene.match.MatchQueryBuilderTest.java
License:Apache License
@Test public void testTwoFieldsSingleTerm() throws Exception { MatchQueryBuilder builder = new io.crate.lucene.match.MultiMatchQueryBuilder(mockMapperService(), cache, null, Collections.emptyMap()); Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).put("col2", null) .map();//w ww . j av a 2 s . com Query query = builder.query(fields, new BytesRef("foo")); assertThat(query, instanceOf(DisjunctionMaxQuery.class)); }
From source file:io.crate.lucene.match.MatchQueryBuilderTest.java
License:Apache License
@Test public void testTwoFieldsSingleTermMostFields() throws Exception { MatchQueryBuilder builder = new io.crate.lucene.match.MultiMatchQueryBuilder(mockMapperService(), cache, new BytesRef("most_fields"), Collections.emptyMap()); Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).put("col2", null) .map();//from w w w. j a v a2 s .c o m Query query = builder.query(fields, new BytesRef("foo")); assertThat(query, instanceOf(BooleanQuery.class)); }
From source file:io.crate.lucene.match.MatchQueryBuilderTest.java
License:Apache License
@Test public void testCrossFieldMatchType() throws Exception { Analyzer analyzer = new GermanAnalyzer(); MapperService.SmartNameFieldMappers smartNameFieldMappers = mock(MapperService.SmartNameFieldMappers.class); when(smartNameFieldMappers.hasMapper()).thenReturn(true); FieldMapper fieldMapper = mock(FieldMapper.class, Answers.RETURNS_MOCKS.get()); when(smartNameFieldMappers.mapper()).thenReturn(fieldMapper); when(fieldMapper.searchAnalyzer()).thenReturn(analyzer); MapperService mapperService = mock(MapperService.class); when(mapperService.smartName(anyString())).thenReturn(smartNameFieldMappers); when(mapperService.searchAnalyzer()).thenReturn(analyzer); MatchQueryBuilder builder = new io.crate.lucene.match.MultiMatchQueryBuilder(mapperService, cache, new BytesRef("cross_fields"), Collections.emptyMap()); Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).put("col2", null) .map();//from w w w .j a v a2 s .c o m Query query = builder.query(fields, new BytesRef("foo bar")); assertThat(query, instanceOf(BooleanQuery.class)); Query innerQuery = ((BooleanQuery) query).clauses().get(0).getQuery(); assertThat(innerQuery, instanceOf(BlendedTermQuery.class)); }
From source file:io.crate.lucene.match.MatchQueryBuilderTest.java
License:Apache License
@Test public void testFuzzyQuery() throws Exception { MatchQueryBuilder builder = new io.crate.lucene.match.MultiMatchQueryBuilder(mockMapperService(), cache, null, newMapBuilder().put("fuzziness", 2).map()); Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).map(); Query query = builder.query(fields, new BytesRef("foo")); assertThat(query, instanceOf(FuzzyQuery.class)); }
From source file:io.crate.lucene.match.MatchQueryBuilderTest.java
License:Apache License
@Test public void testPhraseQuery() throws Exception { MatchQueryBuilder builder = new MatchQueryBuilder(mockMapperService(), cache, new BytesRef("phrase"), Collections.emptyMap()); Query query = builder.query(MapBuilder.<String, Object>newMapBuilder().put("col1", null).map(), new BytesRef("foo bar")); assertThat(query, instanceOf(PhraseQuery.class)); }
From source file:io.crate.lucene.match.MatchQueryBuilderTest.java
License:Apache License
@Test public void testPhrasePrefix() throws Exception { MatchQueryBuilder builder = new MatchQueryBuilder(mockMapperService(), cache, 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)); }
From source file:io.crate.metadata.blob.BlobTableInfoBuilder.java
License:Apache License
private BytesRef blobsPath(DocIndexMetaData md) { BytesRef blobsPath;/*from ww w . j a v a 2s . c o m*/ String blobsPathStr = metaData.index(md.concreteIndexName()).settings() .get(BlobIndices.SETTING_INDEX_BLOBS_PATH); if (blobsPathStr != null) { blobsPath = new BytesRef(blobsPathStr); } else { File path = blobEnvironment.blobsPath(); if (path != null) { blobsPath = new BytesRef(path.getPath()); } else { File[] dataFiles = environment.dataFiles(); blobsPath = new BytesRef(dataFiles[0].getAbsolutePath()); } } return blobsPath; }
From source file:io.crate.metadata.blob.InternalBlobTableInfoFactory.java
License:Apache License
private BytesRef blobsPath(Settings indexMetaDataSettings) { BytesRef blobsPath;/*from ww w. j av a2 s . c o m*/ String blobsPathStr = BlobIndicesService.SETTING_INDEX_BLOBS_PATH.get(indexMetaDataSettings); if (!Strings.isNullOrEmpty(blobsPathStr)) { blobsPath = new BytesRef(blobsPathStr); } else { Path path = globalBlobPath; if (path != null) { blobsPath = new BytesRef(path.toString()); } else { // TODO: should we set this to null because there is no special blobPath? Path[] dataFiles = environment.dataFiles(); blobsPath = new BytesRef(dataFiles[0].toString()); } } return blobsPath; }
From source file:io.crate.metadata.doc.DocTableInfoBuilderTest.java
License:Apache License
@Test public void testNoTableInfoFromOrphanedPartition() throws Exception { ClusterService clusterService = mock(ClusterService.class); ClusterState clusterState = mock(ClusterState.class); when(clusterService.state()).thenReturn(clusterState); String schemaName = randomSchema(); PartitionName partitionName = new PartitionName(schemaName, "test", Collections.singletonList(new BytesRef("boo"))); IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(partitionName.asIndexName()) .numberOfReplicas(0).numberOfShards(5).putMapping(Constants.DEFAULT_MAPPING_TYPE, "{" + " \"default\": {" + " \"properties\":{" + " \"id\": {" + " \"type\": \"integer\"," + " \"index\": \"not_analyzed\"" + " }" + " }" + " }" + "}"); MetaData metaData = MetaData.builder().put(indexMetaDataBuilder).build(); when(clusterState.metaData()).thenReturn(metaData); DocTableInfoBuilder builder = new DocTableInfoBuilder(null, new TableIdent(schemaName, "test"), clusterService, mock(TransportPutIndexTemplateAction.class), executorService, false); expectedException.expect(TableUnknownException.class); expectedException.expectMessage(String.format(Locale.ENGLISH, "Table '%s.test' unknown", schemaName)); builder.build();/*from w w w . ja va2s . c om*/ }
From source file:io.crate.metadata.information.InformationTableConstraintsTableInfo.java
License:Apache License
public static Map<ColumnIdent, RowCollectExpressionFactory<TableInfo>> expressions() { return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory<TableInfo>>builder() .put(Columns.TABLE_SCHEMA,/*from w w w. j a v a 2 s . c o m*/ () -> RowContextCollectorExpression.objToBytesRef(r -> r.ident().schema())) .put(Columns.TABLE_NAME, () -> RowContextCollectorExpression.objToBytesRef(r -> r.ident().name())) .put(Columns.CONSTRAINT_NAME, () -> RowContextCollectorExpression.forFunction(row -> { BytesRef[] values = new BytesRef[row.primaryKey().size()]; List<ColumnIdent> primaryKey = row.primaryKey(); for (int i = 0, primaryKeySize = primaryKey.size(); i < primaryKeySize; i++) { values[i] = new BytesRef(primaryKey.get(i).fqn()); } return values; })) .put(Columns.CONSTRAINT_TYPE, () -> RowContextCollectorExpression.objToBytesRef(r -> PRIMARY_KEY)) .build(); }