Package org.apache.lucene.search.similarities

Examples of org.apache.lucene.search.similarities.Similarity


      Properties indexProperties,
      XClass clazz,
      WorkerBuildContext buildContext) {

    // now we check the config
    Similarity configLevelSimilarity = getConfiguredPerIndexSimilarity(
        directoryProviderName,
        indexProperties,
        buildContext
    );
View Full Code Here


    }
  }

  private Similarity getConfiguredPerIndexSimilarity(String directoryProviderName, Properties indexProperties, WorkerBuildContext buildContext) {
    Similarity configLevelSimilarity = null;
    String similarityClassName = indexProperties.getProperty( Environment.SIMILARITY_CLASS_PER_INDEX );
    if ( similarityClassName != null ) {
      ServiceManager serviceManager = buildContext.getServiceManager();
      configLevelSimilarity = ClassLoaderHelper.instanceFromName(
          Similarity.class,
View Full Code Here

  private LazyQueryState buildSearcher(SearchFactoryImplementor searchFactoryImplementor, Boolean forceScoring) {
    Map<Class<?>, EntityIndexBinding> builders = searchFactoryImplementor.getIndexBindings();
    List<IndexManager> targetedIndexes = new ArrayList<IndexManager>();
    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 entities,
      // but we have to make sure there is at least one
      if ( builders.isEmpty() ) {
View Full Code Here

    this.indexName = indexManager.getIndexName();
    LuceneIndexingParameters luceneParameters = indexManager.getIndexingParameters();
    this.indexParameters = luceneParameters.getIndexParameters();
    this.directoryProvider = indexManager.getDirectoryProvider();
    luceneParameters.applyToWriter( writerConfig );
    Similarity similarity = indexManager.getSimilarity();
    if ( similarity != null ) {
      writerConfig.setSimilarity( similarity );
    }
    writerConfig.setOpenMode( OpenMode.APPEND ); //More efficient to open
  }
View Full Code Here

  private ConnectedMoreLikeThisQueryBuilder.INPUT_TYPE inputType;
  private TermQuery findById;

  public MoreLikeThisBuilder( DocumentBuilderIndexedEntity<T> documentBuilder, SearchFactoryImplementor searchFactory ) {
    this.documentBuilder = documentBuilder;
    Similarity configuredSimilarity = searchFactory.getIndexBindings().get( documentBuilder.getBeanClass() ).getSimilarity();
    if ( configuredSimilarity instanceof TFIDFSimilarity ) {
      this.similarity = (TFIDFSimilarity) configuredSimilarity;
    }
    else {
      throw log.requireTFIDFSimilarity( documentBuilder.getBeanClass() );
View Full Code Here

        }
        return terms;
    }

    public IndexSearcher setSimilarity(IndexSearcher searcher) {
        Similarity similarity = random().nextBoolean() ? new BM25Similarity() : new DefaultSimilarity();
        searcher.setSimilarity(similarity);
        return searcher;
    }
View Full Code Here

                             final SimilarityLookupService similarityLookupService, final MapperService mapperService) {
        super(index, indexSettings);
        this.similarityLookupService = similarityLookupService;
        this.mapperService = mapperService;

        Similarity defaultSimilarity = similarityLookupService.similarity(SimilarityLookupService.DEFAULT_SIMILARITY).get();
        // Expert users can configure the base type as being different to default, but out-of-box we use default.
        Similarity baseSimilarity = (similarityLookupService.similarity("base") != null) ? similarityLookupService.similarity("base").get() :
                defaultSimilarity;

        this.perFieldSimilarity = (mapperService != null) ? new PerFieldSimilarity(defaultSimilarity, baseSimilarity, mapperService) :
                defaultSimilarity;
    }
View Full Code Here

  private ConnectedMoreLikeThisQueryBuilder.INPUT_TYPE inputType;
  private TermQuery findById;

  public MoreLikeThisBuilder( DocumentBuilderIndexedEntity<T> documentBuilder, SearchFactoryImplementor searchFactory ) {
    this.documentBuilder = documentBuilder;
    Similarity configuredSimilarity = searchFactory.getIndexBindings().get( documentBuilder.getBeanClass() ).getSimilarity();
    if ( configuredSimilarity instanceof TFIDFSimilarity ) {
      this.similarity = (TFIDFSimilarity) configuredSimilarity;
    }
    else {
      throw log.requireTFIDFSimilarity( documentBuilder.getBeanClass() );
View Full Code Here

      SearchConfiguration cfg,
      WorkerBuildContext buildContext
  ) {
    String indexName = getIndexName( entity, cfg );
    Properties[] indexProperties = getIndexProperties( cfg, indexName );
    Similarity similarity = createSimilarity( indexName, cfg, indexProperties[0], entity, buildContext );
    boolean isDynamicSharding = isShardingDynamic( indexProperties[0], buildContext );

    IndexManager[] indexManagers = new IndexManager[0];
    if ( !isDynamicSharding ) {
      indexManagers = createIndexManagers(
View Full Code Here

      SearchConfiguration searchConfiguration,
      Properties indexProperties,
      XClass clazz,
      WorkerBuildContext buildContext) {
    // first check on class level
    Similarity classLevelSimilarity = null;

    // TODO - the processing of the @Similarity annotation is temporary here. The annotation should be removed in Search 5 (HF)
    List<XClass> hierarchyClasses = ReflectionHelper.createXClassHierarchy( clazz );
    Class<?> similarityClass = null;
    for ( XClass hierarchyClass : hierarchyClasses ) {
      org.hibernate.search.annotations.Similarity similarityAnnotation = hierarchyClass.getAnnotation( org.hibernate.search.annotations.Similarity.class );
      if ( similarityAnnotation != null ) {
        Class<?> tmpSimilarityClass = similarityAnnotation.impl();
        if ( similarityClass != null && !similarityClass.equals( tmpSimilarityClass ) ) {
          throw log.getMultipleInconsistentSimilaritiesInClassHierarchyException( clazz.getName() );
        }
        else {
          similarityClass = tmpSimilarityClass;
        }
        classLevelSimilarity = ClassLoaderHelper.instanceFromClass(
            Similarity.class,
            similarityClass,
            "Similarity class for index " + directoryProviderName
        );
      }
    }

    // now we check the config
    Similarity configLevelSimilarity = getConfiguredPerIndexSimilarity(
        directoryProviderName,
        indexProperties,
        buildContext
    );

    if ( classLevelSimilarity != null && configLevelSimilarity != null ) {
      throw log.getInconsistentSimilaritySettingBetweenAnnotationsAndConfigPropertiesException(
          classLevelSimilarity.getClass().getName(),
          configLevelSimilarity.getClass().getCanonicalName()
      );
    }
    else if ( classLevelSimilarity != null ) {
      return classLevelSimilarity;
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.similarities.Similarity

Copyright © 2018 www.massapicom. 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.