⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.bsh

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 BSH
字号:
/* *  Copyright (c) 2003-2005 The Open For Business Project - www.ofbiz.org * *  Permission is hereby granted, free of charge, to any person obtaining a *  copy of this software and associated documentation files (the "Software"), *  to deal in the Software without restriction, including without limitation *  the rights to use, copy, modify, merge, publish, distribute, sublicense, *  and/or sell copies of the Software, and to permit persons to whom the *  Software is furnished to do so, subject to the following conditions: * *  The above copyright notice and this permission notice shall be included *  in all copies or substantial portions of the Software. * *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *  THE USE OR OTHER DEALINGS IN THE SOFTWARE. * *@author *@version    $Rev: 5462 $ *@since      3.1 */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;paramMap = UtilHttp.getParameterMap(request);queryLine = paramMap.get("queryLine");//Debug.logInfo("in search, queryLine:" + queryLine, "");formDefFile = page.get("formDefFile");queryFormName = page.get("queryFormName");//Debug.logInfo("in search, queryFormName:" + queryFormName, "");HtmlFormWrapper queryWrapper = new HtmlFormWrapper(formDefFile, queryFormName, request, response);context.put("queryWrapper", queryWrapper);listFormName = page.get("listFormName");//Debug.logInfo("in search, listFormName:" + listFormName, "");HtmlFormWrapper listWrapper = new HtmlFormWrapper(formDefFile, listFormName, request, response);context.put("listWrapper", listWrapper);siteId = paramMap.get("siteId");//Debug.logInfo("in search, siteId:" + siteId, "");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);    searcher = new IndexSearcher(indexPath);    analyzer = new StandardAnalyzer();} catch(java.io.FileNotFoundException e) {    Debug.logError(e, "search.bsh");    request.setAttribute("errorMsgReq", "No index file exists.");}if (UtilValidate.isEmpty(siteId)) {    siteId = "WebStoreCONTENT";}termQuery = new TermQuery(new Term("site", siteId.toLowerCase()));combQuery.add(termQuery, true, false);//Debug.logInfo("in search, termQuery:" + termQuery.toString(), "");//Debug.logInfo("in search, combQuery(1):" + combQuery, "");if (UtilValidate.isNotEmpty(queryLine) && analyzer != null) {    Query query = null;    if (UtilValidate.isNotEmpty(queryLine)) {       query = QueryParser.parse(queryLine, "content", analyzer);       combQuery.add(query, true, false);    }}if (!featureIdByType.isEmpty()) {    featureQuery = new BooleanQuery();    anyOrAll = paramMap.get("any_or_all");    boolean featuresRequired = true;    if (anyOrAll != null && anyOrAll.equals("any")) {        featuresRequired = false;    }    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);        }    }    listWrapper.putInContext("queryResults", contentList);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -