@Test public void intoTermsTest() { Term t = new Term("test", "test"); Query q = new TermQuery(t); List<Term> terms = SuggesterUtils.intoTerms(q); assertEquals(1, terms.size()); assertEquals(t, terms.get(0)); }
public static List<Term> intoTerms(final Query query) { if (query == null) { return Collections.emptyList(); } List<Term> terms = new LinkedList<>(); LinkedList<Query> queue = new LinkedList<>(); queue.add(query); while (!queue.isEmpty()) { Query q = queue.poll(); if (q instanceof BooleanQuery) { for (BooleanClause bc : ((BooleanQuery) q).clauses()) { queue.add(bc.getQuery()); } } else if (q instanceof TermQuery) { terms.add(((TermQuery) q).getTerm()); } else if (q instanceof PhraseQuery) { terms.addAll(Arrays.asList(((PhraseQuery) q).getTerms())); } } return terms; }
SuggesterUtils { public static List<Term> intoTerms(final Query query) { if (query == null) { return Collections.emptyList(); } List<Term> terms = new LinkedList<>(); LinkedList<Query> queue = new LinkedList<>(); queue.add(query); while (!queue.isEmpty()) { Query q = queue.poll(); if (q instanceof BooleanQuery) { for (BooleanClause bc : ((BooleanQuery) q).clauses()) { queue.add(bc.getQuery()); } } else if (q instanceof TermQuery) { terms.add(((TermQuery) q).getTerm()); } else if (q instanceof PhraseQuery) { terms.addAll(Arrays.asList(((PhraseQuery) q).getTerms())); } } return terms; } }
SuggesterUtils { public static List<Term> intoTerms(final Query query) { if (query == null) { return Collections.emptyList(); } List<Term> terms = new LinkedList<>(); LinkedList<Query> queue = new LinkedList<>(); queue.add(query); while (!queue.isEmpty()) { Query q = queue.poll(); if (q instanceof BooleanQuery) { for (BooleanClause bc : ((BooleanQuery) q).clauses()) { queue.add(bc.getQuery()); } } else if (q instanceof TermQuery) { terms.add(((TermQuery) q).getTerm()); } else if (q instanceof PhraseQuery) { terms.addAll(Arrays.asList(((PhraseQuery) q).getTerms())); } } return terms; } private  SuggesterUtils(); }
SuggesterUtils { public static List<Term> intoTerms(final Query query) { if (query == null) { return Collections.emptyList(); } List<Term> terms = new LinkedList<>(); LinkedList<Query> queue = new LinkedList<>(); queue.add(query); while (!queue.isEmpty()) { Query q = queue.poll(); if (q instanceof BooleanQuery) { for (BooleanClause bc : ((BooleanQuery) q).clauses()) { queue.add(bc.getQuery()); } } else if (q instanceof TermQuery) { terms.add(((TermQuery) q).getTerm()); } else if (q instanceof PhraseQuery) { terms.addAll(Arrays.asList(((PhraseQuery) q).getTerms())); } } return terms; } private  SuggesterUtils(); static List<Term> intoTerms(final Query query); static List<Term> intoTermsExceptPhraseQuery(final Query query); static boolean isComplexQuery(final Query query, final SuggesterQuery suggesterQuery); }
SuggesterUtils { public static List<Term> intoTerms(final Query query) { if (query == null) { return Collections.emptyList(); } List<Term> terms = new LinkedList<>(); LinkedList<Query> queue = new LinkedList<>(); queue.add(query); while (!queue.isEmpty()) { Query q = queue.poll(); if (q instanceof BooleanQuery) { for (BooleanClause bc : ((BooleanQuery) q).clauses()) { queue.add(bc.getQuery()); } } else if (q instanceof TermQuery) { terms.add(((TermQuery) q).getTerm()); } else if (q instanceof PhraseQuery) { terms.addAll(Arrays.asList(((PhraseQuery) q).getTerms())); } } return terms; } private  SuggesterUtils(); static List<Term> intoTerms(final Query query); static List<Term> intoTermsExceptPhraseQuery(final Query query); static boolean isComplexQuery(final Query query, final SuggesterQuery suggesterQuery); static final int NORMALIZED_DOCUMENT_FREQUENCY_MULTIPLIER; }