List of usage examples for org.apache.lucene.search Sort Sort
public Sort(SortField... fields)
From source file:com.isotrol.impe3.nr.core.LuceneTranslator.java
License:Open Source License
/** * Translate a node sort to lucene sort//w ww . ja va 2 s.c o m * @param lsort original sort * @return lucene sort */ public Sort sort(final NodeSort lsort) { if (lsort == null) { return null; } NRSortField[] lfields = lsort.getFields(); SortField[] fields = new SortField[lfields.length]; for (int i = 0; i < lfields.length; i++) { final SortField field = new SortField(lfields[i].getField(), lfields[i].getType(), lfields[i].isReverse()); fields[i] = field; } Sort sort = new Sort(fields); return sort; }
From source file:com.isotrol.impe3.nr.core.LucisQuerySupportTest.java
License:Open Source License
@Test public void lucisSortTest() { Sort sort = new Sort(new SortField[] { new SortField("UNO", SortField.STRING, false), new SortField("DOS", SortField.STRING, true) }); NodeSort lsort = createLucisSort();/* w w w. j av a2s . c o m*/ Sort test = translator().sort(lsort); Assert.assertNotNull(test); // Assert.assertEquals(sort, test); Assert.assertTrue(test instanceof Sort); Assert.assertEquals(sort.toString(), test.toString()); }
From source file:com.isotrol.impe3.oi.dao.impl.IndexDAOImpl.java
License:Open Source License
private Sort orderings(List<OrderDTO> orders) { if (orders == null || orders.isEmpty()) { return null; }/*from w ww . j a va 2 s.co m*/ SortField[] fields = new SortField[orders.size()]; for (int i = 0; i < orders.size(); i++) { final OrderDTO order = orders.get(i); final SortField field = new SortField(order.getName(), SortField.STRING, order.getAscending()); fields[i] = field; } return new Sort(fields); }
From source file:com.isotrol.impe3.oi.nr.QueryTranslator.java
License:Open Source License
/** * Translate a node sort to lucene sort/*from ww w .j a v a 2 s. c o m*/ * @param lsort original sort * @return lucene sort */ public Sort sort(final NodeSort lsort) { if (lsort == null) { return null; } NRSortField[] lfields = lsort.getFields(); SortField[] fields = new SortField[lfields.length]; for (int i = 0; i < lfields.length; i++) { final SortField field = new SortField(lfields[i].getField(), SortField.STRING, lfields[i].isReverse()); fields[i] = field; } return new Sort(fields); }
From source file:com.khepry.frackhem.entities.Blendeds.java
License:Apache License
public QueryResult facetViaLucene(String queryField, String queryValue, Integer maxDocs, String sortOrder, Boolean allowLeadingWildcard) throws IOException, ParseException { QueryResult queryResult = new QueryResult(); list.clear();/*from w ww . j a va2s. c om*/ documents.clear(); String message; String[] sortColumns = sortOrder.split(","); if (!initialized) { queryResult = initialize(indexFolderPath, taxonomyFolderPath); } if (!queryResult.isNotValid() && !queryValue.equals("")) { QueryParser parser = new QueryParser(Version.LUCENE_44, queryField, analyzer); parser.setAllowLeadingWildcard(allowLeadingWildcard); Query query = parser.parse(queryValue); SortField[] sortFields = new SortField[sortColumns.length]; String[] pieces; for (int i = 0; i < sortColumns.length; i++) { pieces = sortColumns[i].split(":"); if (pieces.length > 1) { switch (pieces[1].toLowerCase()) { case "integer": sortFields[i] = new SortField(sortColumns[i], SortField.Type.INT); break; default: sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); break; } } else { sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); } } Sort sort = new Sort(sortFields); queryResult.setTopFieldCollector(TopFieldCollector.create(sort, maxDocs, true, false, false, false)); List<FacetRequest> facetRequests = new ArrayList<>(); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "Toxicity"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "Toxicity"), 200)); FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests); queryResult.setFacetsCollector(FacetsCollector.create(facetSearchParams, indexReader, taxonomyReader)); indexSearcher.search(query, MultiCollector.wrap(queryResult.getTopFieldCollector(), queryResult.getFacetsCollector())); // for (ScoreDoc scoreDoc : queryResult.getTopFieldCollector().topDocs().scoreDocs) { // Document document = indexSearcher.doc(scoreDoc.doc); // documents.add(document); // Blended blended = new Blended(document); // list.add((E)blended); // if (outputDebugInfo) { // for (IndexableField field : document.getFields()) { // System.out.print(field.stringValue()); // System.out.print("\t"); // } // System.out.println(); // } // } // queryResult.setDocuments(documents); if (outputDebugInfo) { for (FacetResult facetResult : queryResult.getFacetsCollector().getFacetResults()) { for (FacetResultNode node0 : facetResult.getFacetResultNode().subResults) { if (node0.label.toString().indexOf("/Toxicity/") > -1) { if (node0.label.toString().indexOf(",") == -1) { System.out.println(node0.label + ": " + node0.value); } } else { System.out.println(node0.label + ": " + node0.value); } // for (FacetResultNode node1 : node0.subResults) { // System.out.println(node1.label + ": " + node1.value); // } } } } } return queryResult; }
From source file:com.khepry.frackhem.entities.Blendeds.java
License:Apache License
public QueryResult queryViaLucene(String queryField, String queryValue, Integer maxDocs, String sortOrder, Boolean allowLeadingWildcard) throws IOException, ParseException { QueryResult queryResult = new QueryResult(); list.clear();//from w w w . j ava2 s. c om documents.clear(); String message; String[] sortColumns = sortOrder.split(","); if (!initialized) { queryResult = initialize(indexFolderPath, taxonomyFolderPath); } if (!queryResult.isNotValid() && !queryValue.equals("")) { QueryParser parser = new QueryParser(Version.LUCENE_44, queryField, analyzer); parser.setAllowLeadingWildcard(allowLeadingWildcard); Query query = parser.parse(queryValue); SortField[] sortFields = new SortField[sortColumns.length]; String[] pieces; for (int i = 0; i < sortColumns.length; i++) { pieces = sortColumns[i].split(":"); if (pieces.length > 1) { switch (pieces[1].toLowerCase()) { case "integer": sortFields[i] = new SortField(sortColumns[i], SortField.Type.INT); break; default: sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); break; } } else { sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); } } Sort sort = new Sort(sortFields); queryResult.setTopFieldCollector(TopFieldCollector.create(sort, maxDocs, true, false, false, false)); List<FacetRequest> facetRequests = new ArrayList<>(); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "Toxicity"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "Toxicity"), 200)); FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests); queryResult.setFacetsCollector(FacetsCollector.create(facetSearchParams, indexReader, taxonomyReader)); indexSearcher.search(query, MultiCollector.wrap(queryResult.getTopFieldCollector(), queryResult.getFacetsCollector())); for (ScoreDoc scoreDoc : queryResult.getTopFieldCollector().topDocs().scoreDocs) { Document document = indexSearcher.doc(scoreDoc.doc); documents.add(document); Blended blended = new Blended(document); list.add((E) blended); if (outputDebugInfo) { for (IndexableField field : document.getFields()) { System.out.print(field.stringValue()); System.out.print("\t"); } System.out.println(); } } queryResult.setDocuments(documents); if (outputDebugInfo) { for (FacetResult facetResult : queryResult.getFacetsCollector().getFacetResults()) { for (FacetResultNode node0 : facetResult.getFacetResultNode().subResults) { if (node0.label.toString().indexOf("/Toxicity/") > -1) { if (node0.label.toString().indexOf(",") == -1) { System.out.println(node0.label + ": " + node0.value); } } else { System.out.println(node0.label + ": " + node0.value); } // for (FacetResultNode node1 : node0.subResults) { // System.out.println(node1.label + ": " + node1.value); // } } } } } return queryResult; }
From source file:com.khepry.frackhem.entities.Chemicals.java
License:Apache License
public QueryResult facetViaLucene(String queryField, String queryValue, Integer maxDocs, String sortOrder, Boolean allowLeadingWildcard) throws IOException, ParseException { QueryResult queryResult = new QueryResult(); list.clear();/* w w w.j ava 2 s .c o m*/ documents.clear(); String message; String[] sortColumns = sortOrder.split(","); if (!initialized) { queryResult = initialize(indexFolderPath, taxonomyFolderPath); } if (!queryResult.isNotValid() && !queryValue.equals("")) { QueryParser parser = new QueryParser(Version.LUCENE_44, queryField, analyzer); parser.setAllowLeadingWildcard(allowLeadingWildcard); Query query = parser.parse(queryValue); SortField[] sortFields = new SortField[sortColumns.length]; String[] pieces; for (int i = 0; i < sortColumns.length; i++) { pieces = sortColumns[i].split(":"); if (pieces.length > 1) { switch (pieces[1].toLowerCase()) { case "integer": sortFields[i] = new SortField(sortColumns[i], SortField.Type.INT); break; default: sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); break; } } else { sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); } } Sort sort = new Sort(sortFields); queryResult.setTopFieldCollector(TopFieldCollector.create(sort, maxDocs, true, false, false, false)); List<FacetRequest> facetRequests = new ArrayList<>(); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "Toxicity"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "Toxicity"), 200)); FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests); queryResult.setFacetsCollector(FacetsCollector.create(facetSearchParams, indexReader, taxonomyReader)); indexSearcher.search(query, MultiCollector.wrap(queryResult.getTopFieldCollector(), queryResult.getFacetsCollector())); // List<Document> documents = new ArrayList<>(); // for (ScoreDoc scoreDoc : queryResult.getTopFieldCollector().topDocs().scoreDocs) { // Document document = indexSearcher.doc(scoreDoc.doc); // documents.add(document); // Chemical chemical = new Chemical(document); // list.add((E)chemical); // if (outputDebugInfo) { // for (IndexableField field : document.getFields()) { // System.out.print(field.stringValue()); // System.out.print("\t"); // } // System.out.println(); // } // } // queryResult.setDocuments(documents); if (outputDebugInfo) { for (FacetResult facetResult : queryResult.getFacetsCollector().getFacetResults()) { for (FacetResultNode node0 : facetResult.getFacetResultNode().subResults) { if (node0.label.toString().indexOf("/Toxicity/") > -1) { if (node0.label.toString().indexOf(",") == -1) { System.out.println(node0.label + ": " + node0.value); } } else { System.out.println(node0.label + ": " + node0.value); } // for (FacetResultNode node1 : node0.subResults) { // System.out.println(node1.label + ": " + node1.value); // } } } } } return queryResult; }
From source file:com.khepry.frackhem.entities.Chemicals.java
License:Apache License
public QueryResult queryViaLucene(String queryField, String queryValue, Integer maxDocs, String sortOrder, Boolean allowLeadingWildcard) throws IOException, ParseException { QueryResult queryResult = new QueryResult(); list.clear();/*ww w. j a v a 2 s .co m*/ documents.clear(); String message; String[] sortColumns = sortOrder.split(","); if (!initialized) { queryResult = initialize(indexFolderPath, taxonomyFolderPath); } if (!queryResult.isNotValid() && !queryValue.equals("")) { QueryParser parser = new QueryParser(Version.LUCENE_44, queryField, analyzer); parser.setAllowLeadingWildcard(allowLeadingWildcard); Query query = parser.parse(queryValue); SortField[] sortFields = new SortField[sortColumns.length]; String[] pieces; for (int i = 0; i < sortColumns.length; i++) { pieces = sortColumns[i].split(":"); if (pieces.length > 1) { switch (pieces[1].toLowerCase()) { case "integer": sortFields[i] = new SortField(sortColumns[i], SortField.Type.INT); break; default: sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); break; } } else { sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); } } Sort sort = new Sort(sortFields); queryResult.setTopFieldCollector(TopFieldCollector.create(sort, maxDocs, true, false, false, false)); List<FacetRequest> facetRequests = new ArrayList<>(); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "Toxicity"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "CasEdfId"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "Toxicity"), 200)); FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests); queryResult.setFacetsCollector(FacetsCollector.create(facetSearchParams, indexReader, taxonomyReader)); indexSearcher.search(query, MultiCollector.wrap(queryResult.getTopFieldCollector(), queryResult.getFacetsCollector())); List<Document> documents = new ArrayList<>(); for (ScoreDoc scoreDoc : queryResult.getTopFieldCollector().topDocs().scoreDocs) { Document document = indexSearcher.doc(scoreDoc.doc); documents.add(document); Chemical chemical = new Chemical(document); list.add((E) chemical); if (outputDebugInfo) { for (IndexableField field : document.getFields()) { System.out.print(field.stringValue()); System.out.print("\t"); } System.out.println(); } } queryResult.setDocuments(documents); if (outputDebugInfo) { for (FacetResult facetResult : queryResult.getFacetsCollector().getFacetResults()) { for (FacetResultNode node0 : facetResult.getFacetResultNode().subResults) { if (node0.label.toString().indexOf("/Toxicity/") > -1) { if (node0.label.toString().indexOf(",") == -1) { System.out.println(node0.label + ": " + node0.value); } } else { System.out.println(node0.label + ": " + node0.value); } // for (FacetResultNode node1 : node0.subResults) { // System.out.println(node1.label + ": " + node1.value); // } } } } } return queryResult; }
From source file:com.khepry.frackhem.entities.Reports.java
License:Apache License
public QueryResult facetViaLucene(String queryField, String queryValue, Integer maxDocs, String sortOrder, Boolean allowLeadingWildcard) throws IOException, ParseException { QueryResult queryResult = new QueryResult(); list.clear();//from w w w . j a va 2 s . co m documents.clear(); String message; String[] sortColumns = sortOrder.split(","); if (!initialized) { queryResult = initialize(indexFolderPath, taxonomyFolderPath); } if (!queryResult.isNotValid() && !queryValue.equals("")) { QueryParser parser = new QueryParser(Version.LUCENE_44, queryField, analyzer); parser.setAllowLeadingWildcard(allowLeadingWildcard); Query query = parser.parse(queryValue); SortField[] sortFields = new SortField[sortColumns.length]; String[] pieces; for (int i = 0; i < sortColumns.length; i++) { pieces = sortColumns[i].split(":"); if (pieces.length > 1) { switch (pieces[1].toLowerCase()) { case "integer": sortFields[i] = new SortField(sortColumns[i], SortField.Type.INT); break; default: sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); break; } } else { sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); } } Sort sort = new Sort(sortFields); queryResult.setTopFieldCollector(TopFieldCollector.create(sort, maxDocs, true, false, false, false)); List<FacetRequest> facetRequests = new ArrayList<>(); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "Toxicity"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "Toxicity"), 200)); FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests); queryResult.setFacetsCollector(FacetsCollector.create(facetSearchParams, indexReader, taxonomyReader)); indexSearcher.search(query, MultiCollector.wrap(queryResult.getTopFieldCollector(), queryResult.getFacetsCollector())); // // List<Document> documents = new ArrayList<>(); // for (ScoreDoc scoreDoc : queryResult.getTopFieldCollector().topDocs().scoreDocs) { // Document document = indexSearcher.doc(scoreDoc.doc); // documents.add(document); // Report report = new Report(document); // list.add((E)report); // if (outputDebugInfo) { // for (IndexableField field : document.getFields()) { // System.out.print(field.stringValue()); // System.out.print("\t"); // } // System.out.println(); // } // } // queryResult.setDocuments(documents); if (outputDebugInfo) { for (FacetResult facetResult : queryResult.getFacetsCollector().getFacetResults()) { for (FacetResultNode node0 : facetResult.getFacetResultNode().subResults) { if (node0.label.toString().indexOf(",") == -1) { System.out.println(node0.label + ": " + node0.value); } // for (FacetResultNode node1 : node0.subResults) { // System.out.println(node1.label + ": " + node1.value); // } } } } } return queryResult; }
From source file:com.khepry.frackhem.entities.Reports.java
License:Apache License
public QueryResult queryViaLucene(String queryField, String queryValue, Integer maxDocs, String sortOrder, Boolean allowLeadingWildcard) throws IOException, ParseException { QueryResult queryResult = new QueryResult(); list.clear();/*from ww w. j a v a 2 s. c om*/ documents.clear(); String message; String[] sortColumns = sortOrder.split(","); if (!initialized) { queryResult = initialize(indexFolderPath, taxonomyFolderPath); } if (!queryResult.isNotValid() && !queryValue.equals("")) { QueryParser parser = new QueryParser(Version.LUCENE_44, queryField, analyzer); parser.setAllowLeadingWildcard(allowLeadingWildcard); Query query = parser.parse(queryValue); SortField[] sortFields = new SortField[sortColumns.length]; String[] pieces; for (int i = 0; i < sortColumns.length; i++) { pieces = sortColumns[i].split(":"); if (pieces.length > 1) { switch (pieces[1].toLowerCase()) { case "integer": sortFields[i] = new SortField(sortColumns[i], SortField.Type.INT); break; default: sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); break; } } else { sortFields[i] = new SortField(sortColumns[i], SortField.Type.STRING); } } Sort sort = new Sort(sortFields); queryResult.setTopFieldCollector(TopFieldCollector.create(sort, maxDocs, true, false, false, false)); List<FacetRequest> facetRequests = new ArrayList<>(); facetRequests.add(new CountFacetRequest(new CategoryPath("toxRecognized", "Toxicity"), 200)); facetRequests.add(new CountFacetRequest(new CategoryPath("toxSuspected", "Toxicity"), 200)); FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests); queryResult.setFacetsCollector(FacetsCollector.create(facetSearchParams, indexReader, taxonomyReader)); indexSearcher.search(query, MultiCollector.wrap(queryResult.getTopFieldCollector(), queryResult.getFacetsCollector())); List<Document> documents = new ArrayList<>(); for (ScoreDoc scoreDoc : queryResult.getTopFieldCollector().topDocs().scoreDocs) { Document document = indexSearcher.doc(scoreDoc.doc); documents.add(document); Report report = new Report(document); list.add((E) report); if (outputDebugInfo) { for (IndexableField field : document.getFields()) { System.out.print(field.stringValue()); System.out.print("\t"); } System.out.println(); } } queryResult.setDocuments(documents); if (outputDebugInfo) { for (FacetResult facetResult : queryResult.getFacetsCollector().getFacetResults()) { for (FacetResultNode node0 : facetResult.getFacetResultNode().subResults) { if (node0.label.toString().indexOf(",") == -1) { System.out.println(node0.label + ": " + node0.value); } // for (FacetResultNode node1 : node0.subResults) { // System.out.println(node1.label + ": " + node1.value); // } } } } } return queryResult; }