当前位置: 首页>>代码示例>>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;未经允许,请勿转载。