當前位置: 首頁>>代碼示例>>Java>>正文


Java Occur.SHOULD屬性代碼示例

本文整理匯總了Java中org.apache.lucene.search.BooleanClause.Occur.SHOULD屬性的典型用法代碼示例。如果您正苦於以下問題:Java Occur.SHOULD屬性的具體用法?Java Occur.SHOULD怎麽用?Java Occur.SHOULD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.lucene.search.BooleanClause.Occur的用法示例。


在下文中一共展示了Occur.SHOULD屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: _queryClauseJoinFor

private static Occur _queryClauseJoinFor(final QueryClauseOccur occur) {
	Occur outOccur = null;
	switch(occur) {
	case MUST:
		outOccur = Occur.MUST;
		break;
	case MUST_NOT:
		outOccur = Occur.MUST_NOT;
		break;
	case SHOULD:
		outOccur = Occur.SHOULD;
		break;
	default:
		throw new IllegalArgumentException();
	}
	return outOccur;
}
 
開發者ID:opendata-euskadi,項目名稱:r01fb,代碼行數:17,代碼來源:LuceneSearchQuery.java

示例2: fromParamMap

public static WebDSLFacet fromParamMap(Map<String,String> paramMap){
    WebDSLFacet f = new WebDSLFacet();
    try{
        String key, value;
        for (Map.Entry<String, String> e : paramMap.entrySet()) {
            key = e.getKey();
            value = e.getValue();
            if ("fn".equals(key)) {
                f.fieldName = value;
            } else if ("v".equals(key)) {
                f.value = value;
            } else if ("cnt".equals(key)) {
                f.count = Integer.parseInt(value);
            } else if ("occ".equals(key)){
                f.occur = Occur.valueOf(value);
            } else if ("sel".equals(key)){
                f.isSelected = Boolean.parseBoolean(value);
            }
        }
    } catch (Exception ex){
        return new WebDSLFacet("Illegal facet", "Illegal facet", Occur.SHOULD, 0);
    }
    return f;
}
 
開發者ID:webdsl,項目名稱:webdsl,代碼行數:24,代碼來源:WebDSLFacet.java

示例3: createUsagesQuery

