Files
ofbiz-framework/applications/content/widget/cms/search.bsh
T
Jacques Le Roux dad67935f7 A (large) patch from Scott Gray "Update ASL header" (https://issues.apache.org/jira/browse/OFBIZ-637).
I put also some svn:ignore for shark build and lib diretories and assetmaint/build 

I did some by hand lately, too much to remember. They were files with old header but without copyright. A 1st attempt I suppose, will have to check this after this commit.

I add some problems to commit this patch in one piece because it's so huge (specially with Eclipse I had to turn to Tortoise) !

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@499486 13f79535-47bb-0310-9956-ffa450edef68
2007-01-24 17:15:54 +00:00

162 lines
7.5 KiB
Plaintext

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.content.search.SearchWorker;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Hits;
import org.apache.lucene.queryParser.QueryParser;
import org.ofbiz.widget.html.HtmlFormWrapper;
import org.ofbiz.product.feature.ParametricSearch;
delegator = request.getAttribute("delegator");
paramMap = UtilHttp.getParameterMap(request);
queryLine = paramMap.get("queryLine");
Debug.logInfo("in search, queryLine:" + queryLine, "");
//formDefFile = page.getProperty("formDefFile");
//queryFormName = page.getProperty("queryFormName");
//Debug.logInfo("in search, queryFormName:" + queryFormName, "");
//HtmlFormWrapper queryWrapper = new HtmlFormWrapper(formDefFile, queryFormName, request, response);
//context.put("queryWrapper", queryWrapper);
//listFormName = page.getProperty("listFormName");
//Debug.logInfo("in search, listFormName:" + listFormName, "");
//HtmlFormWrapper listWrapper = new HtmlFormWrapper(formDefFile, listFormName, request, response);
//context.put("listWrapper", listWrapper);
siteId = paramMap.get("lcSiteId");
Debug.logInfo("in search, siteId:" + siteId, "");
searchFeature1 = paramMap.get("SEARCH_FEAT");
searchFeature2 = paramMap.get("SEARCH_FEAT2");
searchFeature3 = paramMap.get("SEARCH_FEAT3");
Map featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(paramMap);
Debug.logInfo("in search, featureIdByType:" + featureIdByType, "");
combQuery = new BooleanQuery();
String indexPath = null;
Searcher searcher = null;
Analyzer analyzer = null;
try {
indexPath = SearchWorker.getIndexPath(null);
Debug.logInfo("in search, indexPath:" + indexPath, "");
searcher = new IndexSearcher(indexPath);
Debug.logInfo("in search, searcher:" + searcher, "");
analyzer = new StandardAnalyzer();
} catch(java.io.FileNotFoundException e) {
request.setAttribute("errorMsgReq", "No index file exists.");
Debug.logError("in search, error:" + e.getMessage(), "");
}
if (UtilValidate.isNotEmpty(queryLine) || UtilValidate.isNotEmpty(siteId) ) {
// reader = IndexReader.open("/usr/local/agi/ofbiz/applications/content/index");
// Debug.logInfo("in search, reader:" + reader, "");
// termEnum = reader.terms();
// while (termEnum.next()) {
// thisTerm = termEnum.term();
// Debug.logInfo("in search, term:" + thisTerm.toString(), "");
//
// }
Query query = null;
if (UtilValidate.isNotEmpty(queryLine)) {
query = QueryParser.parse(queryLine, "content", analyzer);
combQuery.add(query, true, false);
}
Debug.logInfo("in search, combQuery(0):" + combQuery, "");
if (UtilValidate.isNotEmpty(siteId)) {
termQuery = new TermQuery(new Term("site", siteId));
combQuery.add(termQuery, true, false);
Debug.logInfo("in search, termQuery:" + termQuery.toString(), "");
}
Debug.logInfo("in search, combQuery(1):" + combQuery, "");
}
if ( UtilValidate.isNotEmpty(searchFeature1) || UtilValidate.isNotEmpty(searchFeature2) || UtilValidate.isNotEmpty(searchFeature3) || !featureIdByType.isEmpty() ) {
featureQuery = new BooleanQuery();
anyOrAll = paramMap.get("any_or_all");
boolean featuresRequired = true;
if (anyOrAll != null && anyOrAll.equals("any"))
featuresRequired = false;
if (UtilValidate.isNotEmpty(searchFeature1) ) {
termQuery = new TermQuery(new Term("feature", searchFeature1));
featureQuery.add(termQuery, featuresRequired, false);
Debug.logInfo("in search searchFeature1, termQuery:" + termQuery.toString(), "");
}
if (UtilValidate.isNotEmpty(searchFeature2) ) {
termQuery = new TermQuery(new Term("feature", searchFeature2));
featureQuery.add(termQuery, featuresRequired, false);
Debug.logInfo("in search searchFeature2, termQuery:" + termQuery.toString(), "");
}
if (UtilValidate.isNotEmpty(searchFeature3) ) {
termQuery = new TermQuery(new Term("feature", searchFeature3));
featureQuery.add(termQuery, featuresRequired, false);
Debug.logInfo("in search searchFeature3, termQuery:" + termQuery.toString(), "");
}
if (!featureIdByType.isEmpty()) {
values = featureIdByType.values();
iter = values.iterator();
while (iter.hasNext()) {
val = iter.next();
termQuery = new TermQuery(new Term("feature", val));
featureQuery.add(termQuery, featuresRequired, false);
Debug.logInfo("in search searchFeature3, termQuery:" + termQuery.toString(), "");
}
}
combQuery.add(featureQuery, featuresRequired, false);
}
if (searcher != null) {
Debug.logInfo("in search searchFeature3, combQuery:" + combQuery.toString(), "");
Hits hits = searcher.search(combQuery);
Debug.logInfo("in search, hits:" + hits.length(), "");
List contentList = new ArrayList();
HashSet hitSet = new HashSet();
for (int start = 0; start < hits.length(); start++) {
doc = hits.doc(start);
contentId = doc.get("contentId");
content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
if (!hitSet.contains(contentId)) {
contentList.add(content);
hitSet.add(contentId);
}
}
context.put("queryResults", contentList);
}