Using Solr 8.11.1
I have a schema with a dynamic multiValued field called tcngramm_X3b_en_field_job_titles
whose schema is:
{
"name":"tcngramm_*",
"type":"text_ngram",
"omitNorms":false,
"termVectors":true,
"multiValued":true,
"indexed":true,
"stored":true
},
Here's a sample result set of 4 documents for this field:
{
"response":{"numFound":4,"start":0,"maxScore":4.9268646,"numFoundExact":true,"docs":[
{
"tcngramm_X3b_en_field_job_titles":["Aboriginal centre coordinator",
"Aboriginal outreach officer - social services",
"Aboriginal outreach worker",
"Addictions worker",
"Addictions worker - compulsive gambling",
"Case aide - social services",
"Certified return-to-work coordinator - disability management",
"Certified return-to-work facilitator - disability management",
"Child and youth worker",
"Child life specialist",
"Child welfare worker",
"Child-care worker (except day care)",
"Community and social services worker",
"Community animator",
"Community centre coordinator",
"Community centre worker",
"Community counsellor - social services",
"Community development worker",
"Community liaison worker",
"Community mental health worker",
"Community organization worker",
"Community rehabilitation worker",
"Community service worker",
"Community services officer - social services",
"Community worker",
"Correctional program officer",
"Crisis intervention worker",
"Detention home worker",
"Development service worker",
"Developmental service worker",
"Disability management worker",
"Drop-in centre worker",
"Drug addiction worker",
"Eligibility coordinator - social assistance",
"Eligibility coordinator - welfare",
"Exceptional-child-care worker (except day care)",
"Family service worker",
"Financial assistance officer - social assistance",
"Financial assistance worker - social services",
"Group home operator",
"Group home worker",
"Halfway house supervisor",
"Halfway house worker",
"Help centre supervisor - social services",
"Hostel coordinator",
"Hostel outreach worker",
"Income maintenance officer - social services",
"Independent living instructor",
"Intellectual disabilities worker",
"Itinerant support service worker",
"Life coach",
"Life skills coach",
"Life skills instructor",
"Meals-on-wheels worker",
"Mental health proctor",
"Mental health support worker",
"Mental health worker",
"Native centre coordinator",
"Native community worker",
"Native outreach officer - social services",
"Native outreach worker",
"Neighbourhood worker - social services",
"Neuro-linguistic programming coach",
"Peer support worker",
"Personal skills development instructor - social services",
"Psychological assistant",
"Registered social service worker",
"Rehabilitation officer - social services",
"Rehabilitation service worker",
"Rehabilitation worker - social services",
"Residence coordinator - group home",
"Residential counsellor - group home",
"Return-to-work coordinator - disability management",
"Return-to-work facilitator - disability management",
"Settlement worker - community services",
"Shelter supervisor - social services",
"Shelter workshop supervisor",
"Social aid officer",
"Social animator",
"Social assistance officer",
"Social rehabilitation officer",
"Social rehabilitation technician",
"Social rehabilitation worker",
"Social services assistant",
"Social services volunteer coordinator",
"Social services worker",
"Social welfare officer",
"Special education technician - social and community services",
"Street outreach worker",
"Streetworker - social services",
"Substance abuse worker",
"Supervised access worker",
"Transition home worker - social services",
"Transition house worker - social services",
"Veteran services officer",
"Veterans' affairs field officer",
"Volunteer manager",
"Welfare and compensation officer",
"Welfare organization supervisor",
"Welfare worker",
"Women's centre coordinator - social services",
"Women's centre program supervisor - social services",
"Women's centre supervisor - social services",
"Women's shelter supervisor",
"Women's shelter supervisor - social services",
"Youth development coordinator",
"Youth hostel coordinator",
"Youth services worker",
"Youth worker",
"Youth worker - social services"],
"ss_search_api_id":"entity:node/466:en",
"hash":"29yp7p",
"ss_search_api_language":"en",
"score":4.9268646},
{
"tcngramm_X3b_en_field_job_titles":["Addiction social worker",
"Case management consultant - social work",
"Case management social worker",
"Case work consultant - social work",
"Casework supervisor - social work",
"Caseworker - social work",
"Certified social worker",
"Child welfare social worker",
"Children's aid investigator",
"Coordinator of social work",
"Family social worker",
"Geriatric social worker",
"Group social worker",
"Human relations officer - social work",
"Intake worker - social services",
"Medical social worker",
"Psychiatric social worker",
"Registered social worker",
"School social worker",
"Social casework consultant",
"Social work coordinator",
"Social work officer",
"Social work officer - Canadian Armed Forces",
"Social work supervisor",
"Social worker",
"Social workers supervisor"],
"ss_search_api_id":"entity:node/450:en",
"hash":"29yp7p",
"ss_search_api_language":"en",
"score":4.8937683},
{
"tcngramm_X3b_en_field_job_titles":["Aboriginal affairs development officer",
"Aboriginal affairs officer",
"Aboriginal employment policy officer",
"Aboriginal employment program officer",
"Aboriginal issues lobbyist",
"Adoption project officer",
"Adviser for the integration of persons with disabilities",
"Affirmative action advisor",
"Child care licensing officer",
"Child welfare policy analyst",
"Child-care programs planning officer",
"Child-care services liaison officer",
"Citizenship officer",
"Community organizer",
"Community policing program consultant",
"Community social development officer",
"Consumer advisor",
"Correctional service policy consultant",
"Employment equity adviser - social policy",
"Employment equity consultant",
"Employment equity policy analyst",
"Employment equity policy consultant",
"Employment initiatives coordinator",
"Employment insurance policy analyst",
"Employment insurance services adviser",
"Employment standards specialist",
"Experimental home economist",
"Extension home economist",
"Family violence prevention program adviser",
"Field representative - housing",
"Food consultant - home economics",
"Home economics consultant",
"Home economist",
"Home economist - consumer association",
"Housing policy analyst",
"Human Rights Commission officer",
"Human Rights Commission officers supervisor",
"Human rights officer",
"Human rights officer - government services",
"Human rights specialist",
"Immigrant settlement liaison officer",
"Immigration and citizenship consultant",
"Immigration and demographic analysis officer",
"Immigration consultant",
"Immigration policy advisor",
"Immigration policy analyst",
"Immigration policy consultant - non-government",
"Immigration settlement practitioner",
"Income maintenance program officer",
"Indigenous affairs officer",
"International aid and development project officer",
"International aid and development researcher",
"International relations specialist",
"Job creation and employment services evaluation officer",
"Labour affairs officer - labour policy",
"Labour market analyst",
"Labour market information officer",
"Labour market policy officer",
"Labour mobility policy consultant",
"Labour policy analyst",
"Labour policy officer",
"Labour standards analyst",
"Multiculturalism project officer",
"Native affairs officer",
"Native employment program officer",
"Native issues lobbyist",
"Occupational supply analyst",
"Peace activist",
"Peace researcher",
"Political organizer",
"Pollster",
"Poverty researcher",
"Psychology assistant (except university)",
"Public assistance adviser",
"Public housing officer",
"Public housing policy analyst",
"Public opinion survey researcher",
"Public rights coordinator",
"Race relations officer",
"Refugee affairs program officer",
"Research home economist",
"Settlement counsellor",
"Settlement liaison officer",
"Settlement practitioner",
"Social and community care licensing officer",
"Social assistance advisor",
"Social assistance policy analyst",
"Social development officer",
"Social issues researcher",
"Social policy advisor",
"Social policy analyst",
"Social policy consultant",
"Social policy planning consultant",
"Social policy researcher",
"Social program officer",
"Social researcher",
"Social science researcher",
"Social service program officer",
"Social services consultant",
"Social services planner",
"Social services planning consultant",
"Social services program officers supervisor",
"Social services program planner",
"Social survey researcher (except statistician)",
"Social survey researchers supervisor",
"Social welfare advisor",
"Social welfare research officer",
"Socio-economic research and planning officer",
"Status of women's directorate policy analyst",
"Textile and clothing consultant - home economics",
"Visible minorities policy officer",
"Welfare policy analysts supervisor",
"Women's employment policy consultant",
"Women's issues lobbyist",
"Women's program coordinator",
"Women's shelter program coordinator",
"Women's status policy consultant",
"Workers' compensation officer",
"Workers' compensation policy analyst"],
"ss_search_api_id":"entity:node/459:en",
"hash":"29yp7p",
"ss_search_api_language":"en",
"score":4.7705584},
{
"tcngramm_X3b_en_field_job_titles":["Anthropologist",
"Applied anthropologist",
"Applied geographer",
"Applied linguist",
"Archaeological consultant",
"Archaeological field worker",
"Archaeologist",
"Biogeographer",
"Biological anthropologist",
"Criminologist",
"Cultural anthropologist",
"Cultural geographer",
"Diplomatic historian",
"Dramatic arts historian",
"Economic geographer",
"Economic historian",
"Educational sociologist",
"Ethnographer",
"Ethnologist",
"Etymologist",
"Genealogist",
"Geographer",
"Gerontologist",
"Graphoanalyst",
"Graphologist",
"Handwriting analyst",
"Handwriting expert",
"Historian",
"Historical geographer",
"Industrial geographer",
"Industrial sociologist",
"Linguist",
"Linguistic anthropologist",
"Medical sociologist",
"Military historian",
"Penologist",
"Philologist",
"Philosopher",
"Physical anthropologist",
"Physical geographer",
"Political geographer",
"Political historian",
"Political scientist",
"Politicist",
"Psycholinguist",
"Psychometrician",
"Psychometrist",
"Quantitative historian",
"Research anthropologist",
"Research archaeologist",
"Rural sociologist",
"Scientific handwriting expert",
"Social and cultural anthropologist",
"Social anthropologist",
"Social ecologist",
"Social historian",
"Social scientist",
"Sociolinguist",
"Sociologist",
"Theatre historian",
"Urban geographer",
"Urban sociologist"],
"ss_search_api_id":"entity:node/464:en",
"hash":"29yp7p",
"ss_search_api_language":"en",
"score":4.3405538}]
}}
I am trying to formulate a query that would return documents where a single value contains both "social" and "worker". The result set above shows entries with:
The query I currently use, which returns results for the first 3 cases above, is:
q.op=OR&q=(tcngramm_X3b_en_field_job_titles:((+SOCIAL +WORKER)))
How can I modify this query to only return results with contain both "social" and "worker" in a single field entry? This would correspond to the first 2 results above instead of the 4 results.
NOTE: I'm not trying to remove the non-matching individual field entries - I can do that easily with the highlighting feature of Solr.
The best solution I found is to change the query to use proximity search, as follows:
q.op=OR&q=(tcngramm_X3b_en_field_job_titles:(("SOCIAL WORKER"~10)))
Regarding the "proximity distance" argument (value 10 in the above), I experimented with values from 1 to 1000 with exactly the same result for my dataset.
This change preserves the requirement that both terms are needed, while adding flexibility for the terms to be located in different places in the field entries - without crossing the boundaries of single entries in the multiValued field. I suspect that positionIncrementGap has a role to play in this behaviour.