diff --git a/applications/content/src/org/ofbiz/content/search/SearchWorker.java b/applications/content/src/org/ofbiz/content/search/SearchWorker.java index ef4e3fe134..150159bf2f 100644 --- a/applications/content/src/org/ofbiz/content/search/SearchWorker.java +++ b/applications/content/src/org/ofbiz/content/search/SearchWorker.java @@ -58,6 +58,8 @@ public class SearchWorker { public static final String module = SearchWorker.class.getName(); + public static final Version LUCENE_VERSION = Version.LUCENE_35; + public static Map indexTree(LocalDispatcher dispatcher, Delegator delegator, String siteId, Map context, String path) throws Exception { Map results = FastMap.newInstance(); GenericValue content = delegator.makeValue("Content", UtilMisc.toMap("contentId", siteId)); @@ -95,24 +97,21 @@ public class SearchWorker { indexContentList(dispatcher, delegator, context, idList, null); } - public static void indexContentList(LocalDispatcher dispatcher, Delegator delegator, Map context,List idList, String path) throws Exception { + public static void indexContentList(LocalDispatcher dispatcher, Delegator delegator, Map context, List idList, String path) throws Exception { Directory directory = FSDirectory.open(new File(getIndexPath(path))); if (Debug.infoOn()) Debug.logInfo("in indexContent, indexAllPath: " + directory.toString(), module); - GenericValue content = null; // Delete existing documents - List contentList = null; IndexReader reader = null; try { reader = IndexReader.open(directory, false); } catch (Exception e) { // ignore } - - contentList = FastList.newInstance(); + List contentList = FastList.newInstance(); for (String id : idList) { if (Debug.infoOn()) Debug.logInfo("in indexContent, id:" + id, module); try { - content = delegator.findOne("Content", UtilMisc .toMap("contentId", id), true); + GenericValue content = delegator.findOne("Content", UtilMisc .toMap("contentId", id), true); if (content != null) { if (reader != null) { deleteContentDocument(content, reader); @@ -130,8 +129,8 @@ public class SearchWorker { // Now create IndexWriter writer = null; long savedWriteLockTimeout = IndexWriterConfig.getDefaultWriteLockTimeout(); - Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34); - IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_34, analyzer); + Analyzer analyzer = new StandardAnalyzer(LUCENE_VERSION); + IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, analyzer); try { IndexWriterConfig.setDefaultWriteLockTimeout(2000); @@ -176,8 +175,8 @@ public class SearchWorker { public static void indexContent(LocalDispatcher dispatcher, Delegator delegator, Map context, GenericValue content, String path) throws Exception { Directory directory = FSDirectory.open(new File(getIndexPath(path))); long savedWriteLockTimeout = IndexWriterConfig.getDefaultWriteLockTimeout(); - Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_35); - IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, analyzer); + Analyzer analyzer = new StandardAnalyzer(LUCENE_VERSION); + IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, analyzer); IndexWriter writer = null; try { try { @@ -227,8 +226,8 @@ public class SearchWorker { public static void indexDataResource(Delegator delegator, Map context, String id, String path) throws Exception { Directory directory = FSDirectory.open(new File(getIndexPath(path))); long savedWriteLockTimeout = IndexWriterConfig.getDefaultWriteLockTimeout(); - Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_35); - IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, analyzer); + Analyzer analyzer = new StandardAnalyzer(LUCENE_VERSION); + IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, analyzer); IndexWriter writer = null; try { diff --git a/applications/content/src/org/ofbiz/content/test/LuceneTests.java b/applications/content/src/org/ofbiz/content/test/LuceneTests.java index d8d0cb604a..44cc835d04 100644 --- a/applications/content/src/org/ofbiz/content/test/LuceneTests.java +++ b/applications/content/src/org/ofbiz/content/test/LuceneTests.java @@ -85,9 +85,9 @@ public class LuceneTests extends OFBizTestCase { String queryLine = "hand"; IndexSearcher searcher = new IndexSearcher(r); - Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_35); + Analyzer analyzer = new StandardAnalyzer(SearchWorker.LUCENE_VERSION); - QueryParser parser = new QueryParser(Version.LUCENE_35, "content", analyzer); + QueryParser parser = new QueryParser(SearchWorker.LUCENE_VERSION, "content", analyzer); Query query = parser.parse(queryLine); combQuery.add(query, BooleanClause.Occur.MUST); diff --git a/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy b/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy index 4f6ef3b86b..d0bd0c1aca 100644 --- a/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy +++ b/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy @@ -56,7 +56,7 @@ try { Debug.logInfo("in search, indexPath:" + directory.toString(), ""); searcher = new IndexSearcher(reader); Debug.logInfo("in search, searcher:" + searcher, ""); - analyzer = new StandardAnalyzer(Version.LUCENE_30); + analyzer = new StandardAnalyzer(SearchWorker.LUCENE_VERSION); } catch (java.io.FileNotFoundException e) { request.setAttribute("errorMsgReq", "No index file exists."); Debug.logError("in search, error:" + e.getMessage(), ""); @@ -66,7 +66,7 @@ try { if (queryLine || siteId) { Query query = null; if (queryLine) { - QueryParser parser = new QueryParser(Version.LUCENE_30, "content", analyzer); + QueryParser parser = new QueryParser(SearchWorker.LUCENE_VERSION, "content", analyzer); query = parser.parse(queryLine); combQuery.add(query, BooleanClause.Occur.MUST); } diff --git a/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy b/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy index 8b3d1aa95f..3a25023800 100644 --- a/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy +++ b/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy @@ -57,7 +57,7 @@ Searcher searcher = null; Analyzer analyzer = null; try { searcher = new IndexSearcher(reader); - analyzer = new StandardAnalyzer(Version.LUCENE_30); + analyzer = new StandardAnalyzer(SearchWorker.LUCENE_VERSION); } catch (java.io.FileNotFoundException e) { Debug.logError(e, "Search.groovy"); request.setAttribute("errorMsgReq", "No index file exists."); @@ -69,7 +69,7 @@ combQuery.add(termQuery, BooleanClause.Occur.MUST); //Debug.logInfo("in search, combQuery(1):" + combQuery, ""); if (queryLine && analyzer) { Query query = null; - QueryParser parser = new QueryParser(Version.LUCENE_30, "content", analyzer); + QueryParser parser = new QueryParser(SearchWorker.LUCENE_VERSION, "content", analyzer); query = parser.parse(queryLine); combQuery.add(query, BooleanClause.Occur.MUST); }