static Query createUsagesQuery(
        final @NonNull String resourceName,
        final @NonNull Set<? extends ClassIndexImpl.UsageType> mask,
        final @NonNull Occur operator) {
    Parameters.notNull("resourceName", resourceName);
    Parameters.notNull("mask", mask);
    Parameters.notNull("operator", operator);
    if (operator == Occur.SHOULD) {
        final BooleanQuery query = new BooleanQuery ();
        for (ClassIndexImpl.UsageType ut : mask) {
            final Query subQuery = new WildcardQuery(
                DocumentUtil.referencesTerm (
                    resourceName,
                    EnumSet.of(ut),
                    false));
            query.add(subQuery, operator);
        }
        return query;
    } else if (operator == Occur.MUST) {
        return new WildcardQuery(
            DocumentUtil.referencesTerm (
                resourceName,
                mask,
                false));
    } else {
        throw new IllegalArgumentException();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:QueryUtil.java

示例4: convertDate

/**
 * Converts a FreeTextDateQuery to a BooleanClause
 */
private BooleanClause convertDate(FreeTextDateQuery query)
{
	TermRangeQuery termQuery = new TermRangeQuery(query.getField(), convertDate(query.getStart(), query),
		convertDate(query.getEnd(), query), query.isIncludeStart(), query.isIncludeEnd());
	termQuery.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
	return new BooleanClause(termQuery, Occur.SHOULD);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:10,代碼來源:ItemIndex.java

示例5: testHighlightingCommonTermsQuery

public void testHighlightingCommonTermsQuery() throws Exception {
  Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
  CommonTermsQuery query = new CommonTermsQuery(Occur.MUST, Occur.SHOULD, 3);
  query.add(new Term(FIELD_NAME, "this"));
  query.add(new Term(FIELD_NAME, "long"));
  query.add(new Term(FIELD_NAME, "very"));

  searcher = newSearcher(reader);
  TopDocs hits = searcher.search(query, 10);
  assertEquals(2, hits.totalHits);
  QueryScorer scorer = new QueryScorer(query, FIELD_NAME);
  Highlighter highlighter = new Highlighter(scorer);

  Document doc = searcher.doc(hits.scoreDocs[0].doc);
  String storedField = doc.get(FIELD_NAME);

  TokenStream stream = TokenSources.getAnyTokenStream(searcher
      .getIndexReader(), hits.scoreDocs[0].doc, FIELD_NAME, doc, analyzer);
  Fragmenter fragmenter = new SimpleSpanFragmenter(scorer);
  highlighter.setTextFragmenter(fragmenter);
  String fragment = highlighter.getBestFragment(stream, storedField);
  assertEquals("Hello <B>this</B> is a piece of text that is <B>very</B> <B>long</B> and contains too much preamble and the meat is really here which says kennedy has been shot", fragment);
  
  doc = searcher.doc(hits.scoreDocs[1].doc);
  storedField = doc.get(FIELD_NAME);

  stream = TokenSources.getAnyTokenStream(searcher
      .getIndexReader(), hits.scoreDocs[1].doc, FIELD_NAME, doc, analyzer);
  highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer));
  fragment = highlighter.getBestFragment(stream, storedField);
  assertEquals("<B>This</B> piece of text refers to Kennedy at the beginning then has a longer piece of text that is <B>very</B>", fragment);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:32,代碼來源:HighlighterTest.java

示例6: assertStopQueryEquals

private void assertStopQueryEquals(String qtxt, String expectedRes)
    throws Exception {
  String[] fields = { "b", "t" };
  Occur occur[] = { Occur.SHOULD, Occur.SHOULD };
  TestQPHelper.QPTestAnalyzer a = new TestQPHelper.QPTestAnalyzer();
  StandardQueryParser mfqp = new StandardQueryParser();
  mfqp.setMultiFields(fields);
  mfqp.setAnalyzer(a);

  Query q = mfqp.parse(qtxt, null);
  assertEquals(expectedRes, q.toString());

  q = QueryParserUtil.parse(qtxt, fields, occur, a);
  assertEquals(expectedRes, q.toString());
}
 
開發者ID:europeana,項目名稱:search,代碼行數:15,代碼來源:TestMultiFieldQPHelper.java

示例7: assertStopQueryEquals

private void assertStopQueryEquals (String qtxt, String expectedRes) throws Exception {
  String[] fields = {"b", "t"};
  Occur occur[] = {Occur.SHOULD, Occur.SHOULD};
  TestQueryParser.QPTestAnalyzer a = new TestQueryParser.QPTestAnalyzer();
  MultiFieldQueryParser mfqp = new MultiFieldQueryParser(fields, a);
  
  Query q = mfqp.parse(qtxt);
  assertEquals(expectedRes, q.toString());
  
  q = MultiFieldQueryParser.parse(qtxt, fields, occur, a);
  assertEquals(expectedRes, q.toString());
}
 
開發者ID:europeana,項目名稱:search,代碼行數:12,代碼來源:TestMultiFieldQueryParser.java

示例8: testCommonTermsQueryHighlight

public void testCommonTermsQueryHighlight() throws IOException {
  Directory dir = newDirectory();
  IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET)));
  FieldType type = new FieldType(TextField.TYPE_STORED);
  type.setStoreTermVectorOffsets(true);
  type.setStoreTermVectorPositions(true);
  type.setStoreTermVectors(true);
  type.freeze();
  String[] texts = {
      "Hello this is a piece of text that is very long and contains too much preamble and the meat is really here which says kennedy has been shot",
      "This piece of text refers to Kennedy at the beginning then has a longer piece of text that is very long in the middle and finally ends with another reference to Kennedy",
      "JFK has been shot", "John Kennedy has been shot",
      "This text has a typo in referring to Keneddy",
      "wordx wordy wordz wordx wordy wordx worda wordb wordy wordc", "y z x y z a b", "lets is a the lets is a the lets is a the lets" };
  for (int i = 0; i < texts.length; i++) {
    Document doc = new Document();
    Field field = new Field("field", texts[i], type);
    doc.add(field);
    writer.addDocument(doc);
  }
  CommonTermsQuery query = new CommonTermsQuery(Occur.MUST, Occur.SHOULD, 2);
  query.add(new Term("field", "text"));
  query.add(new Term("field", "long"));
  query.add(new Term("field", "very"));
 
  FastVectorHighlighter highlighter = new FastVectorHighlighter();
  IndexReader reader = DirectoryReader.open(writer, true);
  IndexSearcher searcher = newSearcher(reader);
  TopDocs hits = searcher.search(query, 10);
  assertEquals(2, hits.totalHits);
  FieldQuery fieldQuery  = highlighter.getFieldQuery(query, reader);
  String[] bestFragments = highlighter.getBestFragments(fieldQuery, reader, hits.scoreDocs[0].doc, "field", 1000, 1);
  assertEquals("This piece of <b>text</b> refers to Kennedy at the beginning then has a longer piece of <b>text</b> that is <b>very</b> <b>long</b> in the middle and finally ends with another reference to Kennedy", bestFragments[0]);

  fieldQuery  = highlighter.getFieldQuery(query, reader);
  bestFragments = highlighter.getBestFragments(fieldQuery, reader, hits.scoreDocs[1].doc, "field", 1000, 1);
  assertEquals("Hello this is a piece of <b>text</b> that is <b>very</b> <b>long</b> and contains too much preamble and the meat is really here which says kennedy has been shot", bestFragments[0]);

  reader.close();
  writer.close();
  dir.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:42,代碼來源:FastVectorHighlighterTest.java

