List of usage examples for org.apache.lucene.search BooleanQuery setMaxClauseCount
public static void setMaxClauseCount(int maxClauseCount)
From source file:servlet.Checkcopy.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j ava 2 s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession ss = request.getSession(); Assignment a = (Assignment) ss.getAttribute("curAm"); int safv_id = Integer.parseInt(request.getParameter("safv_id")); String studentAmPath = getServletContext().getRealPath("/") + "/file/student_assignment_file/"; if (a.getAss_type().equalsIgnoreCase("file")) { StAssignmentFile sa = (StAssignmentFile) ss.getAttribute("sa"); StAmFileList f = StAmFileList.getSafvByListIdSafv(safv_id, sa.getList_id()); String filename = f.getPath_file(); String fileExtension = filename.substring(filename.lastIndexOf(".") + 1); String keyword = ""; if (fileExtension.equalsIgnoreCase("docx")) { keyword = DocumentFunction.readDocxFile(studentAmPath + filename); } else if (fileExtension.equalsIgnoreCase("doc")) { keyword = DocumentFunction.readDocFile(studentAmPath + filename); } else if (fileExtension.equalsIgnoreCase("xls")) { keyword = DocumentFunction.readXlsFile(studentAmPath + filename); } else if (fileExtension.equalsIgnoreCase("xlsx")) { keyword = DocumentFunction.readXlsxFile(studentAmPath + filename); } else if (fileExtension.equalsIgnoreCase("pdf")) { keyword = DocumentFunction.readPdfFile(studentAmPath + filename); } if (!keyword.equals("")) { System.out.println("----------------------search..."); Directory directory = null; IndexReader indexReader; ArrayList<String[]> indexsetList = null; try { directory = FSDirectory.open( new File(studentAmPath + "//" + a.getCourse().getCourse_id() + "//" + sa.getAm_id())); indexReader = DirectoryReader.open(directory); IndexSearcher searcher = new IndexSearcher(indexReader); BooleanQuery.setMaxClauseCount(20000); QueryParser parser = new QueryParser(Version.LUCENE_47, "student_assignment", new ThaiAnalyzer(Version.LUCENE_47)); Query query = parser.parse(QueryParser.escape(keyword)); int hitsPerPage = 10; Sort sort = new Sort(new SortField[] { SortField.FIELD_SCORE, new SortField("student_assignment", SortField.Type.STRING) }); TopFieldCollector topField = TopFieldCollector.create(sort, hitsPerPage, true, true, true, false); searcher.search(query, topField); TopDocs docs = topField.topDocs(); SimpleHTMLFormatter htmlFormatter = new SimpleHTMLFormatter("<font color=red>", "</font>"); Highlighter highlighter = new Highlighter(htmlFormatter, new QueryScorer(query)); indexsetList = new ArrayList<>(); for (int i = 0; i < docs.totalHits; i++) { String[] indexset = new String[5]; int id = docs.scoreDocs[i].doc; float score = docs.scoreDocs[i].score; Document doc = searcher.doc(id); String text = doc.get("student_assignment"); String st_am_id = doc.get("st_am_id"); String owner_safv_id = doc.get("safv_id"); // System.out.println(text); // System.out.println(st_am_id); // System.out.println(owner_safv_id); // System.out.println("-----------"); TokenStream tokenStream = TokenSources.getAnyTokenStream(searcher.getIndexReader(), id, "student_assignment", new ThaiAnalyzer(Version.LUCENE_47)); String[] hltextArr = highlighter.getBestFragments(tokenStream, text, hitsPerPage); String hltext = ""; for (String string : hltextArr) { hltext += string.toString() + "<br/>"; } indexset[0] = st_am_id; indexset[1] = hltext; //getting owner of StAmFileList file = StAmFileList.getSafvBySafv(Integer.parseInt(owner_safv_id)); if (file != null) { System.out.println((a.getAm_id() + " /" + file.getList_id())); StAssignmentFile stam = StAssignmentFile.getStAmBbyAmIDAndList(a.getAm_id(), file.getList_id()); String html = ""; //add ??? boolean add = true; if (stam.getG_id() == 0) { //if no group that mean it's a individual work if (sa.getAcc_id() != stam.getAcc_id()) { Account owneracc = Account.getNameByID(stam.getAcc_id()); html = "<img style=\"width:30px\" src=\"" + owneracc.getProfile_pic() + "\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"\" class=\"img-circle\" data-original-title=\"" + owneracc.getFirstname() + "\">"; } else { add = false; } } else { if (sa.getG_id() != stam.getG_id()) { List<Account> ownerlist = Account.getNameByGIDandAmID(stam.getG_id(), stam.getAm_id()); html = "<a class=\"showGroup\" data-toggle=\"popover\" data-html=\"true\" data-content=\"" + Util.createPopoverGroup(ownerlist) + "\">Group no. " + Group_member.getGNOById(stam.getG_id()) + "</a>"; } else { add = false; } } indexset[2] = html; indexset[3] = score + ""; indexset[4] = owner_safv_id; if (add) { indexsetList.add(indexset); } } } } catch (IOException ex) { Logger.getLogger(TestDriver.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(TestDriver.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidTokenOffsetsException ex) { Logger.getLogger(TestDriver.class.getName()).log(Level.SEVERE, null, ex); } // for (String[] strings : indexsetList) { // System.out.println(strings[0] + " : "+ strings[2] +" : " + strings[1] ); // } request.setAttribute("nowUUid", f.getUuid()); request.setAttribute("keyword", keyword); request.setAttribute("indexsetList", indexsetList); } else { request.setAttribute("error_msg", "This assignment cannot use for check copy."); } // System.out.println(keyword); getServletContext().getRequestDispatcher("/Checkcopy.jsp?tab=AllAssignment").forward(request, response); } }
From source file:stroom.search.server.SearchExpressionQueryBuilder.java
License:Apache License
public SearchExpressionQuery buildQuery(final Version matchVersion, final ExpressionOperator expression) { if (expression == null) { throw new SearchException("No search expression has been provided!"); }/*from w ww . j a v a2s.c om*/ if (!hasChildren(expression)) { throw new SearchException("No search terms have been specified!"); } BooleanQuery.setMaxClauseCount(maxBooleanClauseCount); // Build a query. final Set<String> terms = new HashSet<>(); final Query query = getQuery(matchVersion, expression, terms); return new SearchExpressionQuery(query, terms); }
From source file:uk.ac.ebi.arrayexpress.utils.saxon.search.Controller.java
License:Apache License
public Controller(URL configFile) { this.config = new Configuration(configFile); this.queryPool = new QueryPool(); BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); }
From source file:uk.ac.ebi.arrayexpress.utils.saxon.search.Controller.java
License:Apache License
public Controller(HierarchicalConfiguration config) { this.config = new Configuration(config); this.queryPool = new QueryPool(); BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.config.LuceneIAViewConfiguration.java
License:Mozilla Public License
@PostConstruct public void init() { BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); }
From source file:yasoco.TermScore.java
Query constructQuery(int docId) throws Exception { Query q = null;//from w w w . ja v a 2 s . co m boolean formSelectiveQueries = Boolean.parseBoolean(prop.getProperty("toptermquery", "true")); /* MoreLikeThis not woking for some reason! if (formSelectiveQueries) { q = mlt.like(docId); return q; } */ Document queryDoc = reader.document(docId); q = new BooleanQuery(); int termCount = 0; TokenStream fs = null; List<IndexableField> fields = queryDoc.getFields(); for (IndexableField field : fields) { String fieldName = field.name(); if (fieldName.equals(JavaSCTree.FIELD_DOCNAME) || fieldName.equals(JavaSCTree.FIELD_SC)) continue; // ignore non-searchable fields if (formSelectiveQueries) { List<TermScore> topList = selTerms(docId, field.name(), q); for (TermScore ts : topList) { Term thisTerm = new Term(field.name(), ts.term); ((BooleanQuery) q).add(new TermQuery(thisTerm), BooleanClause.Occur.SHOULD); } } else { fs = queryDoc.getField(fieldName).tokenStream(analyzer); CharTermAttribute termAtt = fs.addAttribute(CharTermAttribute.class); fs.reset(); // print all tokens until stream is exhausted while (fs.incrementToken()) { Term thisTerm = new Term(field.name(), termAtt.toString()); termCount++; if (termCount == maxlimit) { maxlimit = maxlimit << 1; BooleanQuery.setMaxClauseCount(maxlimit); } ((BooleanQuery) q).add(new TermQuery(thisTerm), BooleanClause.Occur.SHOULD); } fs.end(); fs.close(); } } return q; }
From source file:ystorefoundationpackage.domain.util.list.LuceneSearchBufferedList.java
License:Open Source License
@Override protected List<V> fetchSubset(final int absoluteIndex, final int numberOfElements) { final LuceneIndex idx = this.getLuceneIndexInternal(); final SessionContext ctx = JaloSession.getCurrentSession().getSessionContext(); BooleanQuery.setMaxClauseCount(4096); LuceneSearchResult.setMaxHitsThreshold(numberOfElements); // SearchResult result = new StandardSearchResult( Collections.EMPTY_LIST, 0, 0, 0 ); LuceneSearchResult result = null;//from www .j a v a2s. co m try { result = idx.searchItems(ctx, term, null, orderBy, isAscending, absoluteIndex, numberOfElements); //this.maxHitsExceeded = ((LuceneSearchResult)result).isMaxHitsExceeded(); //this.setMaxHits(((LuceneSearchResult)result).getTotalCount()); } catch (final de.hybris.platform.lucenesearch.jalo.ParseException e) { log.error("LuceneSearchControl: " + e.getMessage()); // Commented out: exception is way too much low level to be thrown to screen // throw new de.hybris.jakarta.ext.lucenesearch.jalo.ParseException( e ); } catch (final Exception e) { log.error("LuceneSearchControl: " + e.getMessage() + " \n" + Utilities.getStackTraceAsString(e)); } this.score = new FakeSizeList<Float>(result.getScores(), super.size(), Float.valueOf(0)); return result.getResult(); }