Java 类org.apache.lucene.search.Similarity 实例源码

项目:community-edition-old    文件:AbstractSolrCachingScorer.java   
AbstractSolrCachingScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity);
    if (in instanceof BitDocSet)
    {
        matches = (BitDocSet) in;
    }
    else
    {
        this.matches = new BitDocSet(new OpenBitSet(solrIndexReader.maxDoc()));
        for (DocIterator it = in.iterator(); it.hasNext(); /* */)
        {
            matches.addUnique(it.nextDoc());
        }
    }
    openBitSet = matches.getBits();
    this.solrIndexReader = solrIndexReader;
    doc = solrIndexReader.getBase() - 1;
}
项目:opensearchserver    文件:WriterLocal.java   
private IndexWriter open(boolean create) throws IOException, SearchLibException {
    indexWriterLock.lock();
    final IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, null);
    config.setOpenMode(create ? OpenMode.CREATE_OR_APPEND : OpenMode.APPEND);
    config.setMergeScheduler(new SerialMergeScheduler());
    config.setWriteLockTimeout(indexConfig.getWriteLockTimeout());
    config.setRAMBufferSizeMB(128);
    final Similarity similarity = indexConfig.getNewSimilarityInstance();
    if (similarity != null)
        config.setSimilarity(similarity);
    if (!create) {
        final SnapshotDeletionPolicy snapshotDeletionPolicy =
                new SnapshotDeletionPolicy(config.getIndexDeletionPolicy());
        config.setIndexDeletionPolicy(snapshotDeletionPolicy);
    }
    Logging.debug("WriteLocal open " + indexDirectory.getDirectory());
    return new IndexWriter(indexDirectory.getDirectory(), config);
}
项目:community-edition-old    文件:SolrOwnerSetScorer.java   
public static SolrOwnerSetScorer createOwnerSetScorer(SolrIndexSearcher searcher, Similarity similarity, String authorities, SolrIndexReader reader) throws IOException
{
    // Get hold of solr top level searcher
    // Execute query with caching
    // translate reults to leaf docs
    // build ordered doc list

    BitDocSet authorityOwnedDocs = new BitDocSet(new OpenBitSet(searcher.getReader().maxDoc()));

    HashMap<String, OwnerLookUp> ownerLookUp = (HashMap<String, OwnerLookUp>) searcher.cacheLookup(AlfrescoSolrEventListener.ALFRESCO_CACHE,
            AlfrescoSolrEventListener.KEY_OWNER_LOOKUP);

    String[] auths = authorities.substring(1).split(authorities.substring(0, 1));

    for (String current : auths)
    {
        OwnerLookUp lookUp = ownerLookUp.get(current);
        if (lookUp != null)
        {
            ResizeableArrayList<CacheEntry> indexedOderedByOwnerIdThenDoc = (ResizeableArrayList<CacheEntry>) searcher.cacheLookup(AlfrescoSolrEventListener.ALFRESCO_ARRAYLIST_CACHE,
                    AlfrescoSolrEventListener.KEY_DBID_LEAF_PATH_BY_OWNER_ID_THEN_LEAF);
            for (int i = lookUp.getStart(); i < lookUp.getEnd(); i++)
            {
                authorityOwnedDocs.addUnique(indexedOderedByOwnerIdThenDoc.get(i).getLeaf());
            }
        }
    }

    return new SolrOwnerSetScorer(similarity, authorityOwnedDocs, reader);

}
项目:community-edition-old    文件:LeafScorer.java   
/**
 * Constructor - should use an arg object ...
 * 
 * @param weight
 * @param root
 * @param level0
 * @param containerScorer
 * @param sfps
 * @param followParentInLevel0
 * @param selfIds
 * @param reader
 * @param similarity
 * @param norms
 * @param dictionaryService
 * @param repeat
 */