示例9: randomOccur

private static Occur randomOccur(Random random) {
  return random.nextBoolean() ? Occur.MUST : Occur.SHOULD;
}
 
開發者ID:europeana,項目名稱:search,代碼行數:3,代碼來源:CommonTermsQueryTest.java

示例10: should

public WebDSLFacet should(){
    occur = Occur.SHOULD;
    return this;
}
 
開發者ID:webdsl,項目名稱:webdsl,代碼行數:4,代碼來源:WebDSLFacet.java

示例11: toOccur

public static Occur toOccur(boolean required, boolean prohibited) {
	if(required && !prohibited)		return Occur.MUST;
	if(!required && !prohibited)	return Occur.SHOULD;
	if(!required && prohibited)		return Occur.MUST_NOT;
	throw new RuntimeException("invalid Occur definition (required and prohibited)");
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:6,代碼來源:OccurUtil.java

示例12: setMinShouldMatch

/**
 * Checks the number of optional clauses in the query, and compares it
 * with the specification string to determine the proper value to use.
 *
 * <p>
 * Details about the specification format can be found
 * <a href="doc-files/min-should-match.html">here</a>
 * </p>
 *
 * <p>A few important notes...</p>
 * <ul>
 * <li>
 * If the calculations based on the specification determine that no
 * optional clauses are needed, BooleanQuerysetMinMumberShouldMatch
 * will never be called, but the usual rules about BooleanQueries
 * still apply at search time (a BooleanQuery containing no required
 * clauses must still match at least one optional clause)
 * <li>
 * <li>
 * No matter what number the calculation arrives at,
 * BooleanQuery.setMinShouldMatch() will never be called with a
 * value greater then the number of optional clauses (or less then 1)
 * </li>
 * </ul>
 *
 * <p>:TODO: should optimize the case where number is same
 * as clauses to just make them all "required"
 * </p>
 */
public static void setMinShouldMatch(BooleanQuery q, String spec) {

  int optionalClauses = 0;
  for (BooleanClause c : q.clauses()) {
    if (c.getOccur() == Occur.SHOULD) {
      optionalClauses++;
    }
  }

  int msm = calculateMinShouldMatch(optionalClauses, spec);
  if (0 < msm) {
    q.setMinimumNumberShouldMatch(msm);
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:43,代碼來源:SolrPluginUtils.java


注:本文中的org.apache.lucene.search.BooleanClause.Occur.SHOULD屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。