当前位置: 首页>>代码示例>>Java>>正文


Java Lookup类代码示例

本文整理汇总了Java中org.apache.lucene.search.suggest.Lookup的典型用法代码示例。如果您正苦于以下问题:Java Lookup类的具体用法?Java Lookup怎么用?Java Lookup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Lookup类属于org.apache.lucene.search.suggest包,在下文中一共展示了Lookup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lookup

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
private static void lookup(AnalyzingInfixSuggester suggester, String keyword,
                           String region) throws IOException {
    HashSet<BytesRef> contexts = new HashSet<BytesRef>();
    contexts.add(new BytesRef(region.getBytes("UTF8")));
    //先以contexts为过滤条件进行过滤,再以keyword为关键字进行筛选,根据weight值排序返回前2条
    //第3个布尔值即是否每个Term都要匹配,第4个参数表示是否需要关键字高亮
    List<Lookup.LookupResult> results = suggester.lookup(keyword, 2, true, false);
    System.out.println("-- \"" + keyword + "\" (" + region + "):");
    for (Lookup.LookupResult result : results) {
        System.out.println(result.key);
        //从payload中反序列化出Product对象
        BytesRef bytesRef = result.payload;
        InputStream is = Tools.bytes2InputStream(bytesRef.bytes);
        Product product = (Product) Tools.deSerialize(is);
        System.out.println("product-Name:" + product.getName());
        System.out.println("product-regions:" + product.getRegions());
        System.out.println("product-image:" + product.getImage());
        System.out.println("product-numberSold:" + product.getNumberSold());
    }
    System.out.println();
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:22,代码来源:SuggesterTest.java

示例2: suggest

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
/** TODO add PathParam version of this */
@GET
@Path("/suggest")
@Produces({MediaType.APPLICATION_JSON})
@ApiOperation("Provides search query suggestions given a partially complete input query")
public Response suggest(@QueryParam("q") String q) {

    if (q == null || (q = q.trim()).isEmpty() || q.length() > SuggestLengthMax)
        return Response.noContent().build();

    String x = q;
    return Response.ok((StreamingOutput) os -> {
        List<Lookup.LookupResult> x1 = db.suggest(x, SuggestionResultsMax);
        JSON.toJSON(Lists.transform(x1, y -> y.key), os);
    }).build();
}
 
开发者ID:automenta,项目名称:spimedb,代码行数:17,代码来源:WebAPI.java

示例3: create

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  int grams = (params.get(NGRAMS) != null) 
      ? Integer.parseInt(params.get(NGRAMS).toString()) 
      : FreeTextSuggester.DEFAULT_GRAMS;
  
  byte separator = (params.get(SEPARATOR) != null) 
      ? params.get(SEPARATOR).toString().getBytes(StandardCharsets.UTF_8)[0]
      : FreeTextSuggester.DEFAULT_SEPARATOR;
  
  return new FreeTextSuggester(indexAnalyzer, queryAnalyzer, grams, separator);
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:FreeTextLookupFactory.java

示例4: testConstructionTime

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
/**
 * Test construction time.
 */
public void testConstructionTime() throws Exception {
  System.err.println("-- construction time");
  for (final Class<? extends Lookup> cls : benchmarkClasses) {
    BenchmarkResult result = measure(new Callable<Integer>() {
      @Override
      public Integer call() throws Exception {
        final Lookup lookup = buildLookup(cls, dictionaryInput);          
        return lookup.hashCode();
      }
    });

    System.err.println(
        String.format(Locale.ROOT, "%-15s input: %d, time[ms]: %s",
            cls.getSimpleName(),
            dictionaryInput.length,
            result.average.toString()));
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:22,代码来源:LookupBenchmarkTest.java

示例5: testStorageNeeds

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
/**
 * Test memory required for the storage.
 */
public void testStorageNeeds() throws Exception {
  System.err.println("-- RAM consumption");
  for (Class<? extends Lookup> cls : benchmarkClasses) {
    Lookup lookup = buildLookup(cls, dictionaryInput);
    long sizeInBytes;
    if (lookup instanceof AnalyzingSuggester) {
      // Just get size of FST: else we are also measuring
      // size of MockAnalyzer which is non-trivial and
      // varies depending on test seed:
      sizeInBytes = ((AnalyzingSuggester) lookup).sizeInBytes();
    } else {
      sizeInBytes = RamUsageEstimator.sizeOf(lookup);
    }
    System.err.println(
        String.format(Locale.ROOT, "%-15s size[B]:%,13d",
            lookup.getClass().getSimpleName(), 
            sizeInBytes));
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:23,代码来源:LookupBenchmarkTest.java

示例6: create

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  Object fieldTypeName = params.get(QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
  }
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();
  
  int grams = (params.get(NGRAMS) != null) 
      ? Integer.parseInt(params.get(NGRAMS).toString()) 
      : FreeTextSuggester.DEFAULT_GRAMS;
  
  byte separator = (params.get(SEPARATOR) != null) 
      ? params.get(SEPARATOR).toString().getBytes(IOUtils.CHARSET_UTF_8)[0]
      : FreeTextSuggester.DEFAULT_SEPARATOR;
  
  return new FreeTextSuggester(indexAnalyzer, queryAnalyzer, grams, separator);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:25,代码来源:FreeTextLookupFactory.java

示例7: lessThan

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
@Override
protected boolean lessThan(SuggestDoc a, SuggestDoc b) {
    if (a.score == b.score) {
        int cmp = Lookup.CHARSEQUENCE_COMPARATOR.compare(a.key, b.key);
        if (cmp == 0) {
            // prefer smaller doc id, in case of a tie
            return a.doc > b.doc;
        } else {
            return cmp > 0;
        }
    }
    return a.score < b.score;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:CompletionSuggester.java

示例8: lessThan

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
@Override
protected boolean lessThan(Entry.Option a, Entry.Option b) {
    int cmp = comparator.compare(a, b);
    if (cmp != 0) {
        return cmp > 0;
    }
    return Lookup.CHARSEQUENCE_COMPARATOR.compare(a.getText().string(), b.getText().string()) > 0;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:CompletionSuggestion.java

示例9: suggest

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
/**
 * Provide highlighted suggestion for titles.
 *
 * @param query The current user input.
 * @return A list of highlighted (with HTML mark-ups) titles.
 * @throws IOException
 */
public List<String> suggest(String query) throws IOException {
  List<Lookup.LookupResult> results = suggester.lookup(query, suggestionCount, false, true);

  List<String> suggestions = new ArrayList<String>();
  for (Lookup.LookupResult result : results) {
    if (result.highlightKey instanceof String) {
      suggestions.add((String) result.highlightKey);
    } else {
      suggestions.add(result.key.toString());
    }
  }

  return suggestions;
}
 
开发者ID:lukhnos,项目名称:lucenestudy,代码行数:22,代码来源:Suggester.java

示例10: suggest

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
@NotNull
public List<Lookup.LookupResult> suggest(String qText, int count) throws IOException {
    Lookup s = suggester();
    if (s == null)
        return Collections.EMPTY_LIST;
    else
        return s.lookup(qText, false, count);
}
 
开发者ID:automenta,项目名称:spimedb,代码行数:9,代码来源:SpimeDB.java

示例11: boundedTreeAdd

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
/**
 * Add an element to the tree respecting a size limit
 *
 * @param results the tree to add in
 * @param result the result we try to add
 * @param num size limit
 */
private static void boundedTreeAdd(TreeSet<Lookup.LookupResult> results, Lookup.LookupResult result, int num) {

  if (results.size() >= num) {
    if (results.first().value < result.value) {
      results.pollFirst();
    } else {
      return;
    }
  }

  results.add(result);
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:BlendedInfixSuggester.java

示例12: compare

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
@Override
public int compare(Lookup.LookupResult o1, Lookup.LookupResult o2) {
  // order on weight
  if (o1.value > o2.value) {
    return 1;
  } else if (o1.value < o2.value) {
    return -1;
  }

  // otherwise on alphabetic order
  return CHARSEQUENCE_COMPARATOR.compare(o1.key, o2.key);
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:BlendedInfixSuggester.java

示例13: BytesRef

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
public void /*testT*/rying() throws IOException {

    BytesRef lake = new BytesRef("lake");
    BytesRef star = new BytesRef("star");
    BytesRef ret = new BytesRef("ret");

    Input keys[] = new Input[]{
        new Input("top of the lake", 15, lake),
        new Input("star wars: episode v - the empire strikes back", 12, star),
        new Input("the returned", 10, ret),
    };

    File tempDir = createTempDir("BlendedInfixSuggesterTest");
    Analyzer a = new StandardAnalyzer(CharArraySet.EMPTY_SET);

    // if factor is small, we don't get the expected element
    BlendedInfixSuggester suggester = new BlendedInfixSuggester(TEST_VERSION_CURRENT, newFSDirectory(tempDir), a, a,
                                                                AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS, BlendedInfixSuggester.BlenderType.POSITION_RECIPROCAL,
                                                                BlendedInfixSuggester.DEFAULT_NUM_FACTOR);
    suggester.build(new InputArrayIterator(keys));


    List<Lookup.LookupResult> responses = suggester.lookup("the", null, 4, true, false);

    for (Lookup.LookupResult response : responses) {
      System.out.println(response);
    }

    suggester.close();
  }
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:BlendedInfixSuggesterTest.java

示例14: getInResults

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
private static long getInResults(BlendedInfixSuggester suggester, String prefix, BytesRef payload, int num) throws IOException {

    List<Lookup.LookupResult> responses = suggester.lookup(prefix, null, num, true, false);

    for (Lookup.LookupResult response : responses) {
      if (response.payload.equals(payload)) {
        return response.value;
      }
    }

    return -1;
  }
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:BlendedInfixSuggesterTest.java

示例15: create

import org.apache.lucene.search.suggest.Lookup; //导入依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
  boolean exactMatchFirst = params.get(EXACT_MATCH_FIRST) != null
  ? Boolean.valueOf(params.get(EXACT_MATCH_FIRST).toString())
  : true;

  return new WFSTCompletionLookup(exactMatchFirst);
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:WFSTLookupFactory.java


注:本文中的org.apache.lucene.search.suggest.Lookup类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。