public LeafScorer(Weight weight, TermPositions root, TermPositions level0, ContainerScorer containerScorer, StructuredFieldPosition[] sfps, boolean followParentInLevel0,
        HashMap<String, Counter> selfIds, IndexReader reader, Similarity similarity, byte[] norms, DictionaryService dictionaryService, boolean repeat)
{
    super(similarity);
    this.root = root;
    this.containerScorer = containerScorer;
    this.sfps = sfps;
    //A this.allNodes = allNodes;
    // this.tp = tp;
    if (selfIds == null)
    {
        this.selfIds = new HashMap<String, Counter>();
        hasSelfScorer = false;
    }
    else
    {
        this.selfIds = selfIds;
        hasSelfScorer = true;
    }
    this.reader = reader;
    this.level0 = level0;
    this.dictionaryService = dictionaryService;
    this.repeat = repeat;
    this.followParentInLevel0 = followParentInLevel0;

    matchAllLeaves = allNodes();
    try
    {
        initialise();
    }
    catch (IOException e)
    {
        throw new LeafScorerException("IO Error:", e);
    }

}
项目:dash-xtf    文件:NumericRangeQuery.java   
public NumericRangeScorer(Similarity similarity, IndexReader reader,
                          Weight w)
  throws IOException 
{
  super(similarity);
  theScore = w.getValue();
  data = NumericFieldData.getCachedData(reader, fieldName);
  dataSize = data.size();
  checkLower = (lowerVal != null);
  this.lowerNum = checkLower ? NumericFieldData.parseVal(lowerVal) : -1;
  checkUpper = (upperVal != null);
  this.upperNum = checkUpper ? NumericFieldData.parseVal(upperVal) : -1;
}
项目:dash-xtf    文件:SpanRecordingScorer.java   
/**
 * Construct a recording scorer.
 *
 * @param spans set of spans to process
 * @param weight weight of this query
 * @param similarity used to calculate scores, and compare queries
 * @param maxSpans max # of spans to collect
 * @throws IOException
 */
SpanRecordingScorer(Spans spans, SpanWeight weight, Similarity similarity,
                    int maxSpans)
  throws IOException 
{
  super(spans, weight, similarity);

  this.spans = spans;
  this.maxSpans = maxSpans;

  value = weight.getValue();
  field = ((SpanQuery)weight.getQuery()).getField();

  // Register ourselves with the searcher, so it will know how to call us
  // to get the matching spans.
  //
  Searcher searcher = weight.getSearcher();
  if (searcher instanceof RecordingSearcher)
    ((RecordingSearcher)searcher).registerRecordingScorer(this);

  // Make a map of all the terms.
  Collection termColl = ((SpanQuery)weight.getQuery()).getTerms();
  terms = new HashSet(termColl.size() * 2);
  for (Iterator iter = termColl.iterator(); iter.hasNext();) 
  {
    String term = ((Term)iter.next()).text();
    terms.add(term);

    // If this is a probable bi-gram, add both the component terms to the
    // map as well.
    //
    int sepPos = term.indexOf('~');
    if (sepPos > 0) {
      terms.add(term.substring(0, sepPos));
      terms.add(term.substring(sepPos + 1));
    }
  }
}
项目:dash-xtf    文件:SpanScorer.java   
SpanScorer(Spans spans, Weight weight, Similarity similarity)
  throws IOException 
{
  super(similarity);
  this.spans = spans;
  this.weight = weight;
  this.value = weight.getValue();
}
项目:neo4j-mobile-android    文件:LuceneDataSource.java   
synchronized IndexWriter getIndexWriter( IndexIdentifier identifier )
    {
        if ( closed ) throw new IllegalStateException( "Index has been shut down" );

        Pair<IndexWriter, AtomicBoolean> writer = indexWriters.get( identifier );
        if ( writer != null )
        {
            return writer.first();
        }

        try
        {
            Directory dir = getDirectory( baseStorePath, identifier );
            directoryExists( dir );
            IndexType type = getType( identifier );
            IndexWriterConfig writerConfig = new IndexWriterConfig( LUCENE_VERSION, type.analyzer );
            writerConfig.setIndexDeletionPolicy( new MultipleBackupDeletionPolicy() );
            Similarity similarity = type.getSimilarity();
            if ( similarity != null )
            {
                writerConfig.setSimilarity( similarity );
            }
            IndexWriter indexWriter = new IndexWriter( dir, writerConfig );
            writer = Pair.of( indexWriter, new AtomicBoolean() );

            // TODO We should tamper with this value and see how it affects the
            // general performance. Lucene docs says rather <10 for mixed
            // reads/writes
//            writer.setMergeFactor( 8 );

            indexWriters.put( identifier, writer );
            return writer.first();
        }
        catch ( IOException e )
        {
            throw new RuntimeException( e );
        }
    }
项目:neo4j-mobile-android    文件:IndexType.java   
static IndexType getIndexType( IndexIdentifier identifier, Map<String, String> config )
{
    String type = config.get( LuceneIndexImplementation.KEY_TYPE );
    IndexType result = null;
    Similarity similarity = getCustomSimilarity( config );
    boolean toLowerCase = parseBoolean( config.get( LuceneIndexImplementation.KEY_TO_LOWER_CASE ), true );
    Analyzer customAnalyzer = getCustomAnalyzer( config );
    if ( type != null )
    {
        // Use the built in alternatives... "exact" or "fulltext"
        if ( type.equals( "exact" ) )
        {
            result = EXACT;
        }
        else if ( type.equals( "fulltext" ) )
        {
            Analyzer analyzer = customAnalyzer;
            if ( analyzer == null )
            {
                analyzer = toLowerCase ? LuceneDataSource.LOWER_CASE_WHITESPACE_ANALYZER :
                        LuceneDataSource.WHITESPACE_ANALYZER;
            }
            result = new CustomType( analyzer, toLowerCase, similarity );
        }
    }
    else
    {
        // Use custom analyzer
        if ( customAnalyzer == null )
        {
            throw new IllegalArgumentException( "No 'type' was given (which can point out " +
                    "built-in analyzers, such as 'exact' and 'fulltext')" +
                    " and no 'analyzer' was given either (which can point out a custom " +
                    Analyzer.class.getName() + " to use)" );
        }
        result = new CustomType( customAnalyzer, toLowerCase, similarity );
    }
    return result;
}
项目:opensearchserver    文件:ReaderLocal.java   
ReaderLocal(IndexConfig indexConfig, IndexDirectory indexDirectory) throws IOException, SearchLibException {
    super(indexConfig);
    spellCheckCache = new SpellCheckCache(100);
    docSetHitsCache = new DocSetHitsCache(indexConfig);
    this.indexDirectory = indexDirectory;
    references = new AtomicInteger(0);
    acquire();
    final Directory directory = indexDirectory.getDirectory();
    if (directory == null)
        throw new IOException("The directory is closed");
    if (indexConfig.isMulti()) {
        final List<String> indexList = indexConfig.getIndexList();
        indexDirectories = new IndexDirectory[indexList.size()];
        indexReaders = new IndexReader[indexList.size()];
        int i = 0;
        for (String indexName : indexList) {
            IndexDirectory indexDir =
                    new IndexDirectory(new File(ClientCatalog.getClient(indexName).getDirectory(), "index"));
            indexDirectories[i] = indexDir;
            indexReaders[i++] = IndexReader.open(indexDir.getDirectory());
        }
        indexReader = new MultiReader(indexReaders);
    } else {
        indexReaders = null;
        indexDirectories = null;
        indexReader = IndexReader.open(directory);
    }
    indexSearcher = new IndexSearcher(indexReader);

    final Similarity similarity = indexConfig.getNewSimilarityInstance();
    if (similarity != null)
        indexSearcher.setSimilarity(similarity);

    // Warm
    final TopDocs topDocs = indexSearcher.search(new MatchAllDocsQuery(), 10);
    if (topDocs != null && topDocs.scoreDocs != null)
        for (ScoreDoc scoreDoc : topDocs.scoreDocs)
            indexSearcher.doc(scoreDoc.doc, (FieldSelector) fieldName -> FieldSelectorResult.LOAD);
}
项目:Chi-FRBCS-BigDataCS    文件:TFIDF.java   
public TFIDF(Similarity sim) {
  this.sim = sim;
}
项目:Chi-FRBCS-BigData-Ave    文件:TFIDF.java   
public TFIDF(Similarity sim) {
  this.sim = sim;
}
项目:Chi-FRBCS-BigData-Max    文件:TFIDF.java   
public TFIDF(Similarity sim) {
  this.sim = sim;
}
项目:community-edition-old    文件:SolrReaderSetScorer.java   
SolrReaderSetScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);

}
项目:community-edition-old    文件:SolrCachingReaderScorer.java   
SolrCachingReaderScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);

}
项目:community-edition-old    文件:SolrCachingPathScorer.java   
SolrCachingPathScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);

}
项目:community-edition-old    文件:SolrPathScorer.java   
SolrPathScorer(Similarity similarity, Scorer scorer)
{
    super(similarity);
    this.scorer = scorer;
}
项目:community-edition-old    文件:SolrPathScorer.java   
public static SolrPathScorer createPathScorer(Similarity similarity, SolrPathQuery solrPathQuery, SolrIndexReader reader, Weight weight, DictionaryService dictionarySertvice, boolean repeat) throws IOException
{

    StructuredFieldPosition last = null;
    if(solrPathQuery.getPathStructuredFieldPositions().size() > 0)
    {
       last = solrPathQuery.getPathStructuredFieldPositions().get(solrPathQuery.getPathStructuredFieldPositions().size() - 1);
    }


    if (solrPathQuery.getPathStructuredFieldPositions().size() == 0) 
    {
            ArrayList<StructuredFieldPosition> answer = new ArrayList<StructuredFieldPosition>(2);
            answer.add(new SelfAxisStructuredFieldPosition());
            answer.add(new SelfAxisStructuredFieldPosition());

            solrPathQuery.appendQuery(answer);
    }


    for (StructuredFieldPosition sfp : solrPathQuery.getPathStructuredFieldPositions())
    {
        if (sfp.getTermText() != null)
        {
            TermPositions p = reader.termPositions(new Term(solrPathQuery.getPathField(), sfp.getTermText()));
            if (p == null)
                return null;
            CachingTermPositions ctp = new CachingTermPositions(p);
            sfp.setCachingTermPositions(ctp);
        }
    }

    SolrContainerScorer cs = null;

    TermPositions rootContainerPositions = null;
    if (solrPathQuery.getPathRootTerm() != null)
    {
        rootContainerPositions = reader.termPositions(solrPathQuery.getPathRootTerm());
    }

    if (solrPathQuery.getPathStructuredFieldPositions().size() > 0)
    {
        cs = new SolrContainerScorer(weight, rootContainerPositions, (StructuredFieldPosition[]) solrPathQuery.getPathStructuredFieldPositions().toArray(new StructuredFieldPosition[] {}),
                similarity, reader.norms(solrPathQuery.getPathField()));
    }


    return new SolrPathScorer(similarity, cs);
}
项目:community-edition-old    文件:SolrOwnerSetScorer.java   
/**
 * @param similarity
 * @param in
 * @param solrIndexReader
 */
SolrOwnerSetScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);
    // TODO Auto-generated constructor stub
}
项目:community-edition-old    文件:SolrCachingOwnerScorer.java   
/**
 * @param similarity
 * @param in
 * @param solrIndexReader
 */
SolrCachingOwnerScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);
    // TODO Auto-generated constructor stub
}
项目:community-edition-old    文件:SolrCachingAuxDocScorer.java   
SolrCachingAuxDocScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);

}
项目:community-edition-old    文件:SolrCachingAuthorityScorer.java   
SolrCachingAuthorityScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);

}
项目:community-edition-old    文件:SolrAuthoritySetScorer.java   
SolrAuthoritySetScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity, in, solrIndexReader);

}
项目:community-edition-old    文件:PathScorer.java   
PathScorer(Similarity similarity, Scorer scorer)
{
    super(similarity);
    this.scorer = scorer;
}
项目:neo4j-mobile-android    文件:IndexType.java   
CustomType( Analyzer analyzer, boolean toLowerCase, Similarity similarity )
{
    super( analyzer, toLowerCase );
    this.similarity = similarity;
}
项目:neo4j-mobile-android    文件:IndexType.java   
@Override
Similarity getSimilarity()
{
    return this.similarity;
}
项目:neo4j-mobile-android    文件:IndexType.java   
private static Similarity getCustomSimilarity( Map<String, String> config )
{
    return getByClassName( config, LuceneIndexImplementation.KEY_SIMILARITY, Similarity.class );
}
项目:neo4j-mobile-android    文件:IndexType.java   
Similarity getSimilarity()
{
    return null;
}
项目:community-edition-old    文件:SolrContainerScorer.java   
/**
 * The arguments here follow the same pattern as used by the PhraseQuery.
 * (It has the same unused arguments)
 * 
 * @param weight -
 *            curently unsued
 * @param root -
 *            the term positions for documents with multiple entries - this
 *            may be null, or contain no matches - it specifies those things
 *            that appear under multiple categories etc.
 * @param positions -
 *            the structured field positions - where terms should appear
 * @param similarity -
 *            used in the abstract scorer implementation
 * @param norms -
 *            unused
 */
