@Override
 public final void performOperation(
     LuceneWork work,
     IndexShardingStrategy shardingStrategy,
     WorkQueuePerIndexSplitter context) {
   IndexManager indexManager =
       shardingStrategy.getIndexManagerForAddition(
           work.getEntityClass(), work.getId(), work.getIdInString(), work.getDocument());
   context.getIndexManagerQueue(indexManager).add(work);
 }
 @Override
 public final void performOperation(
     LuceneWork work,
     IndexShardingStrategy shardingStrategy,
     WorkQueuePerIndexSplitter context) {
   IndexManager[] indexManagers =
       shardingStrategy.getIndexManagersForDeletion(
           work.getEntityClass(), work.getId(), work.getIdInString());
   for (IndexManager indexManager : indexManagers) {
     context.getIndexManagerQueue(indexManager).add(work);
   }
 }
コード例 #3
0
  public void testFieldBridge() throws Exception {
    LeakingLuceneBackend.reset();

    PersonPK johnDoePk = new PersonPK();
    johnDoePk.setFirstName("John");
    johnDoePk.setLastName("Doe");
    PersonCustomDocumentId johnDoe = new PersonCustomDocumentId();
    johnDoe.setFavoriteColor("Blue");
    johnDoe.setPersonNames(johnDoePk);
    johnDoe.setSecurityNumber("AB123");

    Session s = openSession();
    Transaction tx = s.beginTransaction();
    s.save(johnDoe);
    tx.commit();
    s.clear();

    List<LuceneWork> lastProcessedQueue = LeakingLuceneBackend.getLastProcessedQueue();
    assertEquals(1, lastProcessedQueue.size());
    LuceneWork luceneWork = lastProcessedQueue.get(0);
    assertEquals("AB123", luceneWork.getIdInString());

    tx = s.beginTransaction();

    QueryBuilder queryBuilder =
        getSearchFactory().buildQueryBuilder().forEntity(PersonCustomDocumentId.class).get();
    Query query =
        queryBuilder.keyword().onField("id").ignoreAnalyzer().matching("AB123").createQuery();

    List results =
        Search.getFullTextSession(s)
            .createFullTextQuery(query, PersonCustomDocumentId.class)
            .list();
    assertEquals(1, results.size());
    johnDoe = (PersonCustomDocumentId) results.get(0);
    johnDoe.setFavoriteColor("Red");
    tx.commit();
    s.clear();

    tx = s.beginTransaction();
    results =
        Search.getFullTextSession(s)
            .createFullTextQuery(query, PersonCustomDocumentId.class)
            .list();
    assertEquals(1, results.size());
    johnDoe = (PersonCustomDocumentId) results.get(0);
    assertEquals("Red", johnDoe.getFavoriteColor());
    s.delete(results.get(0));
    tx.commit();
    s.close();
  }
コード例 #4
0
 @Override
 public void performWork(LuceneWork work, IndexWriterDelegate delegate, IndexingMonitor monitor) {
   final Serializable id = work.getId();
   final String tenantId = work.getTenantId();
   final Class<?> managedType = work.getEntityClass();
   DocumentBuilderIndexedEntity builder = workspace.getDocumentBuilder(managedType);
   try {
     if (DeleteWorkExecutor.isIdNumeric(builder)) {
       log.tracef(
           "Deleting %s#%s by query using an IndexWriter#updateDocument as id is Numeric",
           managedType, id);
       Query exactMatchQuery =
           NumericFieldUtils.createExactMatchQuery(builder.getIdKeywordName(), id);
       BooleanQuery.Builder deleteDocumentsQueryBuilder = new BooleanQuery.Builder();
       deleteDocumentsQueryBuilder.add(exactMatchQuery, Occur.FILTER);
       if (tenantId != null) {
         TermQuery tenantTermQuery =
             new TermQuery(new Term(DocumentBuilderIndexedEntity.TENANT_ID_FIELDNAME, tenantId));
         deleteDocumentsQueryBuilder.add(tenantTermQuery, Occur.FILTER);
       }
       delegate.deleteDocuments(deleteDocumentsQueryBuilder.build());
       // no need to log the Add operation as we'll log in the delegate
       this.addDelegate.performWork(work, delegate, monitor);
     } else {
       log.tracef("Updating %s#%s by id using an IndexWriter#updateDocument.", managedType, id);
       Term idTerm = new Term(builder.getIdKeywordName(), work.getIdInString());
       Map<String, String> fieldToAnalyzerMap = work.getFieldToAnalyzerMap();
       ScopedAnalyzerReference analyzerReference = builder.getAnalyzerReference();
       analyzerReference =
           AddWorkExecutor.updateAnalyzerMappings(
               workspace, analyzerReference, fieldToAnalyzerMap);
       delegate.updateDocument(idTerm, work.getDocument(), analyzerReference);
     }
     workspace.notifyWorkApplied(work);
   } catch (Exception e) {
     String message = "Unable to update " + managedType + "#" + id + " in index.";
     throw new SearchException(message, e);
   }
   if (monitor != null) {
     monitor.documentsAdded(1l);
   }
 }