@Test public void intoTermExceptPhraseQueryTest() { Term t = new Term("test", "term"); BooleanQuery q = new BooleanQuery.Builder() .add(new TermQuery(t), BooleanClause.Occur.MUST) .add(new PhraseQuery("test", "term1", "term2"), BooleanClause.Occur.MUST) .build(); List<Term> terms = SuggesterUtils.intoTermsExceptPhraseQuery(q); assertEquals(1, terms.size()); assertEquals(t, terms.get(0)); }
public static List<Term> intoTermsExceptPhraseQuery(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()); } } return terms; }
SuggesterUtils { public static List<Term> intoTermsExceptPhraseQuery(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()); } } return terms; } }
SuggesterUtils { public static List<Term> intoTermsExceptPhraseQuery(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()); } } return terms; } private  SuggesterUtils(); }
SuggesterUtils { public static List<Term> intoTermsExceptPhraseQuery(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()); } } 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> intoTermsExceptPhraseQuery(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()); } } 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; }