HowTo get the field where the result is found


#1

Hello,

Is there a way to get the field/property that contain the result?

I’am trying to get the page number of an indexed file that contains my search.

I tried to store the page number but I got all the pages in return, not only the page where the result is found.

I’ve define a document structure like this.

{
"type": "document",
"pages" : [{
    "page":1,
    "text":"I am number one"
},{
    "page":2,
    "text":"just a second page"
}]
}

thanks :slight_smile:


#2

Not sure whether I fully understood the problem you face. Especially on “getting all the pages in return part.”
There is an option like, ““includeLocations”: true” which you can try in the search request which would return the array_positions of the search term occurrences inside the document.
In this case, the array position would indirectly tell you the page number information.
for eg:

“locations”: {
“pages.text”: {
seachTerm”: [
{
“pos”: 5,
“start”: 17,
“end”: 26,
“array_positions”: [
0
]
},
{
“pos”: 5,
“start”: 20,
“end”: 29,
“array_positions”: [
1
]
}
]
}
},


#3

that sounds great, but I don’t find any documentation on this includeLocations options, how could I add this option in my search query??

And for what I’m trying to do :
I have a document with text in it, the page separator is defined by a page. All i’m trying to do is wanting to show at what page i’va found the word. In my example above, if a search for “number” i want the result “Page 1”, if i search for a word that appears on several pages i want to show all these pages…


#4

Hm, Not sure how to set this boolean flag in search request using SDKs.
Nearest documentation I found is here:

https://docs.couchbase.com/server/6.0/fts/fts-response-object-schema.html
and here: https://godoc.org/github.com/blevesearch/bleve

Direct curling should help in demonstrating this.

curl -XPOST -H “Content-Type: application/json” -uUser:Pwd http://localhost:port/api/index/FTS/query
-d ‘{
“includeLocations”: true,
“query”: {
“query”: “searchTerm”
}
}’

Let me know, whether it helps or not.


#5

Hum I’m using php and nodejs SDK but sadly I don’t find this option.

I’ll think of another way to do this unless you have an idea :wink:

thanks for having a look at this :slight_smile: