Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed poorly thought out update index method

  • Loading branch information...
commit 7db1a8b32985e28dd7562be725976c2e486dd6d1 1 parent 71fe56b
Jesse Eichar jesseeichar authored
46 web/src/main/java/org/fao/geonet/kernel/DataManager.java
View
@@ -59,7 +59,6 @@
import org.fao.geonet.kernel.harvest.HarvestManager;
import org.fao.geonet.kernel.schema.MetadataSchema;
import org.fao.geonet.kernel.search.SearchManager;
-import org.fao.geonet.kernel.search.UpdateIndexFunction;
import org.fao.geonet.kernel.search.spatial.Pair;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.lib.Lib;
@@ -3343,10 +3342,9 @@ public void saveCustomElementSets(Dbms dbms, CustomElementSet customElementSet)
/**
* TODO javadoc.
*/
- class IncreasePopularityTask implements Runnable, UpdateIndexFunction {
+ class IncreasePopularityTask implements Runnable {
private ServiceContext srvContext;
String id;
- private String updatedPopularity;
/**
*
@@ -3366,7 +3364,7 @@ public void run() {
String updateQuery = "UPDATE Metadata SET popularity = popularity +1 WHERE id = ?";
Integer iId = new Integer(id);
dbms.execute(updateQuery, iId);
- searchMan.updateIndex(id, this);
+ indexMetadata(dbms, id);
}
catch (Exception e) {
Log.error(Geonet.DATA_MANAGER, "The following exception is ignored: " + e.getMessage());
@@ -3384,46 +3382,6 @@ public void run() {
}
- @Override
- public void prepareForUpdate() {
- Dbms dbms = null;
- try {
- dbms = (Dbms) srvContext.getResourceManager().openDirect(Geonet.Res.MAIN_DB);
- Integer iId = new Integer(id);
- String selectQuery = "SELECT popularity from Metadata where id = ?";
- Element result = dbms.select(selectQuery, iId).getChild("record");
- this.updatedPopularity = result.getChildText("popularity");
- }
- catch (Exception e) {
- Log.error(Geonet.DATA_MANAGER, "The following exception is ignored: " + e.getMessage());
- e.printStackTrace();
- }
- finally {
- try {
- if (dbms != null) srvContext.getResourceManager().close(Geonet.Res.MAIN_DB, dbms);
- }
- catch (Exception e) {
- Log.error(Geonet.DATA_MANAGER, "There may have been an error updating the popularity of the metadata "+id+". Error: " + e.getMessage());
- e.printStackTrace();
- }
- }
- }
-
- @Override
- public Pair<org.apache.lucene.document.Document, List<CategoryPath>> update(String indexLanguage,
- org.apache.lucene.document.Document currentDocument) {
- String fieldName = "_popularity";
- currentDocument.removeFields(fieldName);
-
- // TODO check config if popularity becomes a numeric
- FieldType fieldType = new FieldType();
- fieldType.setStored(true);
- fieldType.setIndexed(true);
- fieldType.setTokenized(false);
- Field field = new Field(fieldName, this.updatedPopularity, fieldType);
- currentDocument.add(field);
- return Pair.read(currentDocument, null);
- }
}
public enum UpdateDatestamp {
4 web/src/main/java/org/fao/geonet/kernel/search/SearchManager.java
View
@@ -675,10 +675,6 @@ public String getLuceneTermsToExclude() {
return _luceneTermsToExclude;
}
- public void updateIndex(String id, UpdateIndexFunction function) throws Exception {
- this._indexWriter.update(id, function);
- }
-
// indexing methods
/**
42 web/src/main/java/org/fao/geonet/kernel/search/UpdateIndexFunction.java
View
@@ -1,42 +0,0 @@
-package org.fao.geonet.kernel.search;
-
-import java.util.List;
-
-import org.apache.lucene.document.Document;
-import org.apache.lucene.facet.taxonomy.CategoryPath;
-import org.fao.geonet.kernel.search.spatial.Pair;
-
-/**
- * Strategy for updating the documents related to a particular metadata.
- * See {@link SearchManager#updateIndex(String, UpdateIndexFunction)}
- *
- * @author jeichar
- */
-public interface UpdateIndexFunction {
-
- /**
- * Executed just before loading the document to be updated. If
- * there is any database access or other blocking behaviour it should be done
- * here rather that in update because there is not locks held
- * when this is called
- */
- void prepareForUpdate();
- /**
- * Return updated document to update the document.
- *
- * This method must NOT block (access database etc...) because this
- * method is called within a synchronize block and if this method blocks
- * it will block all searches and updates in the system
- *
- * @param indexLanguage language of index that the document comes from
- * @param currentDocument the document loaded from the index
- *
- * @return A pair of the updated document and any category paths to add to the taxonomy (for facets).
- * The pair can be null if there is no desire to update anything for this index or a pair
- * with one or both parts can be null. Null document indicates that the document should not
- * be updated for this index and null (or empty) category path list means that nothing should
- * be added to the taxonomy
- */
- Pair<Document, List<CategoryPath>> update(String indexLanguage, Document currentDocument);
-
-}
61 web/src/main/java/org/fao/geonet/kernel/search/index/LuceneIndexLanguageTracker.java
View
@@ -39,7 +39,6 @@
import org.fao.geonet.kernel.search.IndexAndTaxonomy;
import org.fao.geonet.kernel.search.LuceneConfig;
import org.fao.geonet.kernel.search.SearchManager;
-import org.fao.geonet.kernel.search.UpdateIndexFunction;
import org.fao.geonet.kernel.search.index.GeonetworkNRTManager.AcquireResult;
import org.fao.geonet.kernel.search.spatial.Pair;
@@ -297,64 +296,4 @@ public void run() {
}
}
-
- public void update(String id, UpdateIndexFunction function) throws Exception {
-
- function.prepareForUpdate();
- Map<String, Document> originalDocs = new HashMap<String, Document>();
-
- final Term idTerm = new Term("_id", id);
- synchronized (this) {
- final TermQuery query = new TermQuery(idTerm);
- for (Map.Entry<String, GeonetworkNRTManager> e : searchManagers.entrySet()) {
- String language = e.getKey();
- GeonetworkNRTManager manager = e.getValue();
- AcquireResult result = manager.acquire(-1L, versionTracker);
- try {
- IndexSearcher searcher = result.searcher;
- TopFieldCollector results = TopFieldCollector.create(Sort.INDEXORDER, 2, true, false, false, false);
- searcher.search(query, results);
- TopDocs docs = results.topDocs();
- if (docs.totalHits > 1) {
- Log.error(Geonet.LUCENE, "The " + language
- + " index has more than one document for the metadata with id: " + id);
- } else if (docs.totalHits == 1) {
- Document doc = searcher.doc(docs.scoreDocs[0].doc);
- originalDocs.put(language, doc);
- }
-
- } finally {
- manager.release(result.searcher);
- }
- }
- HashMap<String, Pair<Document, List<CategoryPath>>> updatedDocs = new HashMap<String, Pair<Document, List<CategoryPath>>>();
- for (Entry<String, Document> entry : originalDocs.entrySet()) {
- Pair<Document, List<CategoryPath>> updated = function.update(entry.getKey(), entry.getValue());
- if (updated != null) {
- updatedDocs.put(entry.getKey(), updated);
- }
- }
-
- for (Entry<String, Pair<Document, List<CategoryPath>>> entry : updatedDocs.entrySet()) {
- String lang = entry.getKey();
- Document doc = entry.getValue().one();
- List<CategoryPath> categoryPaths = entry.getValue().two();
-
- if (categoryPaths != null && !categoryPaths.isEmpty()) {
- taxonomyIndexTracker.addDocument(doc, categoryPaths);
- }
-
- if (doc != null) {
- TrackingIndexWriter writer = this.trackingWriters.get(lang);
- if (writer == null) {
- throw new IllegalStateException("Error updating document with id: " + id
- + ". The document was loaded for language: " + lang
- + " but there was no writer for writing the doc");
- }
- writer.updateDocument(idTerm, doc);
- }
- }
- }
- }
-
}
4 web/src/main/java/org/fao/geonet/kernel/search/index/LuceneIndexWriterFactory.java
View
@@ -12,7 +12,6 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.NRTManager.TrackingIndexWriter;
import org.fao.geonet.constants.Geonet;
-import org.fao.geonet.kernel.search.UpdateIndexFunction;
public class LuceneIndexWriterFactory {
@@ -49,7 +48,4 @@ public void createDefaultLocale() throws IOException {
tracker.open(Geonet.DEFAULT_LANGUAGE);
}
- public void update(String id, UpdateIndexFunction function) throws Exception {
- tracker.update(id, function);
- }
}
Please sign in to comment.
Something went wrong with that request. Please try again.