내 프로젝트에서 매우 기본적인 최대 절전 모드 검색을 구현했습니다. 다음은 검색 방법입니다.java.nio.channels.OverlappingFileLockException 최대 절전 모드 검색
public List<Patients> search (String givenName, String middleName, String email, String phoneNumber)
throws InterruptedException, AppException {
fullTextEntityManager = Search.getFullTextEntityManager(EntityManagerUtil.getEntityManager());
fullTextEntityManager.createIndexer().startAndWait();
QueryBuilder qb = fullTextEntityManager
.getSearchFactory()
.buildQueryBuilder()
.forEntity(Patients.class)
.overridesForField("givenName", "customanalyzer_query")
.overridesForField("middleName", "customanalyzer_query")
.overridesForField("email", "customanalyzer_query")
.overridesForField("phoneNumber", "customanalyzer_query")
.get();
org.apache.lucene.search.Query luceneQuery = qb.bool()
.must(qb.keyword().wildcard().onField("givenName").matching(givenName).createQuery())
.must(qb.keyword().wildcard().onField("middleName").matching(middleName).createQuery())
.must(qb.keyword().wildcard().onField("email").matching(email).createQuery())
.must(qb.keyword().wildcard().onField("phoneNumber").matching(phoneNumber).createQuery()).createQuery();
javax.persistence.Query jpaQuery =
fullTextEntityManager.createFullTextQuery(luceneQuery, Patients.class);
@SuppressWarnings("unchecked")
List<Patients> result = jpaQuery.getResultList();
return result;
}
데이터를 읽으려면 Postgresql을 사용하고 있습니다.
처음 실행하면 모든 것이 잘됩니다. 색인이 디렉토리에 작성되면 검색이 완료됩니다.
그런 다음 데이터베이스에 몇 가지 항목을 추가합니다. 추가 한 후에 동일한 검색을 실행합니다. 때로는 원하는 결과를 얻고 때로는 새로 추가 된 항목이 검색에 포함되지 않습니다. 그리고 나는이 예외가 :
ERROR [Hibernate Search: Index updates queue processor for index com.healthelife.DGS.entity.Patients-1] (LuceneBackendQueueTask.java:73) - HSEARCH000073: Error in backend
java.nio.channels.OverlappingFileLockException
at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1108)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:1155)
at org.apache.lucene.store.NativeFSLock.obtain(NativeFSLockFactory.java:217)
at org.apache.lucene.store.Lock.obtain(Lock.java:72)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:1098)
at org.hibernate.search.backend.impl.lucene.IndexWriterHolder.createNewIndexWriter(IndexWriterHolder.java:148)
at org.hibernate.search.backend.impl.lucene.IndexWriterHolder.getIndexWriter(IndexWriterHolder.java:115)
at org.hibernate.search.backend.impl.lucene.AbstractWorkspaceImpl.getIndexWriter(AbstractWorkspaceImpl.java:117)
at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.applyUpdates(LuceneBackendQueueTask.java:99)
at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.run(LuceneBackendQueueTask.java:67)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
ERROR [Hibernate Search: Index updates queue processor for index com.healthelife.DGS.entity.Patients-1] (LogErrorHandler.java:83) - HSEARCH000058: Exception occurred java.nio.channels.OverlappingFileLockException
Primary Failure:
Entity com.healthelife.DGS.entity.Patients Id null Work Type org.hibernate.search.backend.PurgeAllLuceneWork
내 엔티티 클래스 : 당신은 주어진 경로에 대해, 당신은 최대 절전 모드의 여러 인스턴스를 가진되지 않은 루씬 인덱스를 저장하는 데 사용하고 있는지 확인해야합니다
@Produces(MediaType.APPLICATION_JSON)
@XmlRootElement
@AnalyzerDef(name = "customanalyzer_query",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = { @Parameter(name = "language", value = "English")
})
})
@Analyzer(definition = "customanalyzer_query")
public class Patients implements Serializable {
private static final long serialVersionUID = -6061320465621019356L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "personId", nullable = false, unique = true)
private Long personId;
@Column(name = "prefix", nullable = true, unique = false)
private String prefix;
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO, [email protected](definition="customanalyzer_query"))
@Column(name = "givenName", nullable = true, unique = false)
private String givenName;
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO, [email protected](definition="customanalyzer_query"))
@Column(name = "middleName", nullable = true, unique = false)
private String middleName;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "gender", nullable = true)
private Gender gender;
@Column(name = "dateOfBirth", nullable = true, unique = false)
private String dateOfBirth;
@Column(name = "address1", nullable = true, unique = false)
private String address1;
@Column(name = "address2", nullable = true, unique = false)
private String address2;
@Column(name = "postalCode", nullable = true, unique = false)
private String postalCode;
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO, [email protected](definition="customanalyzer_query"))
@Column(name = "phoneNumber", nullable = true, unique = false)
private String phoneNumber;
@Column(name = "phoneExt", nullable = true, unique = false)
private String phoneExt;
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO, [email protected](definition="customanalyzer_query"))
@Column(name = "email", nullable = true, unique = false)
private String email;
@Column(name = "city", nullable = true, unique = false)
private String city;
@Column(name = "dateChanged", nullable = true, unique = false)
private String dateChanged;
@Column(name = "dateCreated", nullable = false, unique = false)
private String dateCreated;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval=true)
@JoinColumn(name = "personIdentifiers", nullable = true)
private PersonIdentifiers personIdentifiers;
@Column(name = "profileImage", nullable = true, unique = false)
private String profileImage;
@Column(name = "nationality", nullable = true, unique = false)
private String nationality;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "visa", nullable = true)
private VisaDetails visa;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "emergencyContact", nullable = true)
private EmergencyContact emergencyContact;
@OneToMany(fetch = FetchType.EAGER, cascade= CascadeType.ALL)
private List<IDProof> idproof = new ArrayList<>();
//getters and setters....
}