public static SingularTermDeletionQuery fromString(String[] string) { if ( string.length != 3 ) { throw new IllegalArgumentException( "To instantiate a SingularTermDeletionQuery, an array of size 3 is required" + " (type, fieldName, value). Got an array of size " + string.length ); } Type type = Type.valueOf( string[0] ); switch ( type ) { case STRING: return new SingularTermDeletionQuery( string[1], string[2] ); case INT: return new SingularTermDeletionQuery( string[1], Integer.parseInt( string[2] ) ); case FLOAT: return new SingularTermDeletionQuery( string[1], Float.parseFloat( string[2] ) ); case LONG: return new SingularTermDeletionQuery( string[1], Long.parseLong( string[2] ) ); case DOUBLE: return new SingularTermDeletionQuery( string[1], Double.parseDouble( string[2] ) ); default: throw new AssertionFailure( "Unsupported value type: " + type ); } }
public static SingularTermDeletionQuery fromString(String[] string) { if ( string.length != 3 ) { throw new IllegalArgumentException( "To instantiate a SingularTermDeletionQuery, an array of size 3 is required" + " (type, fieldName, value). Got an array of size " + string.length ); } Type type = Type.valueOf( string[0] ); switch ( type ) { case STRING: return new SingularTermDeletionQuery( string[1], string[2] ); case INT: return new SingularTermDeletionQuery( string[1], Integer.parseInt( string[2] ) ); case FLOAT: return new SingularTermDeletionQuery( string[1], Float.parseFloat( string[2] ) ); case LONG: return new SingularTermDeletionQuery( string[1], Long.parseLong( string[2] ) ); case DOUBLE: return new SingularTermDeletionQuery( string[1], Double.parseDouble( string[2] ) ); default: throw new AssertionFailure( "Unsupported value type: " + type ); } }
private List<SingularTermDeletionQuery> buildNumQueries() { List<SingularTermDeletionQuery> l = new ArrayList<>(); { l.add( new SingularTermDeletionQuery( "intField", 1 ) ); l.add( new SingularTermDeletionQuery( "longField", 1L ) ); l.add( new SingularTermDeletionQuery( "floatField", 1F ) ); l.add( new SingularTermDeletionQuery( "doubleField", 1D ) ); } return l; }
private List<DeletionQuery> buildQueries() { List<DeletionQuery> l = new ArrayList<>(); l.add( new SingularTermDeletionQuery( "id", "123" ) ); l.addAll( this.buildNumQueries() ); return l; }
private List<LuceneWork> buildLuceneWorkList() throws Exception { List<LuceneWork> works = new ArrayList<LuceneWork>(); works.add( OptimizeLuceneWork.INSTANCE ); works.add( OptimizeLuceneWork.INSTANCE ); works.add( new OptimizeLuceneWork( remoteTypeId ) ); //won't be send over works.add( new PurgeAllLuceneWork( remoteTypeId ) ); works.add( new PurgeAllLuceneWork( remoteTypeId ) ); works.add( new DeleteByQueryLuceneWork( remoteTypeId, new SingularTermDeletionQuery( "key", "value" ) ) ); works.add( new DeleteLuceneWork( 123L, "123", remoteTypeId ) ); works.add( new DeleteLuceneWork( "Sissi", "Sissi", remoteTypeId ) ); works.add( new DeleteLuceneWork( new URL( "http://emmanuelbernard.com" ), "http://emmanuelbernard.com", remoteTypeId ) ); Document doc = buildDocumentWithNumericFields(); Map<String, String> analyzers = new HashMap<String, String>(); analyzers.put( "godo", "ngram" ); works.add( new AddLuceneWork( 123, "123", remoteTypeId, doc, analyzers ) ); doc = buildDocumentWithMultipleMixedTypeFields(); works.add( new UpdateLuceneWork( 1234, "1234", remoteTypeId, doc ) ); works.add( new AddLuceneWork( 125, "125", remoteTypeId, new Document() ) ); return works; }
@Test public void testStringIdTermQuery() { ExtendedSearchIntegrator integrator = this.factoryHolder.getSearchFactory(); Worker worker = integrator.getWorker(); makeBooksForSingularTermQuery(); this.assertCount( Book.class, 2 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "id", String.valueOf( 5 ) ) ), tc ); tc.end(); } this.assertCount( Book.class, 1 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "id", String.valueOf( 6 ) ) ), tc ); tc.end(); } this.assertCount( Book.class, 0 ); // this should stay empty now! }
@Test public void testNumericIdTermQuery() { ExtendedSearchIntegrator integrator = this.factoryHolder.getSearchFactory(); Worker worker = integrator.getWorker(); makeMoviesForNumericIdTermQuery(); this.assertCount( Movie.class, 2 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( MOVIE_TYPE, new SingularTermDeletionQuery( "id", 3 ) ), tc ); tc.end(); } this.assertCount( Movie.class, 1 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( MOVIE_TYPE, new SingularTermDeletionQuery( "id", 4 ) ), tc ); tc.end(); } this.assertCount( Movie.class, 0 ); // this should stay empty now! }
@Test public void testSingularTermQuery() { ExtendedSearchIntegrator integrator = this.factoryHolder.getSearchFactory(); Worker worker = integrator.getWorker(); makeBooksForSingularTermQuery(); this.assertCount( Book.class, 2 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "url", "lordoftherings" ) ), tc ); tc.end(); } this.assertCount( Book.class, 1 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "url", "thehobbit" ) ), tc ); tc.end(); } this.assertCount( Book.class, 0 ); // this should stay empty now! }
@Test public void canDeleteByQuery() throws Exception { Session s = openSession(); FullTextSession session = Search.getFullTextSession( s ); ExtendedSearchIntegrator integrator = session.getSearchFactory() .unwrap( ExtendedSearchIntegrator.class ); DeleteByQueryWork queryWork = new DeleteByQueryWork( new PojoIndexedTypeIdentifier( HockeyPlayer.class ), new SingularTermDeletionQuery( "active", "false" ) ); TransactionContext tc = new TransactionContextForTest(); integrator.getWorker().performWork( queryWork, tc ); integrator.getWorker().flushWorks( tc ); QueryDescriptor query = ElasticsearchQueries.fromJson( "{ 'query': { 'match_all' : {} } }" ); Transaction tx = s.beginTransaction(); @SuppressWarnings("unchecked") List<HockeyPlayer> result = session.createFullTextQuery( query, HockeyPlayer.class ).list(); assertThat( result ).extracting( "name" ).containsExactlyInAnyOrder( "Hergesheimer", "Brand" ); tx.commit(); s.close(); }
DOWN_TO_THE_EARTH, new PojoIndexedTypeIdentifier( HockeyPlayer.class ), new SingularTermDeletionQuery( "active", "false" ) );
TransactionContextForTest tc = new TransactionContextForTest(); ExtendedSearchIntegrator integrator = this.getExtendedSearchIntegrator(); integrator.getWorker().performWork( new DeleteByQueryWork( TSHIRT_TYPE, new SingularTermDeletionQuery( "id", String.valueOf( ts.getId() ) ) ), tc ); tc.end(); tx.commit();
DeleteByQueryLuceneWork work = new DeleteByQueryLuceneWork( tshirtType, new SingularTermDeletionQuery( "logo", "jboss" ) ); List<LuceneWork> l = new ArrayList<>(); l.add( work );