GithubHelp home page GithubHelp logo

How do i update a index? about riot HOT 3 CLOSED

go-ego avatar go-ego commented on June 18, 2024
How do i update a index?

from riot.

Comments (3)

vcaesar avatar vcaesar commented on June 18, 2024

Index addition and deletion operations are thread safe.

from riot.

jiankuny-zz avatar jiankuny-zz commented on June 18, 2024

seems like i can directly call

Index(id, types.DocData{Content: text,},forceUpdate)

to update a doc,
a exists doc's docState=0, after call

Index()

it marks docState to 1, once you call

Flush()

it will call

AddDocToCache(forceUpdate=true)

and call

RemoveDocToCache(forceUpdate=true) 
if indexer.addCacheLock.addCachePointer >= indexer.initOptions.DocCacheSize ||
forceUpdate {
    indexer.tableLock.Lock()

    position := 0
    for i := 0; i < indexer.addCacheLock.addCachePointer; i++ {
        docIndex := indexer.addCacheLock.addCache[i]

        docState, ok := indexer.tableLock.docsState[docIndex.DocId]
        if ok && docState <= 1 {
            // ok && docState == 0 表示存在于索引中,需先删除再添加
            // ok && docState == 1 表示不一定存在于索引中,等待删除,需先删除再添加
            if position != i {
                indexer.addCacheLock.addCache[position], indexer.addCacheLock.addCache[i] =
                indexer.addCacheLock.addCache[i], indexer.addCacheLock.addCache[position]
            }
            if docState == 0 {
                indexer.removeCacheLock.Lock()
                indexer.removeCacheLock.removeCache[indexer.removeCacheLock.removeCachePointer] =
                docIndex.DocId
                indexer.removeCacheLock.removeCachePointer++
                indexer.removeCacheLock.Unlock()

                indexer.tableLock.docsState[docIndex.DocId] = 1
                indexer.numDocs--
            }
            position++
        } else if !ok {
            indexer.tableLock.docsState[docIndex.DocId] = 2
        }
    }

    indexer.tableLock.Unlock()
    if indexer.RemoveDocToCache(0, forceUpdate) {
        // 只有当存在于索引表中的文档已被删除,其才可以重新加入到索引表中
        position = 0
    }

    addCachedDocs := indexer.addCacheLock.addCache[position:indexer.addCacheLock.addCachePointer]
    indexer.addCacheLock.addCachePointer = position

    indexer.addCacheLock.Unlock()
    sort.Sort(addCachedDocs)
    indexer.AddDocs(&addCachedDocs)
}

to remove the doc which docState=1 and delete the key in docState map, then it will call

AddDocs(addCache[postion:addCachePointer])

which position=0, so it will add all doc in addCache,

if ok && docState == 1 {
			// 如果此时 docState 仍为 1,说明该文档需被删除
			// docState 合法状态为 nil & 2,保证一定不会插入已经在索引表中的文档
			continue
		}

in this case, ok=false, so it will add the doc.

from riot.

vcaesar avatar vcaesar commented on June 18, 2024

What do you express by calling the function call? This is obviously a bug. Closing is due to duplicate ( #19 ) and non-issue regulations.

from riot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.