刘同彬
刘同彬

Reputation: 336

Solr query over mutiple fields, one field needn't be matched completely

  1. I need to query over 2 field by Solr. one is buyerCountry, the other is details. both are indexed.
  2. eg: this is some data

    {
            "buyerCountry":"Peru",
            "arrivaldate":"2017-08-24 00:00:00",
            "supplier":"MONSANTO HOLLAND BV",
            "details":"Demas Semillas Hortalizas (Incluso ?Silvestres?)",
            "buyer":"MONSANTO PERU S A",
            "id":"IMP_PERU-000029fbb06ee9cb49985cbf3600952b",
            "_version_":1584917551396159488},
          {
            "buyerCountry":"Peru",
            "arrivaldate":"2017-08-28 00:00:00",
            "supplier":"SCHNEIDER ELECTRIC INDUSTRIES SAS",
            "details":"Reles, Para Corriente Nominal Inferior",
            "buyer":"SCHNEIDER ELECTRIC PERU S A",
            "id":"IMP_PERU-00003108b929bf36def5ccf37cc23485",
            "_version_":1584917551525134336},
          {
            "buyerCountry":"Peru",
            "arrivaldate":"2017-08-29 00:00:00",
            "supplier":"FEDERAL-MOGUL CORPORATION",
            "details":"Demas Cajas Cojinetes  Cojinetes",
            "buyer":"REPUESTOS SERVICIOS Y DISTRIBUC S A C",
            "id":"IMP_PERU-000080b39e7e83dbae36c5b465d9cb6c",
            "_version_":1584917551527231488}

  3. I need to match field buyerCountry completely, but for field details, I only need that all the search words in the field details. I tried q=buyerCountry:"Peru" AND details="Demas Semillas", no records. fq=buyerCountry:"Peru"&fq=details:"Demas Semillas", neither no records. Can anyone help me?

Upvotes: 0

Views: 30

Answers (1)

MatsLindh
MatsLindh

Reputation: 52912

A string field (usually based on StrField) can only do exact matches. There is no further processing done to the value inserted into the field.

If you want to process the field (i.e. tokenize it into separate tokens and filter those tokens further, such as lowercasing them), you'll have to use a TextField and attach a analysis chain that does the normalization / processing you want to perform.

In this case a StandardTokenizer and a lowercasefilter will probably be fine, so that the details fields get split into separate tokens. Demas Semillas Hortalizas (Incluso ?Silvestres?) will be processed into demas, semillas, hortalizas, incluso and silvestres as separate tokens, and when searching Demas Semillas, the same processing will happen - demas, semillas. Since both tokens from the query match, the document will be returned.

Upvotes: 2

Related Questions