Bleve Search: How do I setup the index on for my struct?

354 views Asked by At

I have this struct in order to index an rdf graph.

type Statement struct {
    StatementHash  string `json:"statementHash"`
    SubjectType    string `json:"subjType"`
    Subject        string `json:"subject"`
    Predicate      string `json:"predicate"`
    Object         string `json:"object"`
    ObjectType     string `json:"objectType"`
    ShortType      string `json:"shortType"`
    ShortPredicate string `json:"shortPredicate"`
    DocType        string `json:"docType"`
}

DocType is initialised to "statement".

My objective is to be able to form a query string like

"shortType:Tweet covid"

in order to find Tweets in the index that have covid anywhere in the index.

I have set up the index as follows:

func buildIndexMapping() (mapping.IndexMapping, error) {

    // a generic reusable mapping for english text
    englishTextFieldMapping := bleve.NewTextFieldMapping()
    englishTextFieldMapping.Analyzer = en.AnalyzerName

    // a generic reusable mapping for keyword text
    keywordFieldMapping := bleve.NewTextFieldMapping()
    keywordFieldMapping.Analyzer = keyword.Name

    statementMapping := bleve.NewDocumentMapping()

    // mapping is based on short names only and object literal
    // shortType
    statementMapping.AddFieldMappingsAt("shortType", keywordFieldMapping)

    // others here

    indexMapping := bleve.NewIndexMapping()
    indexMapping.AddDocumentMapping("statement", statementMapping)

    indexMapping.TypeField = "docType"
    indexMapping.DefaultAnalyzer = "en"

    return indexMapping, nil
}

At this stage, I can get a search on covid to work, but when the term shortType:Tweet is added there are no results.

This is the searching snippet


type IndexHandler struct {
    sync.Mutex
    Index bleve.Index
}

...

// h is of type IndexHandler

            queryS := "shortType:Tweet covid"
            query := bleve.NewQueryStringQuery(queryS)
            searchRequest := bleve.NewSearchRequestOptions(query, size, from, false)
            searchRequest.Fields = []string{"*"}
            searchRequest.Highlight = bleve.NewHighlight()
            searchResult, _ := h.Index.Search(searchRequest)
            docCount, _ := h.Index.DocCount()
            fmt.Printf("GET %s\n", queryS)
            fmt.Printf("%d(%d) of %d\n", len(searchResult.Hits), searchResult.Total, docCount)

Will this set-up be able to achieve the kind of query that I indicated? If so, what could explain the failure to retrieve any results?

0

There are 0 answers