@Test public void testSolrQueryPerser() { String q="envisat"; List <String[]>elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 1, "No element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], q, "Query not properly parsed."); q="*"; elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 1, "No element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], "*", "Query not properly parsed"); q="12-TRE_1_RER.AZS"; elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 1, "No element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], "12-TRE_1_RER.AZS", "Query not properly parsed"); q="platformName:envisat"; elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 1, "No element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], "envisat", "Query not properly parsed"); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_FIELD], "platformName", "Query not properly parsed"); q="*:*"; elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 1, "No element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], "*", "Query not properly parsed"); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_FIELD], "*", "Query not properly parsed"); q="a:12-TRE_1_RER.AZS"; elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 1, "No element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], "12-TRE_1_RER.AZS", "Query not properly parsed"); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_FIELD], "a", "Query not properly parsed"); q="cloudCoverage:[0 TO 100]"; elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 1, "No element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], "[0 TO 100]", "Query not properly parsed"); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_FIELD], "cloudCoverage", "Query not properly parsed"); q="ca:A AND cb:B"; elements = SolrQueryParser.parse(q); Assert.assertEquals(elements.size(), 3, "Not enough element parsed in query \"" + q + "\"."); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_VALUE], "A", "Query not properly parsed"); Assert.assertEquals (elements.get(0)[SolrQueryParser.INDEX_FIELD], "ca", "Query not properly parsed"); Assert.assertEquals (elements.get(1)[SolrQueryParser.INDEX_VALUE], "AND", "Query not properly parsed"); Assert.assertEquals (elements.get(2)[SolrQueryParser.INDEX_VALUE], "B", "Query not properly parsed"); Assert.assertEquals (elements.get(2)[SolrQueryParser.INDEX_FIELD], "cb", "Query not properly parsed"); }
public static List<String[]>parse (String query) { LOGGER.debug("Matching query : \"" + query + "\""); List<String[]>list = new ArrayList<String[]>(); Matcher matcher = PATTERN.matcher(query.trim()); while (matcher.find()) { String[] strs = new String[5]; strs[INDEX_ALL] = neverNull(matcher.group(0)).trim(); strs[INDEX_FOOTER] = neverNull(matcher.group(1)).trim(); strs[INDEX_FIELD] = neverNull(matcher.group(2)).trim(); strs[INDEX_VALUE] = neverNull(matcher.group(3)).trim(); strs[INDEX_TRAILER] = neverNull(matcher.group(4)).trim(); list.add(strs); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" \"" + strs[INDEX_ALL] + "\" is descabled as"); LOGGER.debug(" Footer \"" + strs[INDEX_FOOTER]+ "\""); LOGGER.debug(" Field \"" + strs[INDEX_FIELD]+ "\""); LOGGER.debug(" Value \"" + strs[INDEX_VALUE]+ "\""); LOGGER.debug(" Trailer \"" + strs[INDEX_TRAILER]+ "\""); } } return list; }
SolrQueryParser { public static List<String[]>parse (String query) { LOGGER.debug("Matching query : \"" + query + "\""); List<String[]>list = new ArrayList<String[]>(); Matcher matcher = PATTERN.matcher(query.trim()); while (matcher.find()) { String[] strs = new String[5]; strs[INDEX_ALL] = neverNull(matcher.group(0)).trim(); strs[INDEX_FOOTER] = neverNull(matcher.group(1)).trim(); strs[INDEX_FIELD] = neverNull(matcher.group(2)).trim(); strs[INDEX_VALUE] = neverNull(matcher.group(3)).trim(); strs[INDEX_TRAILER] = neverNull(matcher.group(4)).trim(); list.add(strs); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" \"" + strs[INDEX_ALL] + "\" is descabled as"); LOGGER.debug(" Footer \"" + strs[INDEX_FOOTER]+ "\""); LOGGER.debug(" Field \"" + strs[INDEX_FIELD]+ "\""); LOGGER.debug(" Value \"" + strs[INDEX_VALUE]+ "\""); LOGGER.debug(" Trailer \"" + strs[INDEX_TRAILER]+ "\""); } } return list; } }
SolrQueryParser { public static List<String[]>parse (String query) { LOGGER.debug("Matching query : \"" + query + "\""); List<String[]>list = new ArrayList<String[]>(); Matcher matcher = PATTERN.matcher(query.trim()); while (matcher.find()) { String[] strs = new String[5]; strs[INDEX_ALL] = neverNull(matcher.group(0)).trim(); strs[INDEX_FOOTER] = neverNull(matcher.group(1)).trim(); strs[INDEX_FIELD] = neverNull(matcher.group(2)).trim(); strs[INDEX_VALUE] = neverNull(matcher.group(3)).trim(); strs[INDEX_TRAILER] = neverNull(matcher.group(4)).trim(); list.add(strs); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" \"" + strs[INDEX_ALL] + "\" is descabled as"); LOGGER.debug(" Footer \"" + strs[INDEX_FOOTER]+ "\""); LOGGER.debug(" Field \"" + strs[INDEX_FIELD]+ "\""); LOGGER.debug(" Value \"" + strs[INDEX_VALUE]+ "\""); LOGGER.debug(" Trailer \"" + strs[INDEX_TRAILER]+ "\""); } } return list; } private  SolrQueryParser(); }
SolrQueryParser { public static List<String[]>parse (String query) { LOGGER.debug("Matching query : \"" + query + "\""); List<String[]>list = new ArrayList<String[]>(); Matcher matcher = PATTERN.matcher(query.trim()); while (matcher.find()) { String[] strs = new String[5]; strs[INDEX_ALL] = neverNull(matcher.group(0)).trim(); strs[INDEX_FOOTER] = neverNull(matcher.group(1)).trim(); strs[INDEX_FIELD] = neverNull(matcher.group(2)).trim(); strs[INDEX_VALUE] = neverNull(matcher.group(3)).trim(); strs[INDEX_TRAILER] = neverNull(matcher.group(4)).trim(); list.add(strs); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" \"" + strs[INDEX_ALL] + "\" is descabled as"); LOGGER.debug(" Footer \"" + strs[INDEX_FOOTER]+ "\""); LOGGER.debug(" Field \"" + strs[INDEX_FIELD]+ "\""); LOGGER.debug(" Value \"" + strs[INDEX_VALUE]+ "\""); LOGGER.debug(" Trailer \"" + strs[INDEX_TRAILER]+ "\""); } } return list; } private  SolrQueryParser(); static List<String[]> parse(String query); }
SolrQueryParser { public static List<String[]>parse (String query) { LOGGER.debug("Matching query : \"" + query + "\""); List<String[]>list = new ArrayList<String[]>(); Matcher matcher = PATTERN.matcher(query.trim()); while (matcher.find()) { String[] strs = new String[5]; strs[INDEX_ALL] = neverNull(matcher.group(0)).trim(); strs[INDEX_FOOTER] = neverNull(matcher.group(1)).trim(); strs[INDEX_FIELD] = neverNull(matcher.group(2)).trim(); strs[INDEX_VALUE] = neverNull(matcher.group(3)).trim(); strs[INDEX_TRAILER] = neverNull(matcher.group(4)).trim(); list.add(strs); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" \"" + strs[INDEX_ALL] + "\" is descabled as"); LOGGER.debug(" Footer \"" + strs[INDEX_FOOTER]+ "\""); LOGGER.debug(" Field \"" + strs[INDEX_FIELD]+ "\""); LOGGER.debug(" Value \"" + strs[INDEX_VALUE]+ "\""); LOGGER.debug(" Trailer \"" + strs[INDEX_TRAILER]+ "\""); } } return list; } private  SolrQueryParser(); static List<String[]> parse(String query); static final int INDEX_ALL; static final int INDEX_FOOTER; static final int INDEX_FIELD; static final int INDEX_VALUE; static final int INDEX_TRAILER; }