Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

How can pass url and url param(key/value pair) into couchdb-lucene index view #254

Open
wonderfuljamesjin opened this issue Jul 25, 2017 · 16 comments

Comments

@wonderfuljamesjin
Copy link

wonderfuljamesjin commented Jul 25, 2017

Hello All
Is there existed couchedb/couchdb-lucene api or good way to pass couchdb-lucene call final url url and url's param(key/value pair)param into couchdb-lucene index view defined?I have several couchdb document existed like following structure:
register": [ { "key": "serial_number", "value": "aaaaaaaaa" }, { "key": "register_information", "value": "abcde", } ...... ]
Here is a part of couchdb-lucene index view :

for(var u = 0; u < doc.register.length; u++){
    if (doc.register[u].key !=null && doc.register[u].value !=null){
      if(doc.register[u].key == 'serial_number'){
        r.add(doc.register[u].key, {field: 'registerKey1',store: 'yes'});r.add(doc.register[u].value, {field: 'registerValue1',store: 'yes'});
     }
    }
}

how can I get url and param value from URL using javascript like following registerKey/Value[i]'s serialNumber, aaaaaaaaa,register_information,abcde

http://127.0.0.1:5984/_fti/local/db/_design/designdoc/abc?q=registerKey1:"serialNumber"%20AND%20registerValue11:"aaaaaaaaa"%20AND%20registerKey2:"register_information"%20AND%20registerValue2:"abcde"&include_docs=true

Thanks for help!

@wonderfuljamesjin
Copy link
Author

I am stuck here, hope sb help this out, thanks

@wonderfuljamesjin
Copy link
Author

@rnewson, thnx

@wonderfuljamesjin wonderfuljamesjin changed the title How can pass url param(key/value pair) into couchdb-lucene index view How can pass url and url param(key/value pair) into couchdb-lucene index view Jul 25, 2017
@wonderfuljamesjin
Copy link
Author

How can pass the url to the couchdb-lucene index view(function(doc){....}) so that I can get some params from the url?

http://127.0.0.1:5984/_fti/local/db/_design/designdoc/abc?q=registerKey1:"serialNumber"%20AND%20registerValue11:"aaaaaaaaa"%20AND%20registerKey2:"register_information"%20AND%20registerValue2:"abcde"&include_docs=true

@rnewson
Copy link
Owner

rnewson commented Jul 25, 2017

the index function is not called at query time, but at index time, so you can't pass the url to it.

you can index any number of key/value pairs with your function and then query those later.

Unfortunately it is not clear from your description here exactly what problem you are having.

@wonderfuljamesjin
Copy link
Author

wonderfuljamesjin commented Jul 25, 2017

thanks for your following this issue, I hope get some suggestion here

Here is my issue, I have some couchdb document metaData structure like following part

metaData: [   
       {
           "key": "serial_number",
           "value": "abcde",
       },  
       {
           "key": "register_infor",
           "value": "123456"
       },....
       ]
 

Now I want to get the multiple pairs of key/value results like this result

("key": "serial_number", "value": "abcde") AND(OR) ("key": "register_infor", "value": "123456")

What I designed in the couchdb lucence index view is as following

for(var u = 0; u < doc.metaData.length; u++){
  if (doc.metaData[u].key !=null && doc.metaData[u].value !=null){
    r.add(doc.metaData[u].key, {field: 'metaDataKey',store: 'yes'});r.add(doc.metaData[u].value, {field: 'metaDataValue',store: 'yes'});
   }
  } 
}

Then I call request at:
?metaDataKey=serial_number&metaDataValue=serial_number&metaDataKey=register_infor&metaDataValue=123456....

But I can also get the following results which is not expected pair :

metaData: [  
      {
          "key": "serial_number",
          "value": "123456",
      },  
      {
          "key": "register_infor",
          "value": "abcde"
      }........
     ]

I found if my index view include the key name (e.g. doc.metaData[u].key == 'serial_number') it can get correct pair results, but it is hard coded in the index which is not good

for(var u = 0; u < doc.metaData.length; u++){
  if (doc.metaData[u].key !=null && doc.metaData[u].value !=null){
  if(doc.metaData[u].key == 'serial_number'){
    r.add(doc.metaData[u].key, {field: 'metaDataKey',store: 'yes'});r.add(doc.metaData[u].value, {field: 'metaDataValue',store: 'yes'});
   }
  } 
}

How can I do correct key/value pair with out hard code key as condition defined in the index view?

Thank you

@rnewson
Copy link
Owner

rnewson commented Jul 25, 2017

ok, I think I get you. I think you want this;

for(var u = 0; u < doc.metaData.length; u++){
  if (doc.metaData[u].key !=null && doc.metaData[u].value !=null){
    r.add(doc.metaData[u].value, {field: doc.metaData[u].key,store: 'yes'})
   }
  } 
}

then try ?q=register_infor:abcde should match as you expect, etc.

@wonderfuljamesjin
Copy link
Author

Thanks a lot @rnewson, good idea and it is working

Seems this idea is support metaDataKey and metaDataValue params pairs. this will not support single one searchlike? ...metaDataKey1=serial_number&metaDataKey2=register_infor, right?

Thank you

@wonderfuljamesjin
Copy link
Author

@rnewson, another question, why if there are spaces within the key, like I run ?q=Mobile Product:1234567, why no result return? how to fix this?

Thank you

@rnewson
Copy link
Owner

rnewson commented Jul 26, 2017 via email

@wonderfuljamesjin
Copy link
Author

Thanks @rnewson
If I change this as following, it will have 400 error?
?q=%22Problem%20Area%22:%22Configuration%20Assistance%22

"reason":"Bad query syntax: Cannot parse '\"Problem Area\":\"Configuration Assistance\"': Encountered \" \":\" \": \"\" at line 1, column 14.\nWas expecting one of:\n <EOF> \n <AND> ...\n <OR> ...\n <NOT> ...\n \"+\" ...\n \"-\" ...\n <BAREOPER> ...\n \"(\" ...\n \"*\" ...\n \"^\" ...\n <QUOTED> ...\n <TERM> ...\n <FUZZY_SLOP> ...\n <PREFIXTERM> ...\n <WILDTERM> ...\n <REGEXPTERM> ...\n \"[\" ...\n \"{\" ...\n <NUMBER> ...\n ","code":400}

@rnewson
Copy link
Owner

rnewson commented Jul 26, 2017 via email

@wonderfuljamesjin
Copy link
Author

Thanks @rnewson, so is there way to fix the issue that there are spaces within the key?

@rnewson
Copy link
Owner

rnewson commented Jul 26, 2017 via email

@wonderfuljamesjin
Copy link
Author

wonderfuljamesjin commented Jul 26, 2017

Hi @rnewson thanks, I am not following your suggestion, you mean replace the spaces for underscore in field there? field: doc.metaData[u].key, if replace with the underscore can query results as expected? I tried but not work, ?q=Product_Technology:%22Dial-Access%22& not sure why

Thanks

@wonderfuljamesjin
Copy link
Author

Thanks @rnewson , I know how to fix this issue, thank you

@rnewson
Copy link
Owner

rnewson commented Jul 27, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants