protected Query ne(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) { BooleanQuery bq = new BooleanQuery(); bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), Occur.MUST_NOT)); bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); return bq; }
private int countBooksInIndex() { Session session = openSession(); FullTextSession fullTextSession = Search.getFullTextSession( session ); fullTextSession.beginTransaction(); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ); int size = fullTextQuery.list().size(); fullTextSession.getTransaction().commit(); fullTextSession.close(); return size; }
public static MatchAllDocsQuery newScanQuery() { return new MatchAllDocsQuery(); }
@Test public void singleClass_multipleResults() throws Exception { Session session = openSession(); Transaction tx = session.beginTransaction(); Query luceneQuery = new MatchAllDocsQuery(); FullTextSession fullTextSession = Search.getFullTextSession( session ); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, A.class ); List<?> result = fullTextQuery.list(); assertEquals( "Should match A only", 2, result.size() ); assertPopulated( result ); fullTextSession.clear(); fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, A.class ) .setProjection( ProjectionConstants.THIS ); result = fullTextQuery.list(); assertPopulated( result ); fullTextSession.clear(); fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, A.class ); assertPopulated( fullTextQuery.iterate() ); tx.commit(); fullTextSession.close(); }
@Test public void testExplicitIndexingIgnoresInterceptor() throws Exception { indexTestData(); Transaction tx = fullTextSession.beginTransaction(); for ( Foo foo : testEntities ) { Foo attachedFoo = (Foo) fullTextSession.merge( foo ); fullTextSession.index( attachedFoo ); } tx.commit(); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ); assertEquals( "All test entities should be indexed", testEntities.size(), fullTextQuery.list().size() ); }
@Test public void testProjectionUnmappedFieldValues() throws ParseException, IOException { FullTextSession s = Search.getFullTextSession( getSession() ); Transaction tx = s.beginTransaction(); org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( new MatchAllDocsQuery(), CalendarDay.class ); hibQuery.setProjection( "day.year" ); resetFieldSelector(); List<?> result = hibQuery.list(); assertFieldSelectorEnabled( ); //empty: can't use one as the bridge we use mandates optimisations to be disabled assertNotNull( result ); assertFalse( result.isEmpty() ); tx.commit(); }
@Test public void testStaleCacheWithAsyncIndexer() { Session session = openSession(); final Statistics statistics = session.getSessionFactory().getStatistics(); statistics.clear(); statistics.setStatisticsEnabled( true ); setData( session, statistics ); GatedLuceneBackend.open.set( false ); // disable processing of index updates Transaction tx = session.beginTransaction(); List list = session.createCriteria( Kernel.class ).list(); assertThat( list ).hasSize( 2 ); session.delete( list.get( 0 ) ); tx.commit(); session.clear(); GatedLuceneBackend.open.set( true ); FullTextSession fullTextSession = Search.getFullTextSession( session ); FullTextQuery allKernelsQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ) .initializeObjectsWith( ObjectLookupMethod.SECOND_LEVEL_CACHE, DatabaseRetrievalMethod.QUERY ); assertThat( allKernelsQuery.getResultSize() ).isEqualTo( 2 ); assertThat( allKernelsQuery.list() ).hasSize( 1 ); assertThat( statistics.getSecondLevelCacheHitCount() ).isEqualTo( 1 ); }
@After public void deleteTestData() { Session s = openSession(); FullTextSession session = Search.getFullTextSession( s ); Transaction tx = s.beginTransaction(); QueryDescriptor query = ElasticsearchQueries.fromJson( "{ 'query': { 'match_all' : {} } }" ); List<?> result = session.createFullTextQuery( query, ResearchPaper.class ).list(); for ( Object entity : result ) { session.delete( entity ); } result = session.createFullTextQuery( new MatchAllDocsQuery(), ComicBook.class ).list(); for ( Object entity : result ) { session.delete( entity ); } tx.commit(); s.close(); }
private void assertNumberOfIndexedEntitiesForTypes(int expectedCount, Class<?>... types) { try ( FullTextSession fullTextSession = Search.getFullTextSession( openSession() ) ) { Transaction tx = fullTextSession.beginTransaction(); org.hibernate.query.Query query = fullTextSession.createFullTextQuery( new MatchAllDocsQuery(), types ); @SuppressWarnings("unchecked") List<Object> results = (List<Object>) query.list(); assertEquals( "Incorrect document count for type: " + Arrays.toString( types ), expectedCount, results.size() ); tx.commit(); } }
@SuppressWarnings("unchecked") private List<Blog> getBlogEntries() { Query query = new MatchAllDocsQuery(); return fullTextSession.createFullTextQuery( query, Blog.class ).list(); }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder(); addBooleanClauses(context, booleanQueryBuilder, mustClauses, BooleanClause.Occur.MUST); addBooleanClauses(context, booleanQueryBuilder, mustNotClauses, BooleanClause.Occur.MUST_NOT); addBooleanClauses(context, booleanQueryBuilder, shouldClauses, BooleanClause.Occur.SHOULD); addBooleanClauses(context, booleanQueryBuilder, filterClauses, BooleanClause.Occur.FILTER); BooleanQuery booleanQuery = booleanQueryBuilder.build(); if (booleanQuery.clauses().isEmpty()) { return new MatchAllDocsQuery(); } final String minimumShouldMatch; if (context.isFilter() && this.minimumShouldMatch == null && shouldClauses.size() > 0) { if (mustClauses.size() > 0 || mustNotClauses.size() > 0 || filterClauses.size() > 0) { deprecationLogger.deprecatedAndMaybeLog("filter_context_min_should_match", "Should clauses in the filter context will no longer automatically set the minimum should " + "match to 1 in the next major version. You should group them in a [filter] clause or explicitly set " + "[minimum_should_match] to 1 to restore this behavior in the next major version." ); } minimumShouldMatch = "1"; } else { minimumShouldMatch = this.minimumShouldMatch; } Query query = Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch); return adjustPureNegative ? fixNegativeQueryIfNeeded(query) : query; }
private FullTextQuery matchAll(FacetingRequest request) { Query luceneQuery = new MatchAllDocsQuery(); FullTextQuery query = fullTextSession.createFullTextQuery( luceneQuery, Car.class ); query.getFacetManager().enableFaceting( request ); assertEquals( "Wrong number of indexed cars", 50, query.getResultSize() ); return query; }
private void assertView(FullTextSessionBuilder node) { assertEquals(slaves.size() + 1, clusterSize(node, EMAIL_TYPE)); FullTextSession session = node.openFullTextSession(); try { FullTextQuery fullTextQuery = session.createFullTextQuery(new MatchAllDocsQuery()); int resultSize = fullTextQuery.getResultSize(); assertEquals(storedEmailsCount, resultSize); } finally { session.close(); } }
/** * Look up potentially matching records. */ public Collection<Record> findCandidateMatches(Record record) { if (directory == null) init(); // if we have a geoprop it means that's the only way to search if (geoprop != null) { String value = record.getValue(geoprop.getName()); if (value != null) { Filter filter = geoprop.geoSearch(value); return maintracker.doQuery(new MatchAllDocsQuery(), filter); } } // ok, we didn't do a geosearch, so proceed as normal. // first we build the combined query for all lookup properties BooleanQuery query = new BooleanQuery(); for (Property prop : config.getLookupProperties()) { Collection<String> values = record.getValues(prop.getName()); if (values == null) continue; for (String value : values) parseTokens(query, prop.getName(), value, prop.getLookupBehaviour() == Property.Lookup.REQUIRED, prop.getHighProbability()); } // do the query return maintracker.doQuery(query); }
@Override protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException { double boost = jsonQuery.optDouble(BOOST_PARAM, 1.0); MatchAllDocsQuery q = new MatchAllDocsQuery(); q.setBoost((float) boost); return q; }
BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()); boolean actuallyRewritten = false; for (BooleanClause clause : this) { actuallyRewritten = true; builder.add(rewritten, clause.getOccur()); return new MatchNoDocsQuery("FILTER or MUST clause also in MUST_NOT"); if (mustNotClauses.contains(new MatchAllDocsQuery())) { return new MatchNoDocsQuery("MUST_NOT clause is MatchAllDocsQuery"); boolean modified = filters.remove(new MatchAllDocsQuery()); modified |= filters.removeAll(clauseSets.get(Occur.MUST)); if (modified) { BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()); for (BooleanClause clause : clauses) { if (clause.getOccur() != Occur.FILTER) { BooleanQuery.Builder builder = new BooleanQuery.Builder(); int minShouldMatch = getMinimumNumberShouldMatch();
@Test public void testIndexUpdatesViaMassIndexerProhibitedByInterceptor() throws Exception { indexTestData(); MassIndexer massIndexer = fullTextSession.createIndexer(); massIndexer.startAndWait(); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ); assertEquals( "There should be no indexed entities, since interceptor also applied for mass indexer", 0, fullTextQuery.list().size() ); }
@Test public void testAllRelevantProgressMonitoringOperationsCalled() throws InterruptedException { // let mass indexer re-index the data in the db (created in initializeData()) AssertingMassIndexerProgressMonitor monitor = new AssertingMassIndexerProgressMonitor( 10, 10 ); fullTextSession.createIndexer( LegacyCar.class ) .progressMonitor( monitor ) .startAndWait(); fullTextSession.createFullTextQuery( new MatchAllDocsQuery(), LegacyCar.class ) .getResultSize(); monitor.assertExpectedProgressMade(); }
@Override public Query rewrite(IndexReader reader) throws IOException { final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, BooleanQuery.getMaxClauseCount()); if (types.length <= threshold) { Set<BytesRef> uniqueTypes = new HashSet<>(); BooleanQuery.Builder bq = new BooleanQuery.Builder(); int totalDocFreq = 0; for (BytesRef type : types) { return new MatchAllDocsQuery(); bq.add(new TermQuery(term, context), BooleanClause.Occur.SHOULD); return new ConstantScoreQuery(bq.build());