public SolrContainerScorer(Weight weight, TermPositions root, StructuredFieldPosition[] positions, Similarity similarity, byte[] norms)
{
    super(similarity);
    this.weight = weight;
    this.positions = positions;
    this.norms = norms;
    this.root = root;
}
项目:community-edition-old    文件:ContainerScorer.java   
/**
 * The arguments here follow the same pattern as used by the PhraseQuery.
 * (It has the same unused arguments)
 * 
 * @param weight -
 *            curently unsued
 * @param root -
 *            the term positions for documents with multiple entries - this
 *            may be null, or contain no matches - it specifies those things
 *            that appear under multiple categories etc.
 * @param positions -
 *            the structured field positions - where terms should appear
 * @param containers TermPositions
 * @param similarity -
 *            used in the abstract scorer implementation
 * @param norms -
 *            unused
 */
public ContainerScorer(Weight weight, TermPositions root, StructuredFieldPosition[] positions, TermPositions containers, Similarity similarity, byte[] norms)
{
    super(similarity);
    this.weight = weight;
    this.positions = positions;
    this.norms = norms;
    this.root = root;
    this.containers = containers;
}
项目:community-edition-old    文件:ContextAwareQuery.java   
/**
 * @param searcher Searcher
 * @return Similarity
 * @see org.apache.lucene.search.Query#getSimilarity(org.apache.lucene.search.Searcher)
 */
public Similarity getSimilarity(Searcher searcher)
{
    return luceneQuery.getSimilarity(searcher);
}
项目:gumtree-spoon-ast-diff    文件:right_IndexWriter_1.22.java   
/** Expert: Set the Similarity implementation used by this IndexWriter.
 *
 * @see Similarity#setDefault(Similarity)
 */
public void setSimilarity(Similarity similarity) {
  this.similarity = similarity;
}
项目:gumtree-spoon-ast-diff    文件:right_IndexWriter_1.22.java   
/** Expert: Return the Similarity implementation used by this IndexWriter.
 *
 * <p>This defaults to the current value of {@link Similarity#getDefault()}.
 */
public Similarity getSimilarity() {
  return this.similarity;
}
项目:gumtree-spoon-ast-diff    文件:left_IndexWriter_1.21.java   
/** Expert: Set the Similarity implementation used by this IndexWriter.
 *
 * @see Similarity#setDefault(Similarity)
 */
public void setSimilarity(Similarity similarity) {
  this.similarity = similarity;
}
项目:gumtree-spoon-ast-diff    文件:left_IndexWriter_1.21.java   
/** Expert: Return the Similarity implementation used by this IndexWriter.
 *
 * <p>This defaults to the current value of {@link Similarity#getDefault()}.
 */
public Similarity getSimilarity() {
  return this.similarity;
}
项目:gumtree-spoon-ast-diff    文件:right_IndexWriter_1.42.java   
/** Expert: Set the Similarity implementation used by this IndexWriter.
 *
 * @see Similarity#setDefault(Similarity)
 */
public void setSimilarity(Similarity similarity) {
  this.similarity = similarity;
}
项目:gumtree-spoon-ast-diff    文件:right_IndexWriter_1.42.java   
/** Expert: Return the Similarity implementation used by this IndexWriter.
 *
 * <p>This defaults to the current value of {@link Similarity#getDefault()}.
 */
public Similarity getSimilarity() {
  return this.similarity;
}
项目:gumtree-spoon-ast-diff    文件:left_IndexWriter_1.41.java   
/** Expert: Set the Similarity implementation used by this IndexWriter.
 *
 * @see Similarity#setDefault(Similarity)
 */
public void setSimilarity(Similarity similarity) {
  this.similarity = similarity;
}
项目:gumtree-spoon-ast-diff    文件:left_IndexWriter_1.41.java   
/** Expert: Return the Similarity implementation used by this IndexWriter.
 *
 * <p>This defaults to the current value of {@link Similarity#getDefault()}.
 */
public Similarity getSimilarity() {
  return this.similarity;
}