Examples of Similarity


Examples of org.apache.lucene.search.Similarity

    private Similarity cachedSimilarity;
   
    @Override
    public byte[] norms(String fieldName) {
      byte[] norms = cachedNorms;
      Similarity sim = getSimilarity();
      if (fieldName != cachedFieldName || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(fieldName);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
        float n = sim.computeNorm(fieldName, invertState);
        byte norm = sim.encodeNormValue(n);
        norms = new byte[] {norm};
       
        // cache it for future reuse
        cachedNorms = norms;
        cachedFieldName = fieldName;
View Full Code Here

Examples of org.apache.lucene.search.Similarity

          testName = "reader re-use after disk full";
        }

        dir.setMaxSizeInBytes(thisDiskFree);
        dir.setRandomIOExceptionRate(rate);
        Similarity sim = new DefaultSimilarity();
        try {
          if (0 == x) {
            int docId = 12;
            for(int i=0;i<13;i++) {
              reader.deleteDocument(docId);
              reader.setNorm(docId, "content", sim.encodeNormValue(2.0f));
              docId += 12;
            }
          }
          reader.close();
          success = true;
View Full Code Here

Examples of org.apache.lucene.search.Similarity

    // Initialize similarity
    if ( similarityClass == null ) {
      return Similarity.getDefault();
    }
    else {
      Similarity defaultSimilarity;
      try {
        defaultSimilarity = (Similarity) similarityClass.newInstance();
      } catch (ClassCastException e) {
        throw new SearchException("Lucene similarity does not extend " + Similarity.class.getName() + ": "
            + similarityClassName, e);
View Full Code Here

Examples of org.apache.lucene.search.Similarity

   */
  private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor) {
    Map<Class<?>, DocumentBuilder<?>> builders = searchFactoryImplementor.getDocumentBuilders();
    List<DirectoryProvider> directories = new ArrayList<DirectoryProvider>();

    Similarity searcherSimilarity = null;
    //TODO check if caching this work for the last n list of classes makes a perf boost
    if ( classes == null || classes.length == 0 ) {
      // empty classes array means search over all indexed enities,
      // but we have to make sure there is at least one
      if ( builders.isEmpty() ) {
View Full Code Here

Examples of org.apache.lucene.search.Similarity

    batchBackend.initialize( batchBackendConfiguration, progressMonitor, this );
    return batchBackend;
  }

  public Similarity getSimilarity(DirectoryProvider<?> provider) {
    Similarity similarity = dirProviderData.get( provider ).getSimilarity();
    if ( similarity == null ) {
      throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
    }
    return similarity;
  }
View Full Code Here

Examples of org.apache.lucene.search.Similarity

  private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor) {
    Map<Class<?>, DocumentBuilderIndexedEntity<?>> builders = searchFactoryImplementor.getDocumentBuildersIndexedEntities();
    List<DirectoryProvider> targetedDirectories = new ArrayList<DirectoryProvider>();
    Set<String> idFieldNames = new HashSet<String>();

    Similarity searcherSimilarity = null;
    //TODO check if caching this work for the last n list of indexedTargetedEntities makes a perf boost
    if ( indexedTargetedEntities.size() == 0 ) {
      // empty indexedTargetedEntities array means search over all indexed enities,
      // but we have to make sure there is at least one
      if ( builders.isEmpty() ) {
View Full Code Here

Examples of org.apache.lucene.search.Similarity

  private void fillSimilarityMapping() {
    for ( DirectoryProviderData directoryConfiguration : dirProviderData.values() ) {
      for ( Class<?> indexedType : directoryConfiguration.getClasses() ) {
        DocumentBuilderIndexedEntity<?> documentBuilder = documentBuildersIndexedEntities.get( indexedType );
        Similarity similarity = documentBuilder.getSimilarity();
        Similarity prevSimilarity = directoryConfiguration.getSimilarity();
        if ( prevSimilarity != null && !prevSimilarity.getClass().equals( similarity.getClass() ) ) {
          throw new SearchException(
              "Multiple entities are sharing the same index but are declaring an " +
                  "inconsistent Similarity. When overrriding default Similarity make sure that all types sharing a same index " +
                  "declare the same Similarity implementation."
          );
View Full Code Here

Examples of org.apache.lucene.search.Similarity

    public ReentrantLock getDirectoryProviderLock(DirectoryProvider<?> dp) {
      return SearchFactoryBuilder.this.dirProviderData.get( dp ).getDirLock();
    }

    public Similarity getSimilarity(DirectoryProvider<?> provider) {
      Similarity similarity = dirProviderData.get( provider ).getSimilarity();
      if ( similarity == null ) {
        throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
      }
      return similarity;
    }
View Full Code Here

Examples of org.apache.lucene.search.Similarity

   * @param cfg the search configuration.
   * @return returns the default similarity class.
   */
  private Similarity initSimilarity(SearchConfiguration cfg) {
    String similarityClassName = cfg.getProperty(Environment.SIMILARITY_CLASS);
    Similarity defaultSimilarity;
    if ( StringHelper.isEmpty( similarityClassName ) ) {
      defaultSimilarity =  Similarity.getDefault();
    }
    else {
      defaultSimilarity = PluginLoader.instanceFromName(
          Similarity.class, similarityClassName, ConfigContext.class, "default similarity" );
    }
    log.debug( "Using default similarity implementation: {}", defaultSimilarity.getClass().getName() );   
    return defaultSimilarity;
  }
View Full Code Here

Examples of org.apache.lucene.search.Similarity

    writer.setMergeFactor(indexConf.getMergeFactor());
    String similarityName = indexConf.getSimilarityName();
    if (similarityName != null) {
      try {
        Class<?> similarityClass = Class.forName(similarityName);
        Similarity similarity = (Similarity) similarityClass.newInstance();
        writer.setSimilarity(similarity);
      } catch (Exception e) {
        throw new IOException("Error in creating a similarty object "
            + similarityName